Unable to create new Chrome remote session

2019-07-10 12:39发布

问题:

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

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

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 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?

回答1:

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

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);


回答2:

The line java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-3.0.1.jar -role node causes 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).

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 chromedriver binary exists to your PATH variable before starting the node, so that you dont see issues related to selenium not being able to find the chromedriver's location.

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



回答3:

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.

Refer below screenshot to get the right details about the node: