Selenium WebDriver在60秒后超时,无论我设置的间隔等待时间如何

C.奥菲特

因此,我正在Web应用程序上使用Selenium Web Driver(使用PhantomJS作为无头浏览器)运行自动化UI测试。当我到达测试的某个点时(该页面上的Web应用程序需要一分钟才能加载下一页(有时最多需要3分钟)),它将失败。

我收到以下错误消息:

结果消息:
测试方法UI_Tests.UT_GI_Template.Delivery_UI引发异常:OpenQA.Selenium.WebDriverException:URL到远程WebDriver服务器的HTTP请求,网址为http:// localhost:45539 ​​/ session / 94ef38f0-a528-11e7-a7fd-69a0e29e333f / element /:wdc:1506697956275 /值在60秒后超时。---> System.Net.WebException:请求已中止:操作已超时。

我已将等待时间间隔设置为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("[email protected]");
                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();
    ....

测试始终会在下面的步骤中超时-在下一个按钮上输入Enter会触发新页面加载(最多需要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)。为什么将间隔时间设置为300秒时,我的测试总是在60秒后超时WebDriverWait wait = new WebDriverWait(wd, new TimeSpan(0, 0, 300));任何帮助将不胜感激,谢谢!

C.奥菲特

经过大量调查(以及大约一百万次google搜索),我已经找出并解决了影响自动硒测试的问题。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秒的唯一方法是在实例化webdriver时执行此操作,在我的情况下,我正在使用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);

我的旧测试超时是因为ASP.net __doPostBack按钮,当我选择许多参数/项目时,从我的数据库中获取数据将花费超过60秒的时间,因此将触发HTTP请求中默认的命令超时。 WebDriver源代码。我知道这是问题所在,因为选择了3个以下参数/项后,测试永远不会在回发时超时。

希望此解决方案可以帮助其他人,加油!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

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

来自分类Java

如何设置Selenium WebDriver超时?

来自分类Dev

Selenium ChromeDriver-到远程WebDriver服务器的URL URL请求在60秒后超时

来自分类Java

如何以最少的等待时间加速Java Selenium脚本

来自分类Python

如何设置Selenium Python WebDriver默认超时?

来自分类Dev

Selenium Webdriver连接超时

来自分类Dev

无法让Selenium WebDriver等待指定的时间

来自分类Dev

X秒后关闭Selenium Webdriver

来自分类Dev

我如何使用Selenium的等待?

来自分类Dev

异常:wait.until Selenium WebDriver C# 上的“在 xx 秒后超时”

来自分类Dev

如何阻止Selenium Webdriver等待页面加载?

来自分类Java

线程“主” org.openqa.selenium.WebDriverException中的异常:geckodriver升级后,等待Firefox等待45秒超时

来自分类Dev

Python Selenium webdriver超时异常

来自分类Dev

如何使用Selenium Webdriver?

来自分类Dev

Selenium隐式等待是否总是占据整个等待时间,还是可以更快地完成?

来自分类Dev

Selenium webdriver 等待元素并单击

来自分类Dev

Selenium:我如何对Selenium说要等待按钮元素?

来自分类Dev

Selenium GRID-调用WebDriver.getCurrentUrl()不到100毫秒后,会话由于超时而终止

来自分类Dev

大约70秒后,Selenium WebDriver崩溃(WebDriverError:newSession)

来自分类Dev

setockopt 在 C++ 中不起作用(超时设置为 1 秒,等待时间更长)

来自分类Python

Selenium超时异常python

来自分类Dev

Selenium ChromeDriver管理超时

来自分类Dev

如何找到Selenium WebDriver的XPath?

来自分类Dev

Selenium Webdriver如何刮文字?

来自分类Dev

Selenium 返回并等待

来自分类Dev

Selenium:等待Tomcat启动

来自分类Dev

等待页面加载Selenium

来自分类Dev

Selenium Webdriver上的超时默认值

来自分类Dev

具有Java NoSuchElementException超时的Selenium WebDriver

Related 相关文章

  1. 1

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

  2. 2

    如何设置Selenium WebDriver超时?

  3. 3

    Selenium ChromeDriver-到远程WebDriver服务器的URL URL请求在60秒后超时

  4. 4

    如何以最少的等待时间加速Java Selenium脚本

  5. 5

    如何设置Selenium Python WebDriver默认超时?

  6. 6

    Selenium Webdriver连接超时

  7. 7

    无法让Selenium WebDriver等待指定的时间

  8. 8

    X秒后关闭Selenium Webdriver

  9. 9

    我如何使用Selenium的等待?

  10. 10

    异常:wait.until Selenium WebDriver C# 上的“在 xx 秒后超时”

  11. 11

    如何阻止Selenium Webdriver等待页面加载?

  12. 12

    线程“主” org.openqa.selenium.WebDriverException中的异常:geckodriver升级后,等待Firefox等待45秒超时

  13. 13

    Python Selenium webdriver超时异常

  14. 14

    如何使用Selenium Webdriver?

  15. 15

    Selenium隐式等待是否总是占据整个等待时间,还是可以更快地完成?

  16. 16

    Selenium webdriver 等待元素并单击

  17. 17

    Selenium:我如何对Selenium说要等待按钮元素?

  18. 18

    Selenium GRID-调用WebDriver.getCurrentUrl()不到100毫秒后,会话由于超时而终止

  19. 19

    大约70秒后,Selenium WebDriver崩溃(WebDriverError:newSession)

  20. 20

    setockopt 在 C++ 中不起作用(超时设置为 1 秒,等待时间更长)

  21. 21

    Selenium超时异常python

  22. 22

    Selenium ChromeDriver管理超时

  23. 23

    如何找到Selenium WebDriver的XPath?

  24. 24

    Selenium Webdriver如何刮文字?

  25. 25

    Selenium 返回并等待

  26. 26

    Selenium:等待Tomcat启动

  27. 27

    等待页面加载Selenium

  28. 28

    Selenium Webdriver上的超时默认值

  29. 29

    具有Java NoSuchElementException超时的Selenium WebDriver

热门标签

归档