java 无法创建新的 Chrome 远程会话

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41600657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:58:59  来源:igfitidea点击:

Unable to create new Chrome remote session

javaselenium-webdriverselenium-chromedriverselenium-grid

提问by Srinivasan Ramu

I'm trying to launch a new Chrome browser using Selenium Grid but ending up with the below error

我正在尝试使用 Selenium Grid 启动新的 Chrome 浏览器,但最终出现以下错误

Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=55.0.2, platform=WINDOWS}], required capabilities = Capabilities [{}] Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700' System info: host: 'PL9710388', ip: '10.61.249.5', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111' Driver info: driver.version: RemoteWebDriver

无法创建新的远程会话。所需功能 = 功能 [{browserName=chrome, version=55.0.2, platform=WINDOWS}],所需功能 = 功能 [{}] 构建信息:版本:'3.0.1',修订版:'1969d75',时间:' 2016-10-18 09:49:13 -0700' 系统信息:主机:'PL9710388',ip:'10.61.249.5',os.name:'Windows 7',os.arch:'amd64',os.version :'6.1',java.version:'1.8.0_111'驱动信息:driver.version:RemoteWebDriver

Below is my code to launch the Remote browser

下面是我启动远程浏览器的代码

java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role hub

java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role hub

java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role node

java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role node

cap = DesiredCapabilities.chrome();
cap.setVersion("55.0.2");
cap.setBrowserName("chrome");
cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);
browser = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

Could you please help me on what is wrong?

你能帮我解决什么问题吗?

回答by karthick23

make sure your code is able to find the chromedriver in your system. You can set the path programatically, you can even download and keep your driver from the below link

确保您的代码能够在您的系统中找到 chromedriver。您可以以编程方式设置路径,您甚至可以从以下链接下载并保留您的驱动程序

System.setProperty("webdriver.chrome.driver","/path to/chromedriver.exe");
cap = DesiredCapabilities.chrome();
cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);
browser = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

回答by Krishnan Mahadevan

The line java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role nodecauses a plain vanilla node to be spun off which is agnostic of PLATFORM flavors (i.e., the node is not classified to recognize platform as a trait and is supposed to work as a generic node).

该行java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role node导致分离出一个普通的普通节点,该节点与平台风格无关(即,该节点未被归类为将平台识别为特征,并且应该作为通用节点工作)。

Your test code however seems to be specifying the platform as below

但是,您的测试代码似乎指定了如下平台

cap = DesiredCapabilities.chrome();
cap.setVersion("55.0.2");
cap.setBrowserName("chrome");
cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);

To fix your problem please change your test code to look like below

要解决您的问题,请将您的测试代码更改为如下所示

cap = DesiredCapabilities.chrome(); // this sets the browser name. u dont need to do it again.
browser = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);

Once you have this, you should be able to execute tests properly.

一旦你有了这个,你应该能够正确地执行测试。

Please dont forget to add the location to where your chromedriverbinary exists to your PATHvariable before starting the node, so that you dont see issues related to selenium not being able to find the chromedriver's location.

在启动节点之前,请不要忘记将chromedriver二进制文件所在的位置添加到PATH变量中,这样您就不会看到与 selenium 无法找到 chromedriver 位置相关的问题。

For general overview on working with Grid, you can refer to my blog post

有关使用 Grid 的一般概述,您可以参考我的博客文章

回答by Prerit Jain

I encounter the same and i found that the platform, browser name & browser version details were not matching the grid configuration. Specifically it was because i was using platrom as windows where i would have used VISTA. Also make sure you are using the hub URL instead of the node URL.Hub URL would be http://hubIP:port/wd/hub.

我遇到了同样的情况,我发现平台、浏览器名称和浏览器版本详细信息与网格配置不匹配。具体来说,这是因为我使用 platrom 作为我会使用 VISTA 的窗口。还要确保您使用的是集线器 URL 而不是节点 URL。集线器 URL 将是http://hubIP:port/wd/hub

Refer below screenshot to get the right details about the node: enter image description here

请参阅以下屏幕截图以获取有关节点的正确详细信息: 在此处输入图片说明