下面是我用来传递浏览器,节点和集线器端口以启动浏览器并执行测试的代码,但我得到了例外,尽管我能够设置selenium服务器。我也在代码下面粘贴错误。我使用mac book,Selenium 3.4,Firefox 55和Gecko 0.18.0
public synchronized WebDriver setUp(String browser, String
nodePort, String hubPort) throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.MAC);
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(ForSeleniumServer.PROXYING_EVERYTHING,
true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT,
true);
if(browser.equals("firefox"))
System.setProperty("webdriver.gecko.driver",
System.getProperty("user.dir")+"//geckoDriver//geckodriver");
else if(browser.equals("chrome"))
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+"//chromeDriver//chromeDriver");
driver = new RemoteWebDriver(new
URL("http://localhost:"+nodePort+"/wd/hub"), capabilities);
driver.get("https://www.bookbaby.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
System.out.println(driver.toString());
return driver;
错误是
org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置;有关更多信息,请参阅https://github.com/mozilla/geckodriver。最新版本可从https://github.com/mozilla/geckodriver/releases下载 命令持续时间或超时:1.41秒 构建信息:版本:' 3.4.0',修订版:'未知',时间:'未知' 系统信息:主持人:' Refaques-MacBook-Pro.local',ip:' 192.168.108.206',os.name:' Mac OS X',os .arch:' x86_64',os.version:' 10.12.6',java.version:' 1.8.0_144' 驱动程序信息:driver.version:驱动程序 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) 在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215) 在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) 在org.openqa.selenium.remote.JsonWireProtocolResponse.lambda $ new $ 0(JsonWireProtocolResponse.java:53) 在org.openqa.selenium.remote.JsonWireProtocolResponse.lambda $ getResponseFunction $ 2(JsonWireProtocolResponse.java:91) 在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) 在java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) 在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368) 在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159) 在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142) 在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) 在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250) 在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236) 在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:137) 在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:174) 在com.bookbaby.driver.Driver.setUp(Driver.java:55) 在com.bookbaby.executor.RunCukesByFeatureForFirefox.setUpClass(RunCukesByFeatureForFirefox.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514) 在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215) 在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 在org.testng.TestRunner.privateRun(TestRunner.java:782) 在org.testng.TestRunner.run(TestRunner.java:632) 在org.testng.SuiteRunner.runTest(SuiteRunner.java:366) 在org.testng.SuiteRunner.access $ 000(SuiteRunner.java:39) 在org.testng.SuiteRunner $ SuiteWorker.run(SuiteRunner.java:400) at org.testng.internal.thread.ThreadUtil $ 2.call(ThreadUtil.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在java.lang.Thread.run(Thread.java:748) 引发者:java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置;有关更多信息,请参阅https://github.com/mozilla/geckodriver。最新版本可从https://github.com/mozilla/geckodriver/releases下载 在com.google.common.base.Preconditions.checkState(Preconditions.java:738) 在org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) 在org.openqa.selenium.firefox.GeckoDriverService.access $ 100(GeckoDriverService.java:41) 在org.openqa.selenium.firefox.GeckoDriverService $ Builder.findDefaultExecutable(GeckoDriverService.java:115) 在org.openqa.selenium.remote.service.DriverService $ Builder.build(DriverService.java:330) 在org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207) 在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:108) 在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:137) 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) 在org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:81) 在org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:63) 在org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60) 在org.openqa.selenium.remote.server.DefaultSession $ BrowserCreator.call(DefaultSession.java:222) 在org.openqa.selenium.remote.server.DefaultSession $ BrowserCreator.call(DefaultSession.java:209) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 在org.openqa.selenium.remote.server.DefaultSession $ 1.run(DefaultSession.java:176) ......还有3个
以下是我从命令提示符
的日志13:25:14.249 INFO - Selenium build
info: version: '3.4.0', revision: 'unknown'
13:25:14.249 INFO - Launching a Selenium Grid node
2017-09-12 13:25:14.814:INFO::main: Logging initialized @833ms to
org.seleniumhq.jetty9.util.log.StdErrLog
13:25:14.864 INFO - Driver provider
org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true,
browserName=internet explorer, version=, platform=WINDOWS}] does not
match the current platform MAC
13:25:14.864 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver
registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge,
version=, platform=WINDOWS}] does not match the current platform MAC
13:25:14.864 INFO - Driver class not found:
com.opera.core.systems.OperaDriver
13:25:14.864 INFO - Driver provider com.opera.core.systems.OperaDriver
registration is skipped:
Unable to create new instances on this machine.
13:25:14.865 INFO - Driver class not found:
com.opera.core.systems.OperaDriver
13:25:14.865 INFO - Driver provider com.opera.core.systems.OperaDriver
is not registered
2017-09-12 13:25:14.899:INFO:osjs.Server:main: jetty-9.4.3.v20170317
2017-09-12 13:25:14.938:INFO:osjsh.ContextHandler:main: Started
o.s.j.s.ServletContextHandler@e056f20{/,null,AVAILABLE}
2017-09-12 13:25:14.963:INFO:osjs.AbstractConnector:main: Started
ServerConnector@39529185{HTTP/1.1,[http/1.1]}{0.0.0.0:5556}
2017-09-12 13:25:14.963:INFO:osjs.Server:main: Started @982ms
13:25:14.963 INFO - Selenium Grid node is up and ready to register to
the hub
13:25:14.983 INFO - Starting auto registration thread. Will try to
register every 5000 ms.
13:25:14.983 INFO - Registering the node to the hub:
http://localhost:4445/grid/register
13:25:15.044 INFO - The node is registered to the hub and ready to use
13:25:20.205 INFO - SessionCleaner initialized with
insideBrowserTimeout 0 and clientGoneTimeout 1800000 polling every
180000
13:26:11.724 INFO - Executing: [new session: Capabilities
[{proxyEverything=true, acceptSslCerts=true, marionette=true,
acceptInsecureCerts=true, browserName=firefox, javascriptEnabled=true,
handlesAlerts=true, version=, platform=MAC}]])
13:26:11.738 INFO - Creating a new session for Capabilities
[{proxyEverything=true, acceptSslCerts=true, marionette=true,
acceptInsecureCerts=true, browserName=firefox, javascriptEnabled=true,
handlesAlerts=true, version=, platform=MAC}]
13:26:11.770 WARN - Exception thrown
java.util.concurrent.ExecutionException:
org.openqa.selenium.WebDriverException:
java.lang.reflect.InvocationTargetException
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'XXXXXX-MacBook-Pro.local', ip: '192.168.108.206',
os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6',
java.version: '1.8.0_144'
Driver info: driver.version: unknown
13:26:11.777 WARN - Exception: The path to the driver executable must
be set by the webdriver.gecko.driver system property; for more
information, see https://github.com/mozilla/geckodriver. The latest
version can be downloaded from
https://github.com/mozilla/geckodriver/releases
答案 0 :(得分:0)
请在您的机器中设置环境变量webdriver.gecko.driver
及其值。
或者您可以在启动集线器或注册节点时传递参数webdriver.gecko.driver
。像
java -Dwebdriver.gecko.driver="path to the gecko driver" {jar} -role node/hub
答案 1 :(得分:0)
首先说明你的代码中的问题,如果你想使用selenium服务器/网格,请在启动selenium服务器时在命令行中指定webdriver路径,而不是通过代码指定。
所以下面的代码是不必要的,只有当你选择不使用selenium服务器/网格的运行测试时才需要它们,我们称它为“直接连接”。 (您的脚本直接与webdriver.exe通信)
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
将节点注册到hub参数示例以指定webdriver.exe路径:
if(browser.equals("firefox"))
System.setProperty("webdriver.gecko.driver",
System.getProperty("user.dir")+"//geckoDriver//geckodriver");
else if(browser.equals("chrome"))
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+"//chromeDriver//chromeDriver");
提醒:请检查standalone.jar,指定的webdriver.exe和节点上的浏览器是否相互兼容,否则节点将无法在测试中启动浏览器。