I have a Selenium test which would fail when run as part of a Jenkins job on a node hosted in vSphere and administered through RDP. The test are run with IE11.
After some troubleshooting it turned out it succeeds if Remote Desktop is connected and focused but fails with an exception if Remote Desktop is disconnected or even minimized:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:56095/session/817b36df-a1b5-484e-b205-d4a0bac8002a/element/0cfa6678-2104-4bc6-bb71-e6d8eac507fb/value timed out after 60 seconds.
----> System.Net.WebException : The operation has timed out
The failing line:
textboxElement.SendKeys("foo").Perform();
As a workaround, I logged through vSphere Console instead of RDP and then even after closing vSphere the test didn't fail anymore. This is a workaround but I would have to be careful never to login through RDP and always to administer only through vSphere Console.
So my questions are:
Is SendKeys() somehow incompatible with an RDP session and is it related to this winapi bug?
Is there an alternative to using SendKeys() in Selenium?
When you execute the selenium script without any UI environment bind to the process the size of the Chrome window may be different from when you execute it when you are logged in with RemoteDesktop.
Try to explicitly set window size in the selenium script prior to the failing command.
1) try some small width/height and execute it where the script usually succeeds, and see what happens
2) set to some large value and execute it on Jenkins, where it usually fails.
Found the culprit - there was a flag RequireWindowFocus = true in InternetExplorerOptions which was causing the issue. After removing it I no longer get the error. This might be related to https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5431.
Related
I started working on Selenium (C#) and, to my surprise, I cannot run even the simplest project from the Selenium Docs. However, my collegues can run it normally out of the box with no problems.
The only way for me to be able to run is to add the --no-sandbox option to the Chrome option. Firefox (Gekco) driver doesn't have this problem, and my Chrome version and my Chromedriver version match. But I can't do this with every project because we're using a library that don't pass this option and it's beyond my controls.
What are the policy/configuration that I might need to change?
I have tried to find other similar threads on S/O but none of that solve my issues. Most of them can be solved by updating Chrome/ChromeDriver version but mine is at the latest of 100 (also has the same problem with Chrome 99).
Error
It just stays at data:, and doesn't proceed to any other page as it should.
Starting ChromeDriver 100.0.4896.60 (6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896#{#875}) on port 61538
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
DevTools listening on ws://127.0.0.1:61542/devtools/browser/38c3268c-dd43-4100-bb1a-71aa2af4c1fc
Unhandled exception. OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:61538/session timed out after 60 seconds.
---> System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.
---> System.TimeoutException: The operation was canceled.
---> System.Threading.Tasks.TaskCanceledException: The operation was canceled.
---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
--- End of inner exception stack trace ---
Code
using System;
using System.Threading;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
namespace SeleniumDocs.Hello
{
public class HelloSelenium
{
public static void Main()
{
var chromeOptions = new ChromeOptions();
var service = ChromeDriverService.CreateDefaultService(#"C:\WebDriver\bin");
// chromeOptions.AddArgument("--no-sandbox"); // with this it works; without, doesn't
var driver = new ChromeDriver(service, chromeOptions);
driver.Navigate().GoToUrl("https://selenium.dev");
Thread.Sleep(10000);
driver.Quit();
}
}
}
Sandbox
The sandbox is a C++ library that allows the creation of sandboxed processes — processes that execute within a very restrictive environment. The only resources sandboxed processes can freely use are CPU cycles and memory. For example, sandboxes processes cannot write to disk or display their own windows. What exactly they can do is controlled by an explicit policy. Chromium renderers are sandboxed processes.
Functionally sandbox limits the severity of bugs in code running inside the sandbox. Such bugs cannot install persistent malware in the user‘s account (because writing to the filesystem is banned). Such bugs also cannot read and steal arbitrary files from the user’s machine.
(In Chromium, the renderer processes are sandboxed and have this protection. After the NPAPI removal, all remaining plugins are also sandboxed. Chromium renderer processes are isolated from the system, but not yet from the web. Therefore, domain-based data isolation is not yet provided.
This usecase
A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
References
You can find a relevant detailed discussion in:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
while creating my test using c# and selenium i ran into a issue i haven't chad before. the test basically opens the web site, logs in as admin, and within the admin page i than have to install a plugin for this site that allows warranties feature to be enabled on the website. everything so far works, but when the test clicks the install button, the page goes into a installing/loading type of screen and then after a min my test fails because of time limits.
this this the error:
Message: OpenQA.Selenium.WebDriverException : The HTTP request to the
remote WebDriver server for URL
http://localhost:59515/session/c098338553dd7e3941e7e6c800273df3/element/0.3693091767590764-2/click
timed out after 60 seconds. ----> System.Net.WebException : The
operation has timed out.
now the test does installs the plugin as it supposed to but my test will still fail and i can not continue with the rest of the test because of this time out. I know it has to do with webdriver or remotedriver that has the default timer set to 60 seconds, but i just don't know how to go around and either extending that time limit or if there is another way to go about this?
My test script is navigating to report page, where it clicks "Download Report" button. After clicking it, an IE download dialog appears at the bottom of the page.
The issue is that it looks like driver is losing connection after clicking that button in IE. Looking for some possible workarounds.
Both IEDriver and Webdriver nuget packages are the latets versions. This is C#.
This issue is only in IE.
This is the error I am getting:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote
WebDriver server for URL
http://localhost:52706/session/ea7da8ec-add0-4562-81c2-d2ebc706a073/click
timed out after 60 seconds. ---> System.Net.WebException: The request
was aborted: The operation has timed out.
The problem here is that when IE is in the process of downloading a file, the readyState of the browser never moves from interactive to complete, meaning that the browser "wait for page load" detection never finishes. The way to stop this is to change the driver’s page load strategy on creation. The downside to this is that there is a chance that it will affect other operations in that the driver will return earlier from a page load than your code expects, so judicious use of WebDriverWait in other parts of your code will be required. The code to set the page load strategy is something like the following:
// DISCLAIMER: Code below written from memory,
// without benefit of Visual Studio or
// another IDE. It might require modification
// to work properly, or even to compile.
InternetExplorerOptions options = new InternetExplorerOptions;
options.PageLoadStrategy = PageLoadStrategy.Eager;
IWebDriver driver = new InternetExplorerDriver(options);
I have a Topshelf C# service that must restore adapter DNS settings when exiting. My stop/start methods work just fine and this code works:
ManagementObject.InvokeMethod("SetDNSServerSearchOrder", DNS, null);
Shutdown, however, is a problem, even with RequestAdditionalTime
I log the following error:
2016-11-30 15:10:53,427 [7] TRACE MyDNSService - DNSService Shutdown command received.
2016-11-30 15:10:53,677 [7] DEBUG MyDNSService - DNSService Error setting DNS: A system shutdown is in progress. (Exception from HRESULT: 0x8007045B)
So it appears that the OS is blocking my call to ManagementObject.InvokeMethod
I'm stymied. Is there a way around this issue? On startup my service detects the anomaly and recovers, but that takes too long. I'd really like to be able to shutdown gracefully.
Rocky, I just re-created the functional elements of your code (logging what's happening) but I'm not getting the error. I'm setting the DNSServerSearchOrder to null and feeding that to the SetDNSServerSearchOrder method of the management object. https://github.com/paulsbruce/StackOverflowExamples/blob/master/PriorityShutdown/PriorityShutdown/MyService.cs
My only additional recommendation is that you can try changing the priority of the shutdown order of your service to see if that has any effect. See this thread: .NET Windows Services stopping order when the system shutdown
I want to run Fiddler to help debug a portable API client that I'm developing.
In Visual Studio, on the Windows Store Unit Test project property page > Debug tab I have checked the 'Allow Local Network Loopback' option.
Every web request run during a store unit test fails with a System.Net.Sockets.SocketException : A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond 127.0.0.1:8888.
The Uri I'm connecting to is not local - but another machine on the local network - so this fiddler loopback address is indeed coming from the global proxy setting.
I know that for Windows Store Apps you have to enable the loopback network isolation exemptions and have ticked every app container listed in the UI for that (despite none of them being related to VS or this unit test projects) - to no avail.
I've also tried disabling IPv6 in Fiddler - don't know why I thought that might work, but it was worth a punt - it didn't work either.
Anyone got any ideas!?
Okay - whilst I was on the right track, thinking that there must be some app container registered for the unit test project - what I didn't think was that it might only be active while MSTest is running.
You need to debug the Windows Store unit test (any of the tests in the project) and stick a breakpoint in (to halt execution of the test runner) so it will then appear in the list of AppContainers within Fiddlers' Loopback Extensions tool.
So - given this test:
[TestMethod]
public async Task Example()
{
var result = await GetSomeData(); //<-- breakpoint
Assert.IsNotNull(result);
}
private async string GetSomeData()
{
//TODO something that makes a web request with, say, HttpClient
}
All you do is breakpoint the line shown above - and then launch the 'Win8 Config' option from Fiddler - and you'll see that your unit tests project appears in the list of AppContainers.
Enable loopback for that app container, save the changes and then continue in your unit test - you should see the traffic correctly captured.
After doing this once it would seem that you don't have to do it again - I've closed down fiddler and restarted it and the traffic is still captured correctly.
One word of warning, however, once you do this the Loopback exemptions tool will moan about an exemption being defined for a SID for which there is no AppContainer if it is launched - unless you happen to be running a unit-test again.