UnixUtils may not be used on Windows | Selenium Forum
M
Posted on 22/08/2015
Hi Ashish/All

The below screenshot code works fine on MAC but on Windows 7 I get an error(below), please advise?

[b:1ztcgwwo]Tools used:[/b:1ztcgwwo] selenium webdriver, cucumber, maven

@After()
public void tearDown(Scenario scenario) throws InterruptedException {
if (scenario.isFailed()) {
scenario.write("Failed Scenario: "+ scenario.getName());
// Take a screenshot
final byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
}


[b:1ztcgwwo]Error:[/b:1ztcgwwo]


java.lang.IllegalStateException: UnixUtils may not be used on Windows
at org.openqa.selenium.os.ProcessUtils.getProcessId(ProcessUtils.java:189)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.getPID(UnixProcess.java:222)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$300(UnixProcess.java:201)
at org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:131)
at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
at org.openqa.selenium.firefox.FirefoxBinary.quit(FirefoxBinary.java:259)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.quit(NewProfileExtensionConnection.java:204)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.quit(FirefoxDriver.java:377)
at org.openqa.selenium.firefox.FirefoxDriver.stopClient(FirefoxDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:467)
at util.WebConnector.quit(WebConnector.java:135)
at tests.CommonUtil.doLogOutAndQuit(CommonUtil.java:62)
at tests.CommonUtil.tearDown(CommonUtil.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cucumber.runtime.Utils$1.call(Utils.java:34)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:30)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:222)
at cucumber.runtime.Runtime.runHooks(Runtime.java:210)
at cucumber.runtime.Runtime.runAfterHooks(Runtime.java:204)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:50)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:89)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:40)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:94)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)






Regards
Ajay

M
Replied on 22/08/2015

Are you sure you are using right imports?


M
Replied on 22/08/2015

Below are the imports I am using:


import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import util.WebConnector;
import java.io.IOException;
import java.net.MalformedURLException;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.fail;


M
Replied on 22/08/2015

Can you please send the entire code ....also the exact line where it is throwing this error.


M
Replied on 22/08/2015

[b:2bi1rh68]Please find below the full code:[/b:2bi1rh68]


The issue appears in the code which takes screenshots, if I comment out the below 2 lines I don't get the error.

final byte[] screenshot = ((TakesScreenshot) selenium.driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");









package tests;


import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.sikuli.script.FindFailed;
import util.WebConnector;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.*;
import java.net.MalformedURLException;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.fail;


public class CommonUtil {
WebConnector selenium = WebConnector.getInstance();
Pages pages = new Pages();
private int assetCount = 0;

@Before
public void setUp() throws MalformedURLException {
selenium.openBrowser();
}


@After()
public void tearDown(Scenario scenario) throws InterruptedException, IOException {
if (scenario.isFailed()) {
scenario.write("Failed Scenario: " + scenario.getName());
// Take a screenshot
final byte[] screenshot = ((TakesScreenshot) selenium.driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
doLogOutAndQuit();
}


public static void assertForCondition(boolean condition) {
try {
assertTrue(condition);
} catch (Exception e) {
e.printStackTrace();
fail("Error occurred " + e.getMessage());
}
}


@After("@downloadasset")
public void deleteDownloadedAsset() throws InterruptedException, FindFailed, IOException {
pages.abstractPage().deleteDownloadedAssetFromDesktop();
}


public void doLogOutAndQuit() {
pages.abstractPage().navigateToQuickFindPage();
pages.quickFindPage().clickAdvancedLink();
pages.advancedPage().logOut();
assertForCondition(pages.logOutPage().isLogOutSuccessful());
selenium.quit();
}


public void navigateLoginAcceptTerms() throws FindFailed, InterruptedException {
pages.abstractPage().navigateToAssetBankPage();
pages.abstractPage().doLogin();
pages.termsAndConditionsPage().AcceptTermsAndConditions();
}

}


M
Replied on 22/08/2015

scenario.embed(screenshot, "image/png");

This line as the error
I am not sure what Scenario class does in your framework
But it looks like issue in scenario class
Can you contact the person who made this file - Scenario


M
Replied on 23/08/2015

scenario belongs to cucumber api

http://cucumber.github.io/api/cucumber/jvm/javadoc/cucumber/api/Scenario.html


M
Replied on 23/08/2015

Can you please send the code of webconnector class.


M
Replied on 23/08/2015

I found the cause of it, driver.quit() throws this error, I am using driver.close() now and I don't get this issue.


M
Replied on 24/08/2015

Yes big difference between driver.quit and driver.close


M
Replied on 24/08/2015

I still don't understand why driver.quit() is causing this issue, it used to work fine until recently.


M
Replied on 26/08/2015

Not sure why you got the error in driver.quit(). Could you please explain a bit more.
As I didnt see this issue when I used your code.