System.InvalidOperationException:无法创建新服务:在本地计算机上使用ChromeDriver和SeleniumGrid的ChromeDriverService

问题描述 投票:3回答:1

我在我的本地机器上设置了Selenium Grid(Hub和Node),它使用以下命令在Windows 10上运行注册Hub。

java -jar selenium-server-standalone-3.141.59.jar -role hub

为了注册节点,我使用了以下命令

java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://10.37.34.2:4444/grid/register -port 5454

在命令提示符下,它显示“节点已注册到集线器并准备使用”

http://localhost:4444/grid/console验证了网格控制台。一切都很好看。

当我在visual studio中执行一个简单的测试用例时,我看到了以下错误消息。

结果消息:

System.InvalidOperationException : Unable to create new service: ChromeDriverService
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'PCD-F3FD2', ip: '10.37.34.2', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_172'
Driver info: driver.version: unknown (SessionNotCreated)

在Hub命令提示符上,我可以看到

"20:47:46.539 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, goog:chromeOptions: {}, platformName: windows}
20:47:46.542 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=0c4146b1-d7d9-4f39-91ce-b30c57c53342, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platformName=WIN10, platform=WIN10}"

在Node命令提示符上,我可以看到

20:47:46.601 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome",
"goog:chromeOptions": {
},
"platformName": "windows"}


20:47:46.602 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

下面是我的C#代码:

[Test]
    public void AccessGoogle()
    {

        ChromeOptions options = new ChromeOptions();
        options.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
        options.PlatformName = PlatformType.Windows.ToString();

        IWebDriver d = new RemoteWebDriver(new Uri("http://10.37.34.2:4444/wd/hub"), options.ToCapabilities());

        d.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);

        d.Url = "https://www.google.com/";
    }

你能帮我理解出了什么问题吗?

我也调整了我的机器防火墙设置。但没有运气!

selenium selenium-webdriver webdriver selenium-chromedriver selenium-grid
1个回答
2
投票

由于您已在本地计算机上设置了Selenium Grid(Hub和Node),因此在初始化Selenium Grid Node时,您需要通过Dwebdriver.chrome.driver参数传递ChromeDriver位置的绝对路径,如下所示:

java -Dwebdriver.chrome.driver=C:\path\to\chromedriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -hub http://10.37.34.2:4444/grid/register -port 5454
© www.soinside.com 2019 - 2024. All rights reserved.