Webdriver间歇性地抛出超时异常。对远程WebDriver服务器的URL请求

时间:2016-03-03 23:58:16

标签: c# selenium selenium-webdriver nunit

从今天开始,我的测试开始在IE和Firefox上偶尔失败。所有的失败都给了我这个例外。今天早上我在VS2013,与Nunit 3.0.1IEDriver 2.45.0.0Selenium.SupportSelenium.WebDriver 2.48.2。我认为这是因为我的软件包已过期并已更新Selenium.SupportSelenium.Webdriver更新为2.52.0。异常继续间歇性地困扰我的测试。唯一与这些例外相符的是它们都是由

触发的
wait.Until(ExpectedConditions.someCondition(element));

    OpenQA.Selenium.WebDriverException was unhandled by user code
  HResult=-2146233088
  Message=The HTTP request to the remote WebDriver server for URL http://localhost:7055/hub/session/e9b960bc-e750-41f1-93bf-7710bcfc1d5f/element timed out after 60 seconds.
  Source=WebDriver
  StackTrace:
       at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
       at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
       at OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(Command commandToExecute)
       at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
       at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String cssSelector)
       at OpenQA.Selenium.By.<>c__DisplayClass1e.<CssSelector>b__1c(ISearchContext context)
       at OpenQA.Selenium.By.FindElement(ISearchContext context)
       at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
       at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
       at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
       at POMAuctivaTest.AuctivaPageModels.BasePageModel.WaitForElementVisible(IWebDriver driver, By element) in c:\Users\jburns\Documents\Visual Studio 2013\Projects\POMAuctivaTest\POMAuctivaTest.AuctivaPageModels\BasePageModel.cs:line 125
       at POMAuctivaTest.AuctivaPageModels.ProfileManagmentPageModel.ChangeDateCreatedSortMostRecent() in c:\Users\jburns\Documents\Visual Studio 2013\Projects\POMAuctivaTest\POMAuctivaTest.AuctivaPageModels\ProfileManagmentPageModel.cs:line 66
       at POMAuctivaTest.TestSuite.ExistingUserTestSuite`1.CreateItemDetailProfileAndDelete() in c:\Users\jburns\Documents\Visual Studio 2013\Projects\POMAuctivaTest\POMAuctivaTest.TestSuite\ExistingUserTestSuite.cs:line 591
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The operation has timed out
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
       InnerException: 

任何帮助都会令人惊讶我对webdriver相对较新并对初学者级别的代码概念有所了解我很乐意提供额外的信息,这个问题已经让我回到了一天,并且无法承受失去更多。帮帮我Stack Overflow你是我唯一的希望。

今天3/7我的测试没有像星期四(3/4)那样达到这个例外我今天早上遇到过一次,当时我的测试正在等待弹出窗口。这是线 popupWindowHandle = finder.Click(NewListingPage.ImageSelectionPopupElement);

@PankajDubey这是我所有等待方法的样子片段。我在这里使用明确的等待吗?

public void WaitForElementVisible(IWebDriver driver, By element)
{
    try
    {
        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
        wait.Until(ExpectedConditions.ElementIsVisible(element));
    }
    catch (WebDriverTimeoutException)
    {
        TakeScreenshot(Driver);
        Console.Write("Test failed trying to wait for this element " + element.ToString() + " to be visible ");
    }
}

@Pankaj - 所以在我的OneTimeSetup中,我按照建议将所涉及的等待时间提高到了5秒。当我运行测试时,他们无法找到屏幕上的元素。测试在ClickViewScheduled()方法上反复失败。

        ListingDonePage.WaitForElementVisible(Driver, ListerDonePageModel.ViewScheduledSelector);
        var ScheduledListingPage = ListingDonePage.ClickViewScheduled();

以下是ClickViewScheduled()的定义。这对我来说很奇怪,因为在上一行中它使用我在上面发布的等待方法等待元素的可见性。所以它发现了#39;该行中的元素然后找不到点击?

    public ScheduledListingsPageModel ClickViewScheduled()
    {
        ViewScheduledElement.Click();
        return new ScheduledListingsPageModel(Driver);
    }

1 个答案:

答案 0 :(得分:0)

使用隐式等待来处理此问题,您已为每个方案声明了Web驱动程序实例而不是显式时间(等待语句)。

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));

如果它不起作用,请输入您将面临此例外的代码段,以获得更多说明。