2

I am getting connection refused error while creating a firefox driver.

System.setProperty("webdriver.gecko.driver", "path to gecko driver");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.addArguments("-profile", "./firefoxprofile");
options.setHeadless(true);
LOGGER.info("Completed setting firefox optons");
WebDriver driver = new FirefoxDriver(options);

Log:

 1550014357421  mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-profile" "./firefoxprofile" "-foreground" "-no-remote"
 1550014357464  geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1:61008
 [GFX1-]: [OPENGL] Failed to init compositor with reason: FEATURE_FAILURE_OPENGL_CREATE_CONTEXT
 Can't find symbol 'GetGraphicsResetStatus'.
 1550014417545  mozrunner::runner   DEBUG   Killing process 38393
 Exiting due to channel error.
 1550014417592  webdriver::server   DEBUG   <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}

Web server is running and I could able to test it with curl command and I tried with 777 permissions on gecko driver bin file.

Also updated Gecko driver to latest version (0.24.0)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Nuthan Kumar
  • 483
  • 5
  • 22

3 Answers3

2

Your configurations looks good.

I had a similar problems in Linux.

  • In my case the solution was test with all versions of gecko driver and with one of them, it worked.

  • Also you can check if the o.s user of your IDE (eclipse, intellij) is the same user of the firefox. In my case, eclipse was starting with root but firefox could not start with root user.

I hope this help you.

JRichardsz
  • 14,356
  • 6
  • 59
  • 94
  • I will try with different versions of gecko driver, regarding o.s user, we are using same user to run tests and firefox. – Nuthan Kumar Feb 13 '19 at 02:36
  • By the way, we are running these tests using remote login (ssh), not sure whether it's relevant here or not – Nuthan Kumar Feb 13 '19 at 02:37
  • Let me know the results of some gecko driver versions works for you! – JRichardsz Feb 13 '19 at 02:51
  • version 0.21 worked for me along with new profile setting as mentioned by @DebanjanB – Nuthan Kumar Feb 13 '19 at 22:02
  • Chrome and Opera has the same behavior. You just need to find the right version to your operative system. Profile and settings would change according to your needs. Finally, if this helped to solve your day, please click the checkmark on the left to mark this as solved or just mark as useful :D – JRichardsz Feb 14 '19 at 02:35
1

While working with Selenium v3.x, GeckoDriver v0.24.0 and Firefox Quantum v65.0 to use a new Firefox Profile on every run of your Test Execution you can use the following code block :

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

You can find a detailed discussion in Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

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

I was facing the same problem in Windows using python. Make sure that your Firefox browser version is also the latest one.

After searching a lot, I finally found it was because a previous instance of the browser was running. Keep in mind, not another instance like one opened by me but an instance which was previously opened by selenium. If you can, close all the background browser processes. I restarted my system and it works perfectly fine as long as I remember to do browser.quit().

If you stop the program before closing the object properly, there is a chance the background instance will keep running unless eclipse or whichever IDE you are using closes it.

C.Jain
  • 1
  • 1