无论我设置的间隔等待时间如何,Selenium WebDriver 都会在 60 秒时超时
Selenium WebDriver times out at 60 seconds no matter the interval wait time i set
所以我 运行ning 自动 UI 在 Web 应用程序上使用 Selenium Web 驱动程序(使用 PhantomJS 作为无头浏览器)进行测试。当我到达测试中的某个点时——网络应用程序需要一分钟多的时间来加载下一页的页面(有时最多 3 分钟)——它将失败。
我收到以下错误消息:
Result Message:
Test method UI_Tests.UT_GI_Template.Delivery_UI threw exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote
WebDriver server for URL
http://localhost:45539/session/94ef38f0-a528-11e7-a7fd-69a0e29e333f/element/:wdc:1506697956275/value
timed out after 60 seconds. ---> System.Net.WebException: The request
was aborted: The operation has timed out.
我已将等待时间间隔设置为 300 秒,但它总是在 60 秒后超时。有没有人遇到过这个错误?这是我的代码:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.PhantomJS;
namespace UI_Tests
{
[TestClass]
public class UT_GI_Template {
private RemoteWebDriver wd;
[TestMethod]
public void Delivery_UI()
{
IWebDriver wd = new PhantomJSDriver();
try
{
WebDriverWait wait = new WebDriverWait(wd, new TimeSpan(0, 0, 300));
wd.Navigate().GoToUrl("example.com/QA");
wait.Until(d => (d.FindElements(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).Count != 0));
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).Click();
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).Clear();
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).SendKeys("coffutt@icom.com");
wait.Until(d => (d.FindElements(By.CssSelector("#ctl00_ctl00_BodyContent_emailpassword")).Count != 0));
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailpassword")).Click();
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailpassword")).Clear();
....
测试将始终在下面的步骤中超时 -- 在下一步按钮上输入会触发新页面加载(最多需要 3 分钟)-- 我已经检查过,其余的 UI 测试套件 运行 很好,下面的步骤被注释掉了。
wait.Until(d => (d.FindElements(By.CssSelector("#ctl00_ctl00_BodyContent_BodyContent_NextButton")).Count != 0));
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_BodyContent_NextButton")).SendKeys(Keys.Enter);
wait.Until(d => (d.FindElements(By.XPath("//*[@class='grid8 alpha omega']/h1")).Count != 0)); //
string madeIt5 = wd.FindElement(By.XPath("//*[@class='grid8 alpha omega']/h1")).Text;
有什么我不知道的时间间隔或者我做错了什么吗?我没有在代码的其他任何地方包含任何 ImplicitWaits,也没有包含任何 System.Sleep(s)。当我使用 WebDriverWait wait = new WebDriverWait(wd, new TimeSpan(0, 0, 300));
将间隔时间设置为 300 秒时,为什么我的测试总是在 60 秒后超时?任何帮助将不胜感激,谢谢!!
经过大量调查(以及大约一百万次 google 搜索),我发现并解决了影响我的自动 Selenium 测试的问题。 60 秒 HTTP 超时错误来自 Selenium RemoteWebDriver 的默认设置,源代码中的这一行 >
https://github.com/SeleniumHQ/selenium/blob/9ca04253b7ed337852d50d02c72cb44a13169b71/dotnet/src/webdriver/Remote/RemoteWebDriver.cs#L69
protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60);
更改此 60 秒值的唯一方法是在实例化网络驱动程序时这样做,在我的例子中,我使用的是 PhantomJS,代码如下所示 >
var timeOutTime = TimeSpan.FromMinutes(4);
var options = new PhantomJSOptions();
options.AddAdditionalCapability("phantomjs.page.settings.resourceTimeout", timeOutTime);
RemoteWebDriver wd = new PhantomJSDriver("C:\Users\MyName\Source\Workspaces\ICompany\Application\packages\PhantomJS.2.0.0\tools\phantomjs\", options, timeOutTime);
我的旧测试超时,因为当我选择了很多 arguments/items 和因此会触发 WebDriver 源代码中看到的 HTTP 请求的默认命令超时。我知道这是问题所在,因为测试永远不会在回发时超时,并且选择了 3 arguments/items 以下。
希望这个解决方案可以帮助到其他人,干杯!
所以我 运行ning 自动 UI 在 Web 应用程序上使用 Selenium Web 驱动程序(使用 PhantomJS 作为无头浏览器)进行测试。当我到达测试中的某个点时——网络应用程序需要一分钟多的时间来加载下一页的页面(有时最多 3 分钟)——它将失败。
我收到以下错误消息:
Result Message:
Test method UI_Tests.UT_GI_Template.Delivery_UI threw exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:45539/session/94ef38f0-a528-11e7-a7fd-69a0e29e333f/element/:wdc:1506697956275/value timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
我已将等待时间间隔设置为 300 秒,但它总是在 60 秒后超时。有没有人遇到过这个错误?这是我的代码:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.PhantomJS;
namespace UI_Tests
{
[TestClass]
public class UT_GI_Template {
private RemoteWebDriver wd;
[TestMethod]
public void Delivery_UI()
{
IWebDriver wd = new PhantomJSDriver();
try
{
WebDriverWait wait = new WebDriverWait(wd, new TimeSpan(0, 0, 300));
wd.Navigate().GoToUrl("example.com/QA");
wait.Until(d => (d.FindElements(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).Count != 0));
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).Click();
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).Clear();
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailaddress")).SendKeys("coffutt@icom.com");
wait.Until(d => (d.FindElements(By.CssSelector("#ctl00_ctl00_BodyContent_emailpassword")).Count != 0));
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailpassword")).Click();
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_emailpassword")).Clear();
....
测试将始终在下面的步骤中超时 -- 在下一步按钮上输入会触发新页面加载(最多需要 3 分钟)-- 我已经检查过,其余的 UI 测试套件 运行 很好,下面的步骤被注释掉了。
wait.Until(d => (d.FindElements(By.CssSelector("#ctl00_ctl00_BodyContent_BodyContent_NextButton")).Count != 0));
wd.FindElement(By.CssSelector("#ctl00_ctl00_BodyContent_BodyContent_NextButton")).SendKeys(Keys.Enter);
wait.Until(d => (d.FindElements(By.XPath("//*[@class='grid8 alpha omega']/h1")).Count != 0)); //
string madeIt5 = wd.FindElement(By.XPath("//*[@class='grid8 alpha omega']/h1")).Text;
有什么我不知道的时间间隔或者我做错了什么吗?我没有在代码的其他任何地方包含任何 ImplicitWaits,也没有包含任何 System.Sleep(s)。当我使用 WebDriverWait wait = new WebDriverWait(wd, new TimeSpan(0, 0, 300));
将间隔时间设置为 300 秒时,为什么我的测试总是在 60 秒后超时?任何帮助将不胜感激,谢谢!!
经过大量调查(以及大约一百万次 google 搜索),我发现并解决了影响我的自动 Selenium 测试的问题。 60 秒 HTTP 超时错误来自 Selenium RemoteWebDriver 的默认设置,源代码中的这一行 > https://github.com/SeleniumHQ/selenium/blob/9ca04253b7ed337852d50d02c72cb44a13169b71/dotnet/src/webdriver/Remote/RemoteWebDriver.cs#L69
protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60);
更改此 60 秒值的唯一方法是在实例化网络驱动程序时这样做,在我的例子中,我使用的是 PhantomJS,代码如下所示 >
var timeOutTime = TimeSpan.FromMinutes(4);
var options = new PhantomJSOptions();
options.AddAdditionalCapability("phantomjs.page.settings.resourceTimeout", timeOutTime);
RemoteWebDriver wd = new PhantomJSDriver("C:\Users\MyName\Source\Workspaces\ICompany\Application\packages\PhantomJS.2.0.0\tools\phantomjs\", options, timeOutTime);
我的旧测试超时,因为当我选择了很多 arguments/items 和因此会触发 WebDriver 源代码中看到的 HTTP 请求的默认命令超时。我知道这是问题所在,因为测试永远不会在回发时超时,并且选择了 3 arguments/items 以下。
希望这个解决方案可以帮助到其他人,干杯!