作为cron作业运行时,selenium节点中的错误

时间:2016-09-30 04:14:20

标签: selenium selenium-webdriver selenium-chromedriver selenium-grid

我的selenium脚本试图通过连接到已使用 crontab 启动的节点来运行自动化测试时遇到异常错误(如下所示)

@reboot sh /home/selenium/automation/nodeStartUp.sh &

nodeStartUp.sh内容如下所示:

#!/bin/bash
java -jar /home/selenium/automation/selenium-server-standalone-3.0.0-beta3.jar -role node -nodeConfig /home/selenium/automation/node.json -log /home/selenium/automation/node.log

显示的错误如下:(注意:手动启动脚本并执行测试用例时,不会出现此错误)

09:25:08.919 INFO [20] org.openqa.grid.internal.utils.SelfRegisteringRemote - Registering the node to the hub: http://XXX.XXX.XXX.XXX:4444/grid/register
09:25:08.940 INFO [20] org.openqa.grid.internal.utils.SelfRegisteringRemote - The node is registered to the hub and ready to use
09:25:10.972 INFO [17] org.openqa.selenium.remote.server.DriverServlet - Executing: [new session: Capabilities [{browserName=chrome, version=, platform=ANY}]])
09:25:10.972 INFO [28] org.openqa.selenium.remote.server.DefaultDriverProvider - Creating a new session for Capabilities [{browserName=chrome, version=, platform=ANY}]
09:25:10.973 WARN [17] org.openqa.selenium.remote.server.DriverServlet - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '3.0.0-beta3', revision: 'c7b525d', time: '2016-09-01 14:57:03 -0700'
System info: host: 'BLR-SOFT-195', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-96-generic', java.version: '1.8.0_101'
Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:124)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:36)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
        at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:185)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:204)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:166)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:132)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:808)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:587)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.seleniumhq.jetty9.server.Server.handle(Server.java:499)
        at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:310)
        at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:257)
        at org.seleniumhq.jetty9.io.AbstractConnection$2.run(AbstractConnection.java:540)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '3.0.0-beta3', revision: 'c7b525d', time: '2016-09-01 14:57:03 -0700'
System info: host: 'BLR-SOFT-195', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-96-generic', java.version: '1.8.0_101'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:113)
        at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:209)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        ... 1 more
Caused by: java.lang.reflect.InvocationTargetException
        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.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:103)
        ... 9 more
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
        at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:138)
        ... 14 more
09:25:10.974 WARN [17] org.openqa.selenium.remote.server.DriverServlet - Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

这似乎与chromedriver有关。

  

驱动程序可执行文件的路径必须由   webdriver.chrome.driver系统属性;有关更多信息,请参阅   https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。最新的   版本可以从中下载   http://chromedriver.storage.googleapis.com/index.html

你的chromedriver在哪里?

你在做什么? CentOS的? Ubuntu的?我建议你不要在cron中运行它。相反,您可以创建一个服务,看看它是否有效:

/etc/systemd/system/selenium-node.service

中创建一个文件

添加到文件中:

[Unit]
Description=Run a selenium node

[Service]
ExecStart=/usr/bin/java -jar /route/to/selenium/selenium-server-standalone-2.52.0.jar -role node blablabla
Restart=on-abort

[Install]
WantedBy=multi-user.target

并运行:

sudo systemctl daemon-reload
sudo systemctl start selenium-node.service

或者您可以在 init.d 文件的末尾添加sh /home/selenium/automation/nodeStartUp.sh(但这也不是最好的选项)。