Firefox Webdriver非常慢

时间:2015-10-12 10:13:19

标签: selenium windows-7 selenium-firefoxdriver

我们使用设置的selenium webdriver dll来运行我的自动化套件。在Firefox中运行测试时遇到此问题。 Firefox中的测试运行速度非常慢,加载页面需要3-4分钟,但是,当我使用Firefox浏览器手动在同一台机器上运行相同的测试时,我不会遇到这种慢。有时在Firefox上运行自动化时,我们也会收到“连接已重置”页面。此外,相同的测试在Chrome和IE中运行良好。

我们使用以下环境:

Firefox版本28,37(代理设置为使用系统设置)

Webdriver(dlls)版本2.45

Windows 7

之前我们曾经使用Firefox版本14,16在Windows XP中运行相同的设置,而Webdriver版本2.37,我们没有遇到此问题。

我们使用以下代码调用Firefox:

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);

剩下的测试步骤......

有人可以帮我解决这个问题。

提前致谢。

2 个答案:

答案 0 :(得分:3)

这就是我解决“FirefoxDriver 非常慢”问题的方法:

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

上述代码强制 geckodriver 使用 IPv6 协议,该协议与 UI 元素的交互速度快了许多倍。

答案 1 :(得分:0)

现在可能对您没有任何好处,但是Firefox 45和Webdriver 2.15遇到了同样的问题。变成问题是隐式等待设置。就我而言,我有:

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

这一行需要190秒(是的,超过3分钟!)执行。删除它可以将启动时间缩短到8秒以下!

相关问题