Reputation: 101
So I'm running automated UI tests with Selenium Web Driver (using PhantomJS as a headless browser) on a web application. When I get to a certain point in my test -- a page where the web app takes over a minute to load the next page (up to 3 minutes some times) -- It will fail.
I get below error message:
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.
I have set the wait time interval to 300 seconds yet it always times out after 60 seconds. Has anyone experienced this error? Here is my code:
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();
....
Test will always time out on step below -- Enter on next button triggers a new page to load (which takes up to 3 minutes) -- I have checked and the rest of my UI tests in the suite run fine with below step commented out.
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;
Is there something I don't know about time intervals or that I am doing wrong? I have included no ImplicitWaits anywhere else in the code and have not included any System.Sleep(s). Why do my tests always timeout after 60 seconds when i have the interval time set to 300 seconds with WebDriverWait wait = new WebDriverWait(wd, new TimeSpan(0, 0, 300));
? Any help would be greatly appreciated, thanks!!
Upvotes: 3
Views: 8075
Reputation: 11
update 24-10-2022: webBrowser = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromMinutes(5));
Upvotes: 1
Reputation: 101
After a lot of investigation (and about a million google searches) I have figured out and fixed the problem affecting my automated Selenium tests. The 60 second HTTP timeout error was coming from the Selenium RemoteWebDriver's default settings, this line in the source code > https://github.com/SeleniumHQ/selenium/blob/9ca04253b7ed337852d50d02c72cb44a13169b71/dotnet/src/webdriver/Remote/RemoteWebDriver.cs#L69
protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60);
The only way to change this value of 60 seconds is to do so when you instantiate your webdriver, in my case I am using PhantomJS and the code looked like this >
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);
My old tests were timing out because of an ASP.net __doPostBack button that would take longer than 60 seconds to fetch data from my database when I selected a lot of arguments/items and therefore would trigger the default command timeout for HTTP requests seen in the WebDriver source code. I know this was the problem because the test would never time out on the postback with under 3 arguments/items selected.
Hope this solution can help someone else, cheers!
Upvotes: 7