无法创建新服务:ChromeDriverService [英] Unable to create new service: ChromeDriverService
问题描述
我已经全局安装了 Selenium Standalone:
I have globally installed Selenium Standalone:
npm install selenium-standalone -g
selenium-standalone install --singleDriverInstall=chrome
我还将 此页面中的代码混入此 dotnet core/XUnit测试:
I have also bastardised the code from this page into this dotnet core / XUnit test:
using System.Threading;
using System;
using Xunit;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Chrome;
using System.Diagnostics;
namespace XunitTestLib.Unit
{
public class BasicBrowserTest : IDisposable
{
public Process _process;
public IWebDriver Browser { get; }
public BasicBrowserTest()
{
_process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "selenium-standalone",
Arguments = "start --drivers=chrome",
UseShellExecute = true
}
};
_process.Start();
var options = new ChromeOptions();
// options.AddArgument("--headless");
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--allow-insecure-localhost");
options.AddArgument("--acceptInsecureCerts=true");
options.AddArgument("--proxy-server='direct://'");
options.AddArgument("--proxy-bypass-list=*");
options.SetLoggingPreference(OpenQA.Selenium.LogType.Browser, LogLevel.All);
Thread.Sleep(4000);
Browser = new RemoteWebDriver(options);
}
public void Dispose()
{
Browser.Dispose();
_process.CloseMainWindow();
}
}
}
我正在尝试使用 ChromeDriver 启动 selenium-standalone,以便我可以驱动浏览器来执行浏览器测试.
I am trying to start up selenium-standalone with ChromeDriver so that I can driver the browser to perform browser testing.
我不托管我自己的网络应用程序 - 这只是针对已经在运行的网站的测试运行测试.
I am not hosting my own web application - this is only test run tests against a site which is already running.
Sleep 是让 selenium 在 shell 进程中启动.
The Sleep is to allow selenium to start up in the shell process.
但是,当使用 dotnet test --filter DisplayName="Homepage"
运行时,我得到了这个输出:
However, I get this output when run with dotnet test --filter DisplayName="Homepage"
:
[xUnit.net 00:00:04.88] Homepage [FAIL]
Failed Homepage
Error Message:
System.InvalidOperationException : Unable to create new service: ChromeDriverService
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:22:52'
System info: host: 'horacepc', ip: '191.191.191.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: driver.version: unknown (SessionNotCreated)
Stack Trace:
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.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(DriverOptions options)
at XunitTestLib.Unit.BasicBrowserTest..ctor() in C:gitcoreXunitTestLibUnitBasicBrowserTest.cs:line 46
Total tests: 1. Passed: 0. Failed: 1. Skipped: 0.
Test Run Failed.
错误指示的行是这一行:Browser = new RemoteWebDriver(options);
The line the error is indicating is this line: Browser = new RemoteWebDriver(options);
我的理解是 ChromeDriver 正在尝试通过 HTTP 连接连接到 selenium,但无法启动/初始化.
My understanding is that the ChromeDriver is attempting to connect to selenium via an HTTP connection, but is failing to start/initialise.
我不明白为什么它失败了.
I don't understand why it is failing.
推荐答案
结果是包含所需的 NuGet 包列表.来自 Scott Hanselman 的博文 记录了这些内容:
The answer turns out to be including the required list of NuGet packages. The blog post from Scott Hanselman documents these:
dotnet add package "Selenium.Support"
dotnet add package "Selenium.WebDriver"
上面帖子中的代码需要第三个包才能工作:
This third package is required for the code in the post above to work:
dotnet add package "Selenium.WebDriver.ChromeDrive"
这篇关于无法创建新服务:ChromeDriverService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!