4

We use the selenium webdriver dlls set up to run my automation suite. I encounter this problem when runnning tests in Firefox only. The tests in Firefox run very slow , taking 3-4 minutes to load pages, However, when I run the same test on the same machine using Firefox browser manually I don't encounter this slowness. At times while running automation on Firefox, we also get "Connection was reset" page. Also, the same tests run fine in Chrome and IE.

We use the following environment:

Firefox version 28, 37 (proxy is set to use system settings)

Webdriver (dlls) version 2.45

Windows 7

Earlier we used to run the same set up in Windows XP using Firefox version 14,16, and Webdriver version 2.37, we didn't experience this issue.

We invoke Firefox using the following code :

Proxy proxy = new Proxy();
proxy.Kind = ProxyKind.System;
FirefoxProfile profile = new FirefoxProfile(); 
profile.SetProxyPreferences(proxy);

RemoteWebDriver dr = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), profile, TimeSpan.FromSeconds(120));

dr.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));

dr.Manage().Window.Maximize();

dr.Manage().Cookies.DeleteAllCookies();

dr.Navigate().GoToUrl(WebSiteUrl);

remaining tests steps......

Please can someone help me resolve this issue.

Thanks in advance.

Mosam Mehta
  • 1,658
  • 6
  • 25
  • 34
Shudipto
  • 61
  • 1
  • 5

2 Answers2

8

This is how I solved the "extremely slow FirefoxDriver" problem:

FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.Host = "::1";
IWebDriver driver = new FirefoxDriver(service);

The above code forces the geckodriver to use the IPv6 protocol, which works many times faster for the interactions with the UI elements.

Svetlin Nakov
  • 1,599
  • 18
  • 19
  • I have the same problem when I tried to run tests in BrowserStack/Firefox. Is there any way to pass that host in RemoteWebDriver instance? – Frank Escobar Apr 26 '21 at 15:41
  • No, you cannot control how the Firefox instance is created in BrowserStack. It is their job to make it run fast. – Svetlin Nakov Apr 27 '21 at 20:04
  • Bless you for this. It's a 10x order of magnitude in difference. – lsuarez Sep 01 '21 at 20:56
  • When I use this, I get the following error: OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:59346/ TearDown : System.NullReferenceException : Driver is null. – Fieldfare Oct 19 '21 at 09:21
0

Probably won't do you any good now, but I had the same problem with Firefox 45 and Webdriver 2.15. Turned the problem was the implicit wait setup. In my case, I had:

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

This one line was taking 190 seconds (yes, more than 3 minutes!) to execute. Removing it cut the startup time to under 8 seconds!

Ron HD
  • 161
  • 9