0

Running tests in parallel on a windows node and a mac node using selenium grid would pass all tests but fail to run and skip the first test FilterMoreResultsBySquareFeet for either the Mac Firefox browser or the Windows Firefox browser. It keeps throwing this error org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService I am using latest java, latest selenium driver, latest browser driver, and lastest browser version. I have all drivers in the same folder I start my json selenium grid files from and my code system property is pointed to that same folder. I also have set the folder in the path in environment variables in windows and also in the path on the mac. Has anyone encountered this error and how did you solve it?

  public class TestBase {
       private static ThreadLocal<WebDriver> driverThread = new ThreadLocal<>();

    public static String whichNodeURL = "";
    public static String nodeURL = "http://xxxx:4444/wd/hub";
    public static String macNodeURL = "http://xxxx:5555/wd/hub";
    public static String winNodeURL = "http://xxxx:5554/wd/hub";

    DesiredCapabilities capabilities = new DesiredCapabilities();

    @SuppressWarnings({ "rawtypes"})
    @BeforeMethod (alwaysRun=true)
    //Use before method instead of before class or before test so each method/test will open in new browser; 
    //This was tested and found before method was the only one that works.
        @Parameters("browser")
    public final void setDriver(String browser) throws IOException, InterruptedException{

            ReadProperties.retrieveGlobalProperties();

        if (ReadProperties.globalProp.getProperty("webautomation").contains("yes") && ReadProperties.globalProp.getProperty("mobileautomation").contains("no"))
        {
            if(browser.contains("winfirefox"))
            {

                System.setProperty("webdriver.gecko.driver", ReadProperties.globalProp.getProperty("pcgeckodriver"));
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.setCapability("platform", "WINDOWS");
                firefoxOptions.setCapability("browser", "firefox");
                firefoxOptions.setCapability("newCommandTimeout", 5000);
                firefoxOptions.setCapability(FirefoxDriver.MARIONETTE, true);
                firefoxOptions.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");    
                whichNodeURL=winNodeURL;    
                try
                {
                    driverThread.set(new RemoteWebDriver(new URL(whichNodeURL), firefoxOptions));
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }


            }
            else if(browser.contains("macfirefox"))
            {
                System.setProperty("webdriver.gecko.driver", ReadProperties.globalProp.getProperty("macgeckodriver"));
                FirefoxOptions macfirefoxOptions = new FirefoxOptions();
                macfirefoxOptions.setCapability("platform", "MAC");
                macfirefoxOptions.setCapability("browser", "firefox");
                macfirefoxOptions.setCapability("newCommandTimeout", 5000);
                macfirefoxOptions.setCapability(FirefoxDriver.MARIONETTE, true);
                macfirefoxOptions.setBinary("/Applications/Firefox.app/Contents/MacOS/firefox-bin");
                whichNodeURL=macNodeURL;

                try
                {
                    driverThread.set(new RemoteWebDriver(new URL(whichNodeURL), macfirefoxOptions));
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }


            }
            else if (browser.contains("winchrome"))
            {
                System.setProperty("webdriver.chrome.driver", ReadProperties.globalProp.getProperty("pcchromedriver"));
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.setCapability("platform", "WINDOWS");
                chromeOptions.setCapability("browser", "chrome");
                chromeOptions.setCapability("newCommandTimeout", 5000);
                whichNodeURL=winNodeURL;

                try
                {
                    driverThread.set(new RemoteWebDriver(new URL(whichNodeURL), chromeOptions));
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }

            }
            else if (browser.contains("macchrome"))
            {
                System.setProperty("webdriver.chrome.driver", ReadProperties.globalProp.getProperty("macchromedriver"));
                ChromeOptions macchromeOptions = new ChromeOptions();
                macchromeOptions.setCapability("platform", "MAC");
                macchromeOptions.setCapability("browser", "chrome");
                macchromeOptions.setCapability("newCommandTimeout", 5000);
                whichNodeURL=macNodeURL;

                try
                {
                    driverThread.set(new RemoteWebDriver(new URL(whichNodeURL), macchromeOptions));
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }

            }
                String weburl = ReadProperties.globalProp.getProperty("weburl");
                this.driverThread.get().get(weburl);
                Thread.sleep(1000);
                this.driverThread.get().manage().window().maximize(); 
                Thread.sleep(1000);
           }
      }
    }
        public static WebDriver getDriver() {
        return driverThread.get();
    }
        @AfterMethod(alwaysRun=true) 
    public static void OnFailure(ITestResult testResult) throws IOException { 
        if (testResult.getStatus() == ITestResult.FAILURE) 
        { 
            System.out.println(testResult.getStatus()); 
        } 
    } 


@AfterMethod(alwaysRun=true)
//Use after method instead of after class or after test so each method/test will open in new browser; 
//This was tested and found after method was the only one that works.   
public void tearDown() {

        getDriver().quit();
}
}






  public class FilterMoreResultsBySquareFeet extends TestBase{

 static SoftAssert softAssert = new SoftAssert();
 final static Logger log = 
 LogManager.getLogger(FilterMoreResultsBySquareFeet.class);


static String className = 
FilterMoreResultsBySquareFeet.class.getSimpleName();
static Date date1= new Date();
static String originaltimestamp = new Timestamp(date1.getTime()).toString();
static String timestamp = originaltimestamp.replace(':', 'x').substring(11);
static String foldername = className+timestamp;
static String errorname = "";

  @Parameters("browser")
@Test(groups= {"smoke", "regression"}, dataProvider = "getData") 
public void filterResultsBySqFeet (String searchkeyword, String minsqfeet, String maxsqfeet) throws IOException, InterruptedException
{
    WebDriver webdriver = getDriver();
    Search.searchByCity(webdriver, searchkeyword);
    FilterMoreResults_Page.clickOpenMoreFilters(webdriver);
    FilterMoreResults_Page.filterBySqFeet(webdriver, minsqfeet, maxsqfeet);
    FilterMoreResults_Page.applyMoreFilters(webdriver);
    String diditfilter = FilterMoreResults_Page.verifyFilterBySqFeet(webdriver, minsqfeet, maxsqfeet);

    try{
        Assert.assertEquals(diditfilter, "yes");
    } 
    catch(AssertionError e)
    { 
        log.error("Didn't filter by square feet.", e.getMessage());
        errorname = "didntfilterbysqft";
        ScreenshotURL.screenshotURL(webdriver, foldername, errorname);
        softAssert.fail();
    }

       softAssert.assertAll();

}


  TESTNG FILE
  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="XOME Suite" parallel="tests" verbose="10" thread-count="2">

<test name = "Win Firefox Tests" preserve-order="true" group-by-instances="true">
<parameter name="browser" value="winfirefox">
    <classes>
    <class name="webTests.FilterMoreResultsBySquareFeet" />
        <class name="webTests.FilterMoreResultsByKeyword" />
        <class name="webTests.FilterMoreResultsByYear" />
    </classes>
</parameter>
</test>

<test name = "Mac Firefox Tests" preserve-order="true" group-by-instances="true">
<parameter name="browser" value="macfirefox">
    <classes>
    <class name="webTests.FilterMoreResultsBySquareFeet" />
        <class name="webTests.FilterMoreResultsByKeyword" />
        <class name="webTests.FilterMoreResultsByYear" />
    </classes>
</parameter>
</test>

<test name = "Win Chrome Tests" preserve-order="true" group-by-instances="true">
<parameter name="browser" value="winchrome">
    <classes>
    <class name="webTests.FilterMoreResultsBySquareFeet" />
        <class name="webTests.FilterMoreResultsByKeyword" />
        <class name="webTests.FilterMoreResultsByYear" />
    </classes>
</parameter>
</test>
<test name = "Mac Chrome Tests" preserve-order="true" group-by-instances="true">
<parameter name="browser" value="macchrome">
    <classes>
    <class name="webTests.FilterMoreResultsBySquareFeet" />
        <class name="webTests.FilterMoreResultsByKeyword" />
    <class name="webTests.FilterMoreResultsByYear" />
    </classes>
</parameter>
</test>

 macnode.json
 {
  "capabilities":
 [
  {
  "browserName": "firefox",
  "marionette": true,
  "maxInstances": 1,
  "version": 66,
  "platform": "MAC",
  "seleniumProtocol": "WebDriver"
},
{
  "browserName": "chrome",
  "maxInstances": 1,
  "version": 73,
  "platform": "MAC",
  "seleniumProtocol": "WebDriver"
},
{
  "browserName": "safari",
  "technologyPreview": false,
  "platform": "MAC",
  "maxInstances": 1,
  "seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://xxxx:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"cleanUpCycle": 5000,
"timeout": 5000,
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}

hub.json
{
"host": null,
"port": 4444,
"newSessionWaitTimeout": -1,
"servlets" : [],
"prioritizer": null,
"capabilityMatcher": 
"org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"nodePolling": 5000,
"cleanUpCycle": 5000,
"timeout": 300000,
"browserTimeout": 0,
"maxSession": 1
}

java -jar selenium-server-standalone-3.141.59.jar -role hub -hubConfig Hub.json

java -Dwebdriver.chrome.driver="C:\\seleniumgrid\\chromedriver.exe" -Dwebdriver.gecko.driver="C:\\seleniumgrid\\geckodriver.exe" -Dwebdriver.ie.driver="C:\\seleniumgrid\\IEDriverServer.exe" -Dwebdriver.edge.driver="C:\\seleniumgrid\\MicrosoftWebDriver.exe" -jar C:\\seleniumgrid\\selenium-server-standalone-3.141.59.jar -role node -nodeConfig C:\\seleniumgrid\\WindowsNode.json

java -Dwebdriver.chrome.driver="/Users/abc/seleniumgrid/chromedriver" -Dwebdriver.gecko.driver="/Users/abc/seleniumgrid/geckodriver" -jar /Users/abc/seleniumgrid/selenium-server-standalone-3.141.59.jar -role node -nodeConfig /Users/abc/seleniumgrid/MacNode.json

0

Ok after struggling with it for several days and trying everything, I got it to work. Hope this helps someone too. There wasn't much info out there on solving this error and the error didn't tell me much where it was wrong. Here's what I changed. 1. Use the hub url for creating your remotewebdriver for each browser and do not use the node url. public static String nodeURL = "http://xxxx:4444/wd/hub"; public static String macNodeURL = "http://xxxx:4444/wd/hub"; public static String winNodeURL = "http://xxxx:4444/wd/hub"; 2. Add this to the node json files

{
  "browserName": "firefox",
  "marionette": true,
  "maxInstances": 1,
  "version": 66,
  "platform": "MAC",
  "seleniumProtocol": "WebDriver",
  "webdriver.gecko.driver": "/Users/angee/seleniumgrid/geckodriver",
  "binary": "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
},

{
  "browserName": "firefox",
  "marionette": true,
  "maxInstances": 1,
  "version": 66,
  "platform": "WINDOWS",
  "seleniumProtocol": "WebDriver",
  "webdriver.gecko.driver": "C:/seleniumgrid/geckodriver.exe",
  "binary":"C:/Program Files/Mozilla Firefox/firefox.exe"
},
  1. Set this in your code firefoxOptions.setBinary("C:/Program Files/Mozilla Firefox/firefox.exe"); macfirefoxOptions.setBinary("/Applications/Firefox.app/Contents/MacOS/firefox-bin");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.