无法创建新服务:ChromeDriverService [英] Unable to create new service: ChromeDriverService

查看:803
本文介绍了无法创建新服务:ChromeDriverService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经全局安装了Selenium Standalone:

I have globally installed Selenium Standalone:

npm install selenium-standalone -g
selenium-standalone install --singleDriverInstall=chrome

我也混编了此页上的代码进入此dotnet核心/ 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();
        }
    }
}

我正在尝试启动Selenium-standalone with ChromeDriver,以便我可以驱动浏览器执行浏览器测试。

I am trying to start up selenium-standalone with ChromeDriver so that I can driver the browser to perform browser testing.

托管自己的Web应用程序-这是

I am not hosting my own web application - this is only test run tests against a site which is already running.

睡眠是为了让硒在Shell进程中启动。

The Sleep is to allow selenium to start up in the shell process.

但是,当使用 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:\git\core\XunitTestLib\Unit\BasicBrowserTest.cs:line 46

Total tests: 1. Passed: 0. Failed: 1. Skipped: 0.
Test Run Failed.

错误指示的行是此行: Browser = new RemoteWebDriver(选项);

The line the error is indicating is this line: Browser = new RemoteWebDriver(options);

我的理解是ChromeDriver尝试通过HTTP连接连接到硒,但是无法启动/初始化。

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆