Selenium WebDriver 偶尔抛出超时异常 [英] Selenium WebDriver throws Timeout exceptions sporadically

查看:43
本文介绍了Selenium WebDriver 偶尔抛出超时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中使用 selenium 进行 ui 测试.我们正在运行最新版本 2.30.0.我们使用 Firefox WebDriver 并运行 Firefox 19.0.

Using selenium for ui tests on our project. We are running the newest version 2.30.0. We use Firefox WebDriver and are running Firefox 19.0.

一般来说,当我在 Visual Studio 中运行 ui 测试时,ui 测试可以在本地甚至服务器端工作.我们的 ui 测试在我们的构建服务器上执行.它在我通过 Visual Studio 手动测试的同一台服务器上使用相同的部署.

Generally said the ui test works local and even server side when I run the ui test in Visual Studio. Our ui tests gets executed nighlty on our build server. It uses the same deploy on the same server I test manually via Visual Studio.

但是,当在 buildserver 上执行 ui 测试时,我们偶尔会遇到以下问题:

But sporadically we run into following issue when the ui test gets executed on 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 秒的超时.

Basically the test clicks on an upload button where the input field was filled with a file before. Since the file is very small this gets done in a few seconds. Nevertheless the timout of 60 seconds is reached sometimes.

任何想法如何隔离潜在问题?或者之前有人遇到过同样的问题?任何提示表示赞赏.谢谢.

Any ideas how to isolate the underlying issue? Or run anybody into the same issue before? Any hints appreciated. Thanks.

推荐答案

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

I got this same error: .NET WebDriver: 2.37, FF: 25.0.1. I noticed that Firefox was locking up until I exited my test application, so I built the debug version of Firefox and found that the lock-up happened when it was writing to stderr. This gave me the clue to change the webdriver code so that it no longer redirects standard out and error and this solved my problem. It seems like the WebDriver is blocking the std error in some way. From MSDN:

同步读操作引入了调用者之间的依赖从 StandardError 流读取和子进程写入那个流.这些依赖会导致死锁情况...

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...

更多信息此处.

对于任何想要进行相同调整的人:-

For anyone wanting to make the same tweak I did: -

  1. 获取 Selenium 源代码.然后检查您正在使用的相同代码分支.

  1. Get the Selenium source. Then check out the same code branch that you are using.

在 FireFoxBinary.cs 中:

In FireFoxBinary.cs:

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

i. Wherever you find RedirectStandardError = true, change to RedirectStandardError = false.

二.无论您在哪里找到 RedirectStandardOutput = true,请更改为 RedirectStandardOutput = false.(对于非 Windows,Executable.cs 中也有)

ii. Wherever you find RedirectStandardOutput = true, change to RedirectStandardOutput = false. (for non-Windows, there is also one in Executable.cs)

三.在 ConsoleOuput 中,将 'return this.stream.ReadToEnd()' 更改为 'return ""'

iii. In ConsoleOuput, change 'return this.stream.ReadToEnd()', to 'return ""'

用你的构建和替换 WebDriver.dll.

Build and replace WebDriver.dll with yours.

免责声明:这对我有用,但您的问题可能有所不同.此外,据我所知,除了禁用控制台输出之外,这没有任何不利影响,但可能还有其他我不知道的副作用.

Disclaimer: This worked for me, but your issue might be different. Also as far as I can tell, this has no adverse effects other than disabling the console output, but there may be other side effects that I am unaware of.

我很想知道是否有其他人发现相同的情况.

I would be interested to know if anyone else finds the same.

既然我已经解决了我的问题,我不会再深入挖掘了.如果 Selenium 组成员想要更多信息/日志/调整,我很乐意这样做.

Since I have solved my problem, I will not dig any deeper. If anyone a Selenium group member wants more info / logs / tweaks I would be happy to do so.

希望这会很快得到解决.

Hopefully this will get fixed soon.

更新

目前似乎不支持 Firefox v25.请参阅此评论.

It appears that Firefox v25 is not currently supported. See this comment.

2014 年 2 月 25 日更新

查看此更新:

好的,这个问题一般不会在 IE 中表现出来,或者是这样从评论看来.我希望人们尝试使用 Firefox 和Chrome 和 .NET 绑定 2.40.0(将是撰写本文的时间)或之后,看看这是否仍在发生.

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.

自 2.35.0 以来,我在 Chrome 中看到这种情况的报告较少,所以我需要知道这是否仍然是 .NET 绑定的问题和最近的 chromedriver.exe.

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 可能会修复至少一个可能导致 Firefox 出现此问题的问题.

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

这为我解决了问题.查看更改日志,从 2014 年 1 月 31 日开始提交删除控制台日志重定向:

This solved the problem for me. Looking at the change log, there is a commit from 1/31/2014 to remove console logging redirection:

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

我在这里使用的解决方法是什么.所以,这一切都说得通.

Which is the workaround I used here. So, it all makes sense.

这篇关于Selenium WebDriver 偶尔抛出超时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆