Selenium Continuous Integration with Team Services - selenium

I have a set of Selenium tests in a test project within my solution, and they run just fine from within Visual Studio. However, when I check in code and they run as part of my continuous integration build profile, they fail.
A brief explanation of the setup:
1) Code is checked into the build agent server.
2) The project is then built, and then deployed to server 2 (which is remote from the build server).
3) Unit tests then run.
Here is an example unit test:
public void Login_InvalidAccessUrl_ShowMesage()
{
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl("https://testsite.company.com/Login");
IWebElement el = driver.FindElementById("invalidAccessUrlSection");
Assert.AreNotEqual(el, null);
}
This runs beautifully from Visual Studio, but when CI runs the same tests, I get the following:
Error Message:
Test method eNotify.Staff.Tests.SeleniumTests.Login_InvalidAccessUrl_ShowMesage threw exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:11570/session timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
TestCleanup method eNotify.Staff.Tests.SeleniumTests.Dispose threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
Stack Trace:
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor()
at eNotify.Staff.Tests.SeleniumTests.Login_InvalidAccessUrl_ShowMesage()
TestCleanup Stack Trace
at eNotify.Staff.Tests.SeleniumTests.Dispose()
Am I missing a driver or some software? As far as I know, there is nothing listening on port 11570.

First, make sure the VSTS agent is running as Interactive process.
Secondly, adding no-sanbox argument to ChromeDrive instance. For example:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("no-sandbox");
driver = new ChromeDriver(chromeOptions);

Related

webdriver is giving timeout error after opening IE start page

I am moving from selenium 3 to 4 and trying to run my tests in edge-IE mode. After starting the IEDriver with
var driver = new InternetExplorerDriver(ieOptions);
the browser opens but then does not hand control back the the code for the next step, instead I get a time out error.
here is my code.
var options = new InternetExplorerOptions();
options.AttachToEdgeChrome = true;
options.EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe";
//options.BrowserCommandLineArguments = "-private";
IWebDriver edgeIeMode = new InternetExplorerDriver(options);
here is the error
Unhandled Exception, See screenshotOpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:63459/session/197d3eaa-361d-433e-b8b5-0b5d6acb1e7b/url timed out after 60 seconds. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.Remote.HttpCommandExecutor.d__35.MoveNext()
Verify that your edge and webdriver versions are up to date. Typically this happens when a version mismatch can't connect to the browser. I'm not sure if edge uses an IEdriver.exe executable, but if it does, verify that version too.

Causes of Selenium failing when being executed as SYSTEM user from a Windows Scheduled Task

For some context, I have a Windows Scheduled Task set-up running as the SYSTEM user, which periodically opens a small Console Application which makes use of Selenium and specifically the IE Driver. This works perfectly well for a long period of time, but after a month or two has passed it eventually begins failing every time the scheduled task executes with the error below.
The only solution I have found is to restart the application server, whereby the issue is resolved for another month or two, until it magically reappears.
I have taken a look at other Stack Overflow questions of a similar nature, but their solutions haven't allowed this to be resolved. The questions also don't appear to run Selenium as a Scheduled Task as the SYSTEM user so I feel this is a unique take on the issue?
Does anyone have any advice as to what might be causing this issue to reappear? I am looking to avoid having to restart the server as this has to be scheduled in, resulting in a number of days with my Scheduled Task being in the disabled state causing me to less aware of my application isn't working.
Message: The HTTP request to the remote WebDriver server for URL http://localhost:57185/session timed out after 240 seconds.
InnerException: System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
StackTrace: at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(String internetExplorerDriverServerDirectory, InternetExplorerOptions options, TimeSpan commandTimeout)

c# - Selenium 3.14.0 + BrowserStack - Webdriver exception - Receive failure and instantiation fails

I recently upgraded to Selenium 3.14 from 3.9.1 . Now everytime I run, I am getting below error where I try to instantiate the webdriver. Below is the line where it fails and throws an expecption.
When I downgrade to 3.9.1 it works fine. Is there something I am missing? Has anyone see this before?
I am using c# + Spec flow + BrowserStack grid.
Please let me know if you need more information. This is my first post and have googled and researched but couldn't find any information regarding this error.
_driver = new RemoteWebDriver(new Uri("http://" + browserStackConfig["BSserver"] + "/wd/hub/"), capability, new TimeSpan(0,0,30));
Result Message:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://hub-cloud.browserstack.com/wd/hub/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.
----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive.
----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host
Selenium made a change on Jul 25th to expose the Proxy property from HttpCommandExecutor class ( Below is the link) . You would expect that if no Proxy is passed then the Selenium would use Default Web Proxy. This is not the case. The proxy is being set to null which would cause the executor to fail while instantiating the driver.
https://github.com/SeleniumHQ/selenium/commit/52969e49a16efee7efb52893addde19605162a66#diff-bc8a75c5cb22ca86093a1bbced41a6ee
Fix:
I made a simple change in my code to pass the default web proxy. Below is the code snippet. This fixed my issue.
var executor = new HttpCommandExecutor(new Uri("http://" + browserStackConfig["BSserver"] + "/wd/hub/"), new TimeSpan(0, 0, 0, 30));
executor.Proxy = WebRequest.DefaultWebProxy;
_driver = new RemoteWebDriver(executor, capability);

Running Selenium scripts on Bluemix

I am completely new to testing and Bluemix. As per my requirement, I need to run Selenium scripts on Bluemix. I am using Automated Accessibility Tester service in Bluemix for running Selenium scripts. I have added the service to my space and added the aat.jar and the Tool Configuration JSON file to my working directory. I have added some scripts to my test case for running on remote server. However, I am getting the following error message:
error Message: setEnabledIds INFO: Enabled Rulesets: IBM_DCP080115
FAILED CONFIGURATION: #BeforeClass setUp
org.openqa.selenium.remote.UnreachableBrowserException: Could not
start a new session. Possible causes are invalid address of the remote
server or browser start-up failure.
This is the script that I have added:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ComplianceConfig config = new ComplianceConfig(new String[] { "IBM_DCP080115" });
driver = ComplianceDriverRemote.init(config, capabilities);
I am getting an error at driver = ComplianceDriverRemote.init(config, capabilities);
For running test cases on Bluemix, I am following this link: https://console.ng.bluemix.net/docs/services/ecsdashboard/index.html

Possible reasons for Selenium RemoteWebDriver command timeouts

We have a number of Selenium tests running 24/7 and a few times a day we are getting random
webdriver timeout exception. For example:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://*.*.*.*:4444/wd/hub/session/4957b6a8-c885-4dd7-98ab-373f35619495/url timed out after 120 seconds. ---> System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.get_Url()
...
Usually it happens in random places (when fetching the current URL, when clicking an element, finding an element, etc.) and in different tests.
RemoteWebDriver's command timeout for HTTP requests is set to 120s and none of the timeouts set with Manage().Timeouts().* exceed 60 seconds.
My question is, what could be the possible reasons for the command timeout?
It looks like Selenium or possibly the ChromeDriver just locks occasionally for whatever reason. Although I am unable to verify anything visually since the tests are executed on a headless machine.
Could it be that we overlooked or misunderstood some timeout setting?
Versions:
Selenium v2.42.2, .NET bindings v2.40.0, ChromeDriver 2.10