我已经启动了这样的集线器和节点:
#!/bin/bash
java -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role hub &
java -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role webdriver -hub http://192.168.40.40:4444/grid/register -nodeConfig /opt/selenium/defaultNodeConfig.json -browser "browserName=chrome,platform=LINUX" &
这是我的/opt/selenium/defaultNodeConfig.json:
{
"capabilities": [
{
"browserName": "firefox",
"platform": "LINUX",
"maxInstances": 5,
"cleanSession": true,
"webdriver.gecko.driver": "/opt/selenium/geckodriver",
"webdriver.firefox.bin": "/usr/bin/firefox"
},
{
"browserName": "chrome",
"platform": "LINUX",
"maxInstances": 5,
"webdriver.chrome.driver": "/opt/selenium/chromedriver"
}
]
}
当我启动Selenium客户端连接到集线器时,如下所示:
#!/bin/bash
java -cp ".:/opt/selenium/client-combined-3.5.3-nodeps.jar:/opt/selenium/selenium-server-standalone-3.7.1.jar" de.auticon.selenium_server.Grid_SetUp
使用Grid_SetUp.java:
package de.auticon.selenium_server;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
public class Grid_SetUp {
public static WebDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException{
System.setProperty("webdriver.chrome.driver","/opt/selenium/chromedriver");
String URL = "http://www.google.com";
String Node = "http://192.168.40.40:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.chrome();
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
Thread.sleep(5000);
driver.quit();
}
}
我收到错误:
leder@leder-VirtualBox:~/Source/SeleniumCheese/bin$ ./execute_grid.sh
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: 'leder-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.8.0-59-generic', java.version: '1.8.0_131'
Driver info: driver.version: unknown
使用相同的Java客户端连接到Windows上的同一个java中心和节点可以正常工作!
我在ubuntu中的chromedriver_linux64
集成有问题吗?
答案 0 :(得分:0)
我还必须使用java选项-D这样的chromedriver:
java -Dwebdriver.chrome.driver=/opt/selenium/chromedriver -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role webdriver -hub http://192.168.40.40:4444/grid/register -nodeConfig /opt/selenium/defaultNodeConfig.json -browser "browserName=chrome,platform=LINUX" &