2013-03-07 112 views
36

在我们的项目中使用硒进行UI测试。我们正在运行最新版本2.30.0。 我们使用Firefox WebDriver并运行Firefox 19.0。Selenium WebDriver抛出超时异常的例外

通常说,当我在Visual Studio中运行ui测试时,ui测试可以在本地甚至服务器端运行。我们的ui测试在我们的构建服务器上执行得很快。它在我通过Visual Studio手动测试的相同服务器上使用相同的部署。

但是偶尔我们遇到以下问题时,UI测试大干快上buildserver执行:在上传按钮,在输入字段中前充满了文件

Test(s) failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:7056/hub/session/bed1d0e7-efdc-46b6-ba07-34903519c44d/element/%7B8717bb19-96c7-44d3-b0ee-d4b989ae652d%7D/click timed out after 60 seconds. 
     ----> System.Net.WebException : The operation has timed out 
     at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 
     at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) 
--WebException 
    at System.Net.HttpWebRequest.GetResponse() 
    at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 

基本上测试点击。由于该文件非常小,因此可以在几秒钟内完成。尽管如此,60秒钟的时间有时会达到。

任何想法如何隔离潜在的问题?或者之前运行任何人到同一个问题? 任何提示赞赏。谢谢。

+0

什么浏览器和该浏览器的版本? – Arran 2013-03-07 10:09:27

+0

@Arran感谢您的提示。更新了问题。 – dasheddot 2013-03-07 10:14:08

+0

只是好奇,自FF 19更新以来发生了更多? – Arran 2013-03-07 10:16:39

回答

2

在我的情况下,该网页并未完全加载。一些Facebook插件似乎加载太久。我试图捕捉异常并操纵未完成的dom,但这并没有给我带来任何结果。 :(

约翰

1

我们面对我们的项目类似的问题。这个问题已经无关,与硒或我们的应用程序,它是时间,因为该项目的构建服务器的配置应该在5超时分钟但是我们所有的测试都没有在5分钟内完成,因此由于超时问题随机构建失败

另外我们遇到了firefox-19的问题,测试用于随机失败。不知何故,firefox- 10只适用于我们的硒测试

1

试试这个代码:

DesiredCapabilities caps = DesiredCapabilities.Firefox(); 

//set the timeout to 120 seconds 
IWebDriver driver = new RemoteWebDriver(new Uri("<app_url>"), caps, TimeSpan.FromSeconds(120)); 
+0

感谢您的提示,请试一试。 – dasheddot 2013-09-09 07:39:24

8

我得到了同样的错误:.NET WebDriver:2.37,FF:25.0.1。我注意到Firefox在我退出测试应用程序之前锁定了,所以我构建了Firefox的调试版本,发现写入stderr时发生了锁定。这给了我更改webdriver代码的线索,以便它不再重定向标准输出和错误,这解决了我的问题。看起来WebDriver以某种方式阻止了std错误。来自MSDN:

Synchronous read operations introduce a dependency between the caller reading from the StandardError stream and the child process writing to that stream. These dependencies can cause deadlock conditions...

更多信息here

任何人想要让我做了同样的调整: -

  1. 获取硒源。然后查看您使用的代码分支。

  2. 在FireFoxBinary.cs:

    我。无论您在哪里找到RedirectStandardError = true,请更改为RedirectStandardError = false

    ii。无论您在哪里找到RedirectStandardOutput = true,请更改为RedirectStandardOutput = false。 (对于非Windows,在可执行文件中也有一个。cs)

    iii。在ConsoleOutput中,将'return this.stream.ReadToEnd()'更改为'return''''

  3. 构建并用您的WebDriver.dll替换。

声明:这对我有用,但是您的问题可能会有所不同。据我所知,除禁用控制台输出外,没有其他不利影响,但可能还有其他副作用,我不知道。

我很想知道是否有人发现相同。

既然我已经解决了我的问题,我不会深究。如果任何人有一个硒组织成员想要更多的信息/日志/调整,我会很乐意这样做。

希望这会很快得到解决。

更新

看来,火狐V25目前不支持。见this comment

更新2014年2月25日

this update

Okay, this issue in general does not manifest itself in IE, or so it seems from the comments. I'd like people to try with Firefox and Chrome, and the .NET bindings 2.40.0 (will be the next release at the time of this writing) or later, and see if this is still happening.

I've seen fewer reports of this happening in Chrome since 2.35.0, so I need to know if this is still an issue with the .NET bindings and a recent chromedriver.exe.

2.40.0 may have a fix for at least one of the issues that may cause this in Firefox.

这解决了这个问题对我来说。纵观更改日志,有一个从2014年1月31日提交删除控制台记录重定向:

"No longer redirecting console output for Firefox in .NET bindings." 

这是我在这里用的解决方法。所以,这一切都有道理。

+0

对于Selenium.2.43.1,FireFoxBinary.cs中没有名为RedirectStandardError的参数。我在构建服务器上遇到与Firefox32相同的错误... – demokritos 2015-05-10 02:50:10

+0

@demokritos - 根据上一次更新,修复程序已放入2.40.0和更高版本以删除重定向。所以,你遇到的问题可能是由不同的问题引起的。 – acarlon 2015-05-11 05:12:12

5

发生在我身上四种不同的方案:

  1. 的原因是,窗口句柄,我查询已经关闭或者收尾阶段。 如果是这种情况,最好在查询之前检查窗口是否存在。 如果你想避免的60秒长的超时时间,你应该改变你创建的Firefox实例来减少60秒延时的方式:

    新FirefoxDriver(“FfBinaryPath”,FfProfileInstance,TimeSpan.FromSeconds(5) );

  2. 原因是Flash插件'保护模式'。 这种情况发生在我只在windows 7和8时,他们运行在詹金斯工作下,超时并没有偶尔发生。 为了解决这个问题,我运行了禁用flash安全模式的Firefox Selenium实例:

    FfProfile.SetPreference(“dom.ipc.plugins.flash.disable-protected-mode”,true);

  3. 在使用Firefox版本45时,发生在Jenkins和Flash中的另一个原因,也是非零星的,为了解决这个问题,我必须降级到版本44或者替代地卸载Flash。

  4. 内部浏览器原因:有时浏览器需要超过一分钟才能响应硒调用。在这种情况下,将浏览器命令超时设置为60秒以上可以解决问题。例如:

    new FirefoxDriver("FfBinaryPath", FfProfileInstance, TimeSpan.FromMinutes(3));

0
public static IWebElement WaitForElementVisible(By selector, uint timeout = Config.DefaultTimeoutSec) 
    { 
     IWebDriver driver = Browser.Instance.Driver; 

     if (timeout > 0) 
     { 
      WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)); 

      wait.Until(ExpectedConditions.ElementIsVisible(selector)); 
      return driver.FindElement(selector); 
     } 
     else 
     { 
      // Search for element without timeout 
      return driver.FindElement(selector); 
     } 
    } 

我们用这个来防止这样的元素没有发现故障,它就像一个魅力。

还有一个不同的版本,如果元素可以在那里,但不一定是可见的。

只需使用ExpectedConditions.ElementExists(selector)代替ExpectedContitions.ElementIsVisible(selector)

编辑:Browser.Instance.Driver是包含实例化驱动程序

2

我有时间了同样的错误一类。我正在使用IEDriverServer(64位),并且在长时间的sendKey命令中它会超时。

原因是默认的超时时间似乎是60秒。

我的问题解决了什么问题,我使用一种方法实例化驱动程序,使您能够输入IEDriverServer的位置,驱动程序的选项和超时值。

链接到文件:http://seleniumhq.github.io/selenium/docs/api/dotnet/

public InternetExplorerDriver(
    string internetExplorerDriverServerDirectory, 
    InternetExplorerOptions options, 
    TimeSpan commandTimeout 
) 

参数

  1. InternetExplorerDriverServerDirectory
    • 类型:System
    • 的完整路径包含IEDriverServer.exe目录
  2. 选项
    • 类型:OpenQA.Selenium.IE.InternetExplorerOptions
    • 用来初始化驱动程序
  3. 的InternetExplorerOptions
  4. commandTimeout
    • 类型:System.TimeSpan
    • 等待每个命令

我的代码

InternetExplorerOptions options = new InternetExplorerOptions(); 
     IWebDriver driver = new InternetExplorerDriver("C:/Users/jeff/AppData/Local/Microsoft/WindowsApps", options, TimeSpan.FromSeconds(120)); 
+0

什么是IEDriverServer.exe btw,我们可以下载它?但在我的情况是Firefox。谢谢 – 2018-02-27 10:53:30

1

的最长时间我有同样的问题,以及,但只有在Firefox驱动程序。原来,这可能与您使用驱动程序Navigate方法有关,它会尝试与页面进行太快的交互。下面的代码调用修复了我在导航(我也建议使用它之前FindElement以及):

public void VerifyPageIsLoaded() 
{ 
    var pageLoaded = false; 

    for (var i = 0; i < DefaultTimeout.Timeout.Seconds; i++) 
    { 
     Thread.Sleep(1000); 

     if (WebDriver.ExecuteJavaScript<string>("return document.readyState").Equals("complete")) 
     //jQuery.active might cause problems on some browser or browserstack so I commented it out 
     //&& WebDriver.ExecuteJavaScript<bool>("return jQuery.active == 0").Equals(true)) 
     { 
      pageLoaded = true; 
      break; 
     } 

     Thread.Sleep(1000); 
    } 

    if (!pageLoaded) 
    { 
     throw new Exception("Page was not with complete state)!"); 
    } 
}