Server 端:
需要提前安装 firefox 和 selenium jar 还有 gecko packages.
1) 启动 selenium server, e.g.
java -jar selenium-server-standalone-3.141.5.jar -role hub
2) 启动 geckodriver with firefox browser, e.g.
java -Dwebdriver.gecko.driver=/path/to/geckodriver -Dwebdriver.firefox.bin=/path/to/firefox-bin -jar /path/to/selenium-server-standalone-3.141.5.jar -role node -port 6666 -hub http://serverIP:4444/grid/register -browser browserName=firefox
至此, selenium server 开始接收远程test case调用.
Remote 端:
我们用java code连接, 如下:
//support firefox DesiredCapabilities capabilities = DesiredCapabilities.firefox(); //set firefox path on server String firefoxBinPath="/path/to/firefox-bin"; capabilities.setCapability("firefox_binary",firefoxBinPath); seleniumHost="ServerIP"; seleniumPort=6666; //connect remote WebDriver remoteSelenium = new RemoteWebDriver( new URL("http://" + seleniumHost + ":" + String.valueOf(seleniumPort) + "/wd/hub"), capabilities);
在运行远端test case之前,需要启动server firefox的伺服,请查看 firefox 启动