0

I am having a problem with geckodriver (FF) in java-selenium. I am running multiple test scenarios via TEST-NG parallel execution (6+ threads).

Sometimes happens that at the start (opening new browser) I get unreachableBrowserException. So i try-catch it, waited 100ms and try to create it again. it works, but it keeps the first failed browser opened, with a blank page.

Problem is that the first window got opened BEFORE it got initialized as a driver, so it cannot be closed by driver.close() or something (it is null). So I have to close them manually.

So, my question is, has anyone encountered such behaviour? How can i close such browsers, without influencing the other threads?

while(true) {
            try {
                setDriver(DriverFactory.createInstance(getBrowserInstance()));
                break;
            } catch (UnreachableBrowserException e) {

            try {
                Thread.sleep(100);
                log.info("UnreachableBrowserException! Needed to wait for 100ms ");
                removeDriver();
                counter++;
            } catch (Exception e1) {
                log.info("Thread could not wait!");
                e1.printStackTrace();
            }
        }
        if(counter>100){
            log.info("Was not able to create a browser session!");
            break;
        }
    }

and the part of .createInstance :

final ProfilesIni profilesIni = new ProfilesIni();
                System.setProperty("webdriver.gecko.driver", "drivers/geckodriver.exe");
                System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"false");
                firefoxProfile = new FirefoxProfile();
                firefoxProfile.setAcceptUntrustedCertificates(true);
                firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
                firefoxProfile.setPreference("app.update.auto", false);
                firefoxProfile.setPreference("app.update.enabled", false);
                firefoxProfile = profilesIni.getProfile("selenium_profile");
                capabilities = DesiredCapabilities.firefox();
                capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

                return new FirefoxDriver(capabilities); //Here it throws the exception.

Selenium/Java/geckodriver versions are most recent. FF version is unfortunately 44.02 (cannot get newer). I would be grateful for any tips/hints.

Kind regards, Martin

sameera lakshitha
  • 1,925
  • 4
  • 21
  • 29

1 Answers1

1

As you are using Mozilla Firefox version 44.02 and cannot get newer you have to consider a lot of things.

  1. To use Selenium 3.x you have to mandatory use geckodriver. See why here.
  2. Firefox 44.02 is not marionette enabled, so you have to set marionette to false through DesiredCapabilities class. See why here
  3. There are couple of Selenium version dependencies and GeckoDriver version dependencies. See them here
  4. You cannot create a new Firefox Profile and then again try to use a existing Firefox Profile.
  5. Assuming you have a existing Firefox Profile by the name selenium_profile, the following code would open the Firefox Profile in a new browser session:

    System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile firefoxProfile = profile.getProfile("selenium_profile");
    firefoxProfile.setAcceptUntrustedCertificates(true);
    firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
    firefoxProfile.setPreference("app.update.auto", false);
    firefoxProfile.setPreference("app.update.enabled", false);
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
    dc.setCapability("marionette", false);
    WebDriver driver = new FirefoxDriver(dc);
    driver.get("http://www.google.com");
    

Now you can easily return the capabilities.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352