我在从Windows 10主机到Linux VM启动Selenium测试时遇到问题。 在VM上,我启动了Hub并注册了一个Node。 我也可以从我的主机访问Selenium网格接口。
我是否必须手动启动Geckodriver或必须在VM上安装驱动程序?
我使用的是Selenium Standalone 3.5.3,我的VM上的Firefox版本是52.2.0。
这是我想要触发测试的java类
package service;
import junit.framework.TestCase;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class TestTest {
private static WebDriver driver;
public static void main(String[] args) throws Exception {
System.setProperty("driver.gecko.driver", "src/main/resources/geckodriver.exe");
String Node = "http://192.168.20.206:4444/wd/hub";
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL(Node), capabilities);
driver.navigate().to("http://www.DemoQA.com");
Thread.sleep(5000);
driver.quit();
}
}
这是我的stacktrace
Connected to the target VM, address: '127.0.0.1:51403', transport: 'socket'
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
System info: host: 'linux-3rfg', ip: 'Unknown', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.76-1-default', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Command duration or timeout: 81 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
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$22(ProtocolHandshake.java:365)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:174)
at service.TestTest.main(TestTest.java:21)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
System info: host: 'linux-3rfg', ip: 'Unknown', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.76-1-default', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'MINERVA', ip: '192.168.20.83', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.ServicedSession$Factory.lambda$new$0(ServicedSession.java:163)
at org.openqa.selenium.remote.server.ServicedSession$Factory.apply(ServicedSession.java:173)
at org.openqa.selenium.remote.server.ActiveSessionFactory.lambda$createSession$16(ActiveSessionFactory.java:171)
at java.util.Optional.map(Optional.java:215)
at org.openqa.selenium.remote.server.ActiveSessionFactory.createSession(ActiveSessionFactory.java:171)
at org.openqa.selenium.remote.server.BeginSession.execute(BeginSession.java:67)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:231)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Disconnected from the target VM, address: '127.0.0.1:51403', transport: 'socket'
Process finished with exit code 1
答案 0 :(得分:0)
您必须在注册节点时设置gecko驱动程序路径,如下所示,并将驱动程序文件下载并保存在驱动器中。
java -Dwebdriver.gecko.driver = -jar -role node -hub http://192.168.20.206:4444/grid/register