环境
java version "1.8.0_171"
selenium-java-3.9.1
selenium-server-standalone-3.9.1.jar
火狐:60.0b9
火狐驱动:geckodriver-v0.20.1-win32
问题
不用分布式,可以驱动火狐浏览器:
WebDriver driver = new FirefoxDriver()
使用 grid 分布式跑失败,步骤和报错如下:
启动 hub
java -jar selenium-server-standalone-3.9.1.jar -role hub
启动 node 节点
java -jar selenium-server-standalone-3.9.1.jar -role node -hub http://169.254.164.88:4444/grid/register/ -browser "browserName=firefox,version=60.0,platform=WINDOWS"
node 节点成功注册 hub
hub 显示 node 的注册信息,port 5555
控制台信息:
代码:
package test;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class RemoteTest {
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.firefox.bin",
"D:\\Mozilla Firefox_new\\firefox.exe");
System.setProperty("webdriver.gecko.driver",
"D:\\Mozilla Firefox_new\\geckodriver.exe");
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WINDOWS);
capability.setVersion("60.0");
// WebDriver driver = new RemoteWebDriver(new URL("http://169.254.164.88:5555/wd/hub"), capability);
WebDriver driver = new RemoteWebDriver(new URL("http://169.254.164.88:4444/wd/hub"), capability);
driver.get("http://www.hao123.com");
}
}
geckodriver 和火狐路径都在 path 下:
报错:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'USER-20151026BV', ip: '127.0.0.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_171'
Driver info: driver.version: unknown
Command duration or timeout: 227 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
at test.RemoteTest.main(RemoteTest.java:25)
使用参考:
https://github.com/SeleniumHQ/selenium/wiki/Grid2
https://stackoverflow.com/questions/46005652/can-i-specify-webdriver-gecko-driver-in-node-json-using-selenium-grid
https://github.com/SeleniumHQ/selenium/issues/3051
以及网上一些其他的资料,但是比较陈旧,像这样的参数在新版中已经不支持了
-Dwebdriver.gecko.driver=C:\驱动路径
-Dwebdriver.firefox.bin=浏览器exe路径
试过 json 和命令行设置 node 启动参数,但是还是没找到正确指定 node 节点的浏览器 exe 路径和浏览器驱动路径的方法
至于代码中的 URL 地址:
有的说是 node 的地址,也有的说是 hub 的地址,把指令先发到 hub,hub 再发送指令到符合执行条件的 node 节点
都试过,目前一无所获。。。
使用 selenium-server-standalone-3.9.1.jar 用在 appium 分布式上是成功的,URL 是 node 节点
求助各路大神