I am trying to run Selenium test using .net core 2 and xunit
As Selenium server I am using docker container as documented here:
https://github.com/SeleniumHQ/docker-selenium
Running container with command:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome
Test code
public void Test()
{
IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444"), new ChromeOptions());
driver.Navigate().GoToUrl("https://www.google.com");
var s = ((ITakesScreenshot)driver).GetScreenshot();
s.SaveAsFile("screen.jpg");
}
When I try to run the test I get exception:
System.PlatformNotSupportedException : Operation is not supported on this platform.
at System.Net.SystemWebProxy.GetProxy(Uri destination)
at System.Net.ServicePointManager.ProxyAddressIfNecessary(Uri& address, IWebProxy proxy)
at System.Net.ServicePointManager.FindServicePoint(Uri address, IWebProxy proxy)
at System.Net.HttpWebRequest.get_ServicePoint()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.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 Automation.LoginTests.Test() in C:\Git\Automation\test\Tests\LoginTests.cs:line 29
Same result when I am running on linux (Debian 9) or Windows 10.
Am I doing something wrong? Selenium seems to be able to support .NET Core 2
Found an issue on github thanks to this comment.
https://github.com/SeleniumHQ/selenium/issues/4770
Workaround with working code is described here:
https://github.com/SeleniumHQ/selenium/issues/4770#issuecomment-337370420
Related
I'm using C# and Selenium and Chromedriver to run tests.
I'm getting this error:
Unhandled exception. OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /Applications/Google Chrome.app/Contents/MacOS/Google Chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
But it only crashes if I remove the _chromeOptions.AddArgument("headless");, and only on a Mac. I tested on an Intel Mac, an M1 Mac, and a Windows. Windows runs without headed just fine.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
ChromeOptions _chromeOptions = new ChromeOptions();
_chromeOptions.AddArgument("headless");
_chromeOptions.AddArgument("version");
IWebDriver Driver = new ChromeDriver(_chromeOptions);
Driver.Navigate().GoToUrl("https://google.com");
Driver.Close();
From existing SO posts and other resources I found, I have tried adding various other arguments to chromeoptions including:
--headless=false
--no-sandbox
--disable-gpu
--verbose
and also specifying the binary:
_chromeOptions.BinaryLocation = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
I'm using an M1 Macbook Pro, Visual Studio for Mac 17.4.3 (build 21), Selenium.Webdriver 4.8.0, Selenium.Webdriver.ChromeDriver 109.0.5414.7400, and Google Chrome 109.0.5414.87 (Official Build) (arm64)
Because the driver is initialized deep in an in-house library, I can't simply remove the version line, and I need it to not be headless so I can verify the test I'm writing actually does what it's supposed to.
I run into issue when trying to run unit tests for a website using ChromeDriver. Here is the stack trace from job log:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:37329/
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace: at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
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 OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)
at ScamTeamWebsiteTests.Tests.Setup() in /builds/kostyabek/ScamTeamWebsiteTests/ScamTeamWebsiteTests/WebSiteTests.cs:line 19
.yml file contents
image: mcr.microsoft.com/dotnet/sdk:6.0
stages:
- build
- test
variables:
projFolder: "ScamTeamWebsiteTests"
projName: "ScamTeamWebsiteTests.csproj"
before_script:
- "apt-get update -qy"
- "apt-get -y install zip unzip"
- "cd ${projFolder}"
- "wget https://chromedriver.storage.googleapis.com/102.0.5005.27/chromedriver_linux64.zip"
- "unzip chromedriver_linux64.zip -d '/home/kostyabek'"
build:
stage: build
script:
- "dotnet build"
unit-test:
stage: test
script:
"dotnet test ${projName}"
Basically, I have no idea what to do with it. I am relatively new to both CI/CD pipelines and Selenium.
You need to run an instance of selenium chrome with your unit-test stage. Downloading chromedriver may be unnecessary.
unit-test:
stage: test
services:
- name: selenium/standalone-chrome:latest
script:
- dotnet test ${projName}
You will need to configure your test suite to connect to the remote web driver at http://selenium__standalone-chrome:4444/wd/hub, when running in the CI test environment.
https://docs.gitlab.com/ee/ci/services/#accessing-the-services
I am having troubles trying to run simple UI test in Visual Studio (16.11.10) using C# and NUnit. I am using Selenium.Firefox.WebDriver version 0.27.0., Selenium.WebDriver and Selenium.Support both 4.1.0
Test:
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace ClassLibrary2
{
public class Class1
{
[Test]
public static void TestBrowser()
{
IWebDriver driver = new FirefoxDriver();
driver.Url = "https://login.yahoo.com/";
driver.Quit();
}
}
}
Running this test I am getting such error:
TestBrowser
Source: Class1.cs line 10
Duration: 4,6 sec
Message:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:59898/
Stack Trace:
DriverService.Start()
DriverServiceCommandExecutor.Execute(Command commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.StartSession(ICapabilities desiredCapabilities)
WebDriver.ctor(ICommandExecutor executor, ICapabilities capabilities)
FirefoxDriver.ctor(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
FirefoxDriver.ctor(FirefoxOptions options)
FirefoxDriver.ctor()
Class1.TestBrowser() line 18
Standard Output:
Unable to connect to the remote server
All works fine using ChromeDriver. Thanks for your help.
Possibly Selenium.Firefox.WebDriver version 0.27.0 points to the older GeckoDriver of version0.27.0. Hence you see the error.
The solution would be to upgrade to latest version of GeckoDriver i.e. version0.30.0
Information
Hello mates! Several days ago, I've ran into issue with Selenium and that is to be exact the error in the title. I have been trying to resolve this issue myself for some days now with no luck at all. Chrome is being run from external file, when I try to open manually, it works. If I try to run the driver from the default location, it works. I've tried different versions of Selenium with no luck and different versions of Chrome.
Expected results
ChromeDriver will execute chrome.exe.
Actual results
ChromeDriver fails to start chrome.exe for unknown reason.
CLI Picture
Code
ChromeDriver driver = new ChromeDriver(new ChromeOptions { BinaryLocation = Path.Combine(Environment.CurrentDirectory, #"GoogleChromePortable") });
Exception details
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=unknown error: Failed to create Chrome process.
Source=WebDriver
StackTrace:
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(ChromeOptions options)
at Self_Contained.Program.Main(String[] args) in *:\*\*\SFC\Program.cs:line 11
After hours of research I found somewhere that excluding chrome.exe may lead to this issue. I added chrome.exe to the binary path and voilà it is working.
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.