首页 文章

Selenium错误 - 对远程WebDriver的HTTP请求在60秒后超时

提问于
浏览
64

我已经使用Selenium好几个月,我们用它来自动化我们的一些内部测试过程 . 脚本一直很好 . 我最近使用FF 27.01升级到C#2.40.0 webdriver,我们的脚本现在在随机位置失败,出现以下错误 .

[Portal.SmokeTest.SmokeRunTest.Booking] TearDown method failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/element timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/window timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
[09:01:20]
[Portal.SmokeTest.SmokeRunTest.Booking] TearDown method failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/element timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
TearDown : OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL htt(p)://localhost:7055/hub/session/56e99e88-ba17-4d12-bef1-c6a6367ccc2f/window timed out after 60 seconds.
  ----> System.Net.WebException : The operation has timed out
   at OpenQA.Selenium.Support.UI.DefaultWait`1.PropagateExceptionIfNotIgnored(Exception e)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at Portal.Test.Helpers.Process_Bookings.OpenBookings.SelectBooking(String bookingnumber)
   at Portal.SmokeTest.SmokeRunTest.Booking() in d:\TeamCityAgent\work\dac1dcea7f2e80df\SmokeTests\SmokeRunTest.cs:line 68
--WebException
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--TearDown
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
   at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Close()
   at Portal.Test.Helpers.Setup.CloseWebdriver()
   at Portal.SmokeTest.SmokeRunTest.TearDown() in d:\TeamCityAgent\work\dac1dcea7f2e80df\SmokeTests\SmokeRunTest.cs:line 162
--WebException
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)

我设法追踪到一行代码的最新错误:

_setup.driver.FindElement(By.XPath("//button[@class='buttonSmall lockBookingButton']")).Click();

令人讨厌的是,试图解决问题是困难的,就像我在本地机器上运行测试一样,在调试过程中 . 另外,如果我通过构建机器上的NUNIT运行程序运行它,我正在运行测试,它也会通过 . 在使用Teamcity时,它似乎只是作为我们的自动构建运行过程的一部分而失败 . 就像我说的那样,这个问题已经好几个月了,并且唯一改变的是selenium webdriver套件 .

我之前遇到过这个问题,在调试时,当调用了一行代码时,Firefox似乎锁定了,只有停止测试才能让Firefox继续运行 . 这里有很多建议,包括修改webdriver源码?如果可能的话,如果有其他人可以提出任何建议,我不想走这条路 .

11 回答

  • 1

    在我的情况下,我发现在我们的团队构建服务器中发生了这个错误 . 这些测试适用于我们当地的开发机器 .

    问题是目标网站未在构建服务器上正确配置,因此无法正确打开浏览器 .

    我们使用的是Chrome驱动程序,但我不确定它会有所作为 .

  • 2
    new FirefoxDriver(new FirefoxBinary(),new FirefoxProfile(),TimeSpan.FromSeconds(180));
    

    使用上面的代码行启动浏览器 . 它对我有用 .

  • 15

    我几个月前第一次遇到这个问题(也是在 click() 命令上),从那以后它一直是我的问题 . 这似乎是.NET Selenium绑定的某种问题 . 这个关于IE驱动程序的人的博客文章有助于解释发生了什么:

    http://jimevansmusic.blogspot.com/2012/11/net-bindings-whaddaymean-no-response.html

    不幸的是,这个问题似乎没有真正的解决方案 . 每当这个问题提交给Selenium开发人员(see here)时,这都是typical response

    我们需要一个可重现的场景,必须包含一个示例页面或指向可以复制问题的公共站点页面的链接 .

    如果您能够提交一致的可重复的测试用例,那么这可能非常有助于将这个bug放好 .

    也就是说,也许你可以在此期间尝试这种解决方法 . 如果您尝试 click() 的HTML按钮具有包含Javascript的 onclick 属性,请考虑使用JavascriptExecutor直接执行该代码,而不是调用 click() 命令 . 我发现直接执行 onclick Javascript允许我的一些测试通过 .

  • 1

    在我的情况下,我的按钮的类型是 submit 而不是 button 并且我将 Click 更改为 Sumbit 然后每个工作都好 . 像下面的东西,

    来自 driver.FindElement(By.Id("btnLogin")).Click();

    driver.FindElement(By.Id("btnLogin")).Submit();

    顺便说一句,我已经尝试过这篇文章中的所有答案但不适合我 .

  • 16

    在我的情况下,这是因为我删除了chrome更新文件夹 . 重新安装Chrome后,它工作正常 .

  • 12

    有类似的问题 . 尝试在驱动程序的构造函数中设置更多时间 - 添加例如 .

    var timespan = TimeSpan.FromMinutes(3);
    
    var driver = new FirefoxDriver(binary, profile, timeSpan);
    
  • -1

    我认为当您尝试访问您的Web驱动程序对象后,会出现此问题

    1)窗口已关闭,您尚未切换到父级

    2)您切换到一个尚未准备好的窗口,并且在您切换后已更新

    等待 windowhandles.count 是你're expecting doesn' t考虑页面内容也不是document.ready . 我仍在寻找这个问题的解决方案

  • 0

    我有一个类似的问题,使用Chrome驱动程序(v2.23)/通过TeamCity运行测试 . 我可以通过在Chrome选项中添加“no-sandbox”标记来解决此问题:

    var options = new ChromeOptions();
    options.AddArgument("no-sandbox");
    

    我不确定FF驱动程序是否有类似的选项 . 据我所知,这个问题与TeamCity在SYSTEM帐户下运行Selenium有关 .

  • 2

    将Selenium.WebDriver.ChromeDriver从2.40.0更改为2.27.0对我来说没问题

  • 0

    问题是 Click() 的评估时间超过了你的构建环境..你可能想深入了解 Click() 上发生的事情 .

    另外,尝试为 Click() 添加Retrys,因为根据网络速度等,评估需要更长的时间 .

  • 2

    对于ChromDriver,以下为我工作:

    string chromeDriverDirectory = "C:\\temp\\2.37";
     var options = new ChromeOptions();
     options.AddArgument("-no-sandbox");
     driver = new ChromeDriver(chromeDriverDirectory, options, 
     TimeSpan.FromMinutes(2));
    

    Selenium 3.11版,ChromeDriver 2.37

相关问题