I am having issues running Selenium Grid from Visual Studio from Csharp using Selenium 4. I keep getting the error:
Message:
System.InvalidOperationException : Could not start a new session. Could not start a new session. Error while creating session with the driver service. Stopping driver service: Driver server process died prematurely.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown (SessionNotCreated)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
WebDriver.UnpackAndThrowOnError(Response errorResponse)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.StartSession(ICapabilities desiredCapabilities)
WebDriver.ctor(ICommandExecutor executor, ICapabilities capabilities)
RemoteWebDriver.ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
RemoteWebDriver.ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
WebDriverFactory.OpenBrowser() line 28
BaseTest.Test_Setup() line 54*
Can you tell me what I am missing. I downloaded the .jar file from this location - https://www.selenium.dev/downloads/
I started selenium hub on my local machine here:
I then registered selenium node here:
I made sure I can get to grid here:
Here is my code (I initially used http://localhost:4444/wd/hub) but still got the same error:
When I change the code to
I get this error
_driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), browserOptions);
Message:
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:4444/wd/hub/session timed out after 60 seconds.
----> 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 : The I/O operation has been aborted because of either a thread exit or an application request.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.*
This error message...
System.InvalidOperationException : Could not start a new session. Could not start a new session. Error while creating session with the driver service. Stopping driver service: Driver server process died prematurely.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ATTPA-1450', ip: '172.26.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.12'
Driver info: driver.version: unknown
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Possibly your main issue is the incompatibility between the version of the binaries you are using as the ChromeDriver version is not getting detected:
Driver info: driver.version: unknown
Solution
Ensure that:
ChromeDriver is updated to current ChromeDriver 97.0.4692.71 level.
Chrome is updated to current chrome=Version 97.0.4692.71 (as per chrome=97.0.4692.71 release notes).
Related
I'm running tests on a Remote Machine through Azure daily scheduled run. Some of the tests are failing with below error log. How can I fix this ?
Note : I do not have method implementation of launching chrome driver as I am referencing dll of other solution which has abstract methods.
Stack : NUnit, C#, Selenium, Visual Studio, Azure, log4Net
OneTimeSetUp:
Automation.Test.Framework.Models.Exceptions.AtGenericException : Error
initializing WebDriver Chrome
----> System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException: Failed to read the
'localStorage' property from 'Window': Access is denied for this
document. at :1:1 (Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.36.540470
(e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT
6.3.9600 x86_64)
This error message...
OneTimeSetUp: Automation.Test.Framework.Models.Exceptions.AtGenericException : Error initializing WebDriver Chrome
System.InvalidOperationException : unknown error: Runtime.evaluate threw exception: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. at :1:1 (Session info: chrome=77.0.3865.90)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.3.9600 x86_64)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.36
Release Notes of chromedriver=2.36 clearly mentions the following :
Supports Chrome v63-65
You are using chrome= 77.0
Release Notes of ChromeDriver v77.0.3865.40 clearly mentions the following :
Supports Chrome version 77
So there is a clear mismatch between the ChromeDriver v2.36 and the Chrome Browser v77.0
Solution
Ensure that:
ChromeDriver is updated to current ChromeDriver v78.0 level.
Chrome is updated to current Chrome Version 78.0 level. (as per ChromeDriver v78.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Guess you should changed the default Chrome capabilities to allow third-party cookies:
Disabling Cookies in Webdriver for Chrome/Firefox
Ever since the latest Chromium update I have been unable to run Selenium on Linux (.NET Core)
Google Chrome is installed on usr/bin/google-chrome, and I have made sure of it as I have ran it directly from the directory it's stored in.
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}) on port 32911
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Unhandled Exception: OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Linux 4.15.0-45-generic x86_64)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
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(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at selenium.Program.Main() in REDACTED
Aborted (core dumped)
I have tried disabling shm, use headless mode, and other recent issues on this topic, but none have worked.
ChromeOptions options = new ChromeOptions();
options.AddArguments("--headless --no-sandbox");
options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
IWebDriver webDriver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options);
webDriver.Navigate().GoToUrl(#"file:///login.html");
The expected output is for ChromeDriver not to throw an exception and crash.
I am trying to run selenium UI tests through vsts release pipeline usingVisual Studio Test tasks from vsts release. My tests are getting recognized but not getting executed. getting same error for all tests.
I have tried updating the chrome drive used the old chrome driver still no luck. Initially I was using the chromedrive.exe file in my sln but then I removed that and add a nuget reference form Selenium.Chrome.Webdriver 2.45. tests are running fine on my local machine but when I deploy on vsts agent server I am getting an error
this the error I am getting in my VsTest log
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 4620
Only local connections are allowed.
Failed _MenuConfirmation
Error Message:
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:4580/session/1315de45cb967b450b25cef659f6/window/current/size timed out after 60 seconds.
----> System.Net.WebException : The operation has timed out
Stack Trace:
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.RemoteWindow.set_Size(Size value)
at abc.AutomatedTests.BaseTestingClass.CommonInit() in D:\teams\build4\_work\1\s\src\abc.AutomatedTests\BaseTestingClass.cs:line 43
--WebException
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
In my basetestingclass.cs I have code to launch the browser and set its size.
[SetUp]
public void CommonInit()
{
driver = new SeleniumDriver (browser).getdriver();
driver.Navigate().GoToUrl(url);
driver.Manage().Window.Size = new Size { Width = 1920, Height = 1080 };
//driver.Manage().Window.Maximize();
}
In my prior tries I was getting same error for Maximize() code.
This is was added in mu csproj after the nuget addition
<Import Project="..\packages\Selenium.Chrome.WebDriver.2.45\build\Selenium.Chrome.WebDriver.targets" Condition="Exists('..\packages\Selenium.Chrome.WebDriver.2.45\build\Selenium.Chrome.WebDriver.targets')" />
and this in packages.
<package id="Selenium.Chrome.WebDriver" version="2.45" targetFramework="net452" />
I want to Run the selenium tests In my VSTS pipeline using the Visual Studio Test. Also I have Visual Studio Test Platform Installer task prior to test execution task in my pipeline and my tests are getting recognized successfully.
I tried most of the available solution but still the same error. hence asking again.
The error message indicates that the agent you are running the UI tests on can't reach the URL you've specified.
Are you using a hosted agent in the release pipeline in AzDO? If so, it won't have line of sight to your localhost URL. Check that by changing your URL to google.com or bing.com and it should be able to run the test successfully.
Install a self-hosted agent on your machine instead: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops#install
Or follow this: https://www.azuredevopslabs.com/labs/vstsextend/selenium/.
You'll want to make sure that the appropriate NuGet packages for Selenium are also getting restored but I don't think that's specifically related to this error you're getting.
I'm trying to use Azure WebApps, with Webjobs, to Test applications.
Locally, it works great. But when I build to cloud it happens the problem listed above.
Apperently the file was found, but it stays wainting until timeout.
Does anybody knows how to solve this?
I'm using C# Selenium WebDriver.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Diagnostics;
using System.IO;
namespace Ololu_WebJob
{
class Program
{
static void Main()
{
IWebDriver driver = new ChromeDriver();
driver.Url = "my_url";
Console.WriteLine(driver.Title);
driver.Quit();
}
}
}
/*
LOG:
[02/10/2019 12:27:51 > 7f9c27: SYS INFO] Status changed to Initializing
[02/10/2019 12:27:51 > 7f9c27: SYS INFO] Job directory change detected: Job file 'Ololu_WebJob.exe' timestamp differs between source and working directories.
[02/10/2019 12:27:53 > 7f9c27: SYS INFO] Run script 'chromedriver.exe' with script host - 'WindowsScriptHost'
[02/10/2019 12:27:53 > 7f9c27: SYS INFO] Status changed to Running
[02/10/2019 12:27:53 > 7f9c27: INFO] Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 9515
[02/10/2019 12:27:53 > 7f9c27: INFO] Only local connections are allowed.
[02/10/2019 12:27:53 > 7f9c27: INFO] Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[02/10/2019 12:31:55 > 7f9c27: ERR ] Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
cmd /c ""chromedriver.exe""
[02/10/2019 12:31:55 > 7f9c27: SYS INFO] Status changed to Failed
[02/10/2019 12:31:55 > 7f9c27: SYS ERR ] System.AggregateException: One or more errors occurred. ---> Kudu.Core.Infrastructure.CommandLineException: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
cmd /c ""chromedriver.exe""
at Kudu.Core.Infrastructure.IdleManager.WaitForExit(IProcess process) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\IdleManager.cs:line 45
at Kudu.Core.Infrastructure.ProcessExtensions.<Start>d__12.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\ProcessExtensions.cs:line 212
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Kudu.Core.Infrastructure.Executable.<ExecuteAsync>d__31.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 255
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Kudu.Core.Infrastructure.Executable.ExecuteInternal(ITracer tracer, Func`2 onWriteOutput, Func`2 onWriteError, Encoding encoding, String arguments, Object[] args) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 216
at Kudu.Core.Infrastructure.Executable.ExecuteReturnExitCode(ITracer tracer, Action`1 onWriteOutput, Action`1 onWriteError, String arguments, Object[] args) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 165
at Kudu.Core.Jobs.BaseJobRunner.RunJobInstance(JobBase job, IJobLogger logger, String runId, String trigger, ITracer tracer, Int32 port) in C:\Kudu Files\Private\src\master\Kudu.Core\Jobs\BaseJobRunner.cs:line 272
---> (Inner Exception #0) ExitCode: -1, Output: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed., Error: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed., Kudu.Core.Infrastructure.CommandLineException: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
cmd /c ""chromedriver.exe""
at Kudu.Core.Infrastructure.IdleManager.WaitForExit(IProcess process) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\IdleManager.cs:line 45
at Kudu.Core.Infrastructure.ProcessExtensions.<Start>d__12.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\ProcessExtensions.cs:line 212
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Kudu.Core.Infrastructure.Executable.<ExecuteAsync>d__31.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 255<---
*/
Per my experience, you can not directly use selenium and chromedriver without an installed instance of Chrome or Chromium on Azure WebApp, as the requirement of ChromeDriver Setup said below.
Ensure Chromium/Google Chrome is installed in a recognized location
ChromeDriver expects you to have Chrome installed in the default location for your platform. You can also force ChromeDriver to use a custom location by setting a special capability.
However, due to some restricts of Azure WebApp sandbox which include Win32k.sys (User32/GDI32) Restrictions and Local Address Requests, you could not start Chrome or Chromium without GDI support via chromedriver even if you uploaded a portable distribution of Chrome or Chromium into Azure WebApp and configured environment variables.
Although your error information did not point out the real reason of the issue in your C# code, I got the error information in Python on Azure WebApp as below.
So a workaround way is to directly use selenium and chromedriver on Azure VM. Or considering for your scenario, you can start chromedriver on default port 9515 on Azure VM and configure the VM NSG role to allow the inbound of port 9515, then to use class OpenQA.Selenium.Remote.RemoteWebDriver to connect the remote webdriver in Azure WebJob.
Here is a sample code for using RemoteWebDriver which comes from C# (CSharp) OpenQA.Selenium.Remote RemoteWebDriver.FindElement Examples
IWebDriver webDriver = new RemoteWebDriver(new Uri("http://<vm host ip>:9515"), DesiredCapabilities.Chrome());
I created an application that use Selenium using .NetCore for use it on Linux, actually this is my code implementation:
public class Program
{
public static async Task Main(string[] args)
{
//Settings for chrome
var chromeOpts = new ChromeOptions();
chromeOpts.AddArgument("headless");
chromeOpts.AddArgument("no-sandbox");
//Get assembly path where chrome driver is located
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
path = Path.GetDirectoryName(path);
var driver = new ChromeDriver(path, chromeOpts, TimeSpan.FromSeconds(180));
}
}
as you can see I am using as driver Chrome, I downloaded it here, I also added the driver inside the folder of the assembly, in this way the ChromeDriver knows already where to search it.
On linux I changed the folder permission using chmod -R 777, but when I run my Dotnet application I get this:
Seems that Selenium cannot start the application.
Looking at the Exception I get:
Cannot find Chrome binary
Unfortunately I didn't find anything similar on the web, someone could help me?
Thanks in advance.
UPDATE
I Just reinstalled Chrome on my linux machine and now the error above went away, but there is another problem now, infact I get this error:
OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9.248304,platform=Linux 4.4.0-130-generic x86_64)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
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(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)\ at ODS.Program.Main(String[] args)
This error message...
OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.9 which is pretty ancient.
So there is a clear mismatch between the ChromeDriver version (v2.33) and the recent Chrome Browser version (vVersion 68.0)
Solution
Upgrade ChromeDriver to current ChromeDriver v2.41 level.
Keep Chrome version between Chrome v67-69 levels. (as per ChromeDriver v2.41 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Execute your #Test.
References
You can find a couple of relevant discussions in:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium on debian server
Message: unknown error: Chrome failed to start: exited abnormally on AWS Cloud9 with Linux 4.9.85-38.58.amzn1.x86_64 x86_64
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS
first, check your google-chrome version
then download related chromedriver version i.e