node.js – 为什么在尝试在Selenium下运行Chromedriver时Chrome无法启动?

所以我之前有一个Chromedriver / Selenium设置工作,但现在尝试在一台新机器上安装所有东西(64位Linux)它给了我一些问题,并没有真正告诉我什么是绊倒.

我正在使用Selenium的独立服务器版本2.37.0和nodejs以及最新版本的Chromedriver(我也尝试过Chromedriver 2.0,我之前使用的早期版本,结果相同).

如下面的输出所示,当我尝试使用webdriver运行脚本时,我收到一个错误,其中包括:引起:org.openqa.selenium.WebDriverException:未知错误:Chrome无法启动:异常退出.我没有从chromedriver获得日志输出,只从Selenium输出(带错误)和Node.js输出(尝试运行测试脚本).

谁能让我知道我在这里做错了什么?

编辑:我忘了补充说,失败后有一个Chromedriver运行的过程,所以这件事是可以的,我的Chrome可执行文件确实在/ etc / bin / google-chrome,就像Chromedriver想要的那样.

输出:

一旦我启动并运行selenium,我就试图运行一个包含内容的简单测试脚本:

var webdriverjs = require("webdriverjs");
var client = webdriverjs.remote({desiredCapabilities:{browserName:"chrome"}}); // to run in chrome
client
.init()
.url("https://github.com/")
.end();

运行测试脚本的Node.js控制台输出如下所示:

[1;33m=====================================================================================[0m

Selenium 2.0/webdriver protocol bindings implementation with helper commands in nodejs by Camilo Tapia.
For a complete list of commands, visit [1;32mhttp://code.google.com/p/selenium/wiki/JsonWireProtocol[0m. 
Not all commands are implemented yet. visit [1;32mhttps://github.com/Camme/webdriverjs[0m for more info on webdriverjs. 

[1;33m=====================================================================================[0m

[1;30m[21:31:09]: [0m [0;35mCOMMAND [0mPOST      "/wd/hub/session"
[1;30m[21:31:09]: [0m [0;33mDATA         [0m{"desiredCapabilities":{"browserName":"chrome","version":"","javascriptEnabled":true,"platform":"ANY"},"sessionId":null}


[1;30m[21:31:32]: [0m [1;31mERROR   [0mCOULDNT GET A SESSION ID
[1;30m[21:31:32]: [0m Exiting process with 1

最后,Selenium在启动时和尝试运行脚本时的输出如下.出于某种原因,我根本没有得到chromedriver.log文件.

java -jar /usr/local/automation/framework/selenium/selenium-server-standalone-2.37.0.jar -Dwebdriver.chrome.driver='/usr/local/automation/framework/selenium/chromedriver' &
[1] 21293
ubuntu@ip-10-0-0-35:/usr/local/automation/framework/selenium$Nov 15, 2013 9:30:31 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
Setting system property webdriver.chrome.driver to /usr/local/automation/framework/selenium/chromedriver
21:30:32.240 INFO - Java: Oracle Corporation 23.5-b02
21:30:32.241 INFO - OS: Linux 3.2.0-48-virtual amd64
21:30:32.289 INFO - v2.37.0, with Core v2.37.0. Built from revision a7c61cb
21:30:32.586 INFO - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPhone, version=}] does not match with current platform: LINUX
21:30:32.626 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: LINUX
21:30:32.774 INFO - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPad, version=}] does not match with current platform: LINUX
21:30:32.913 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
21:30:32.918 INFO - Version Jetty/5.1.x
21:30:32.919 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
21:30:32.920 INFO - Started HttpContext[/selenium-server,/selenium-server]
21:30:32.920 INFO - Started HttpContext[/,/]
21:30:32.968 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@3b3d8503
21:30:32.968 INFO - Started HttpContext[/wd,/wd]
21:30:32.974 INFO - Started SocketListener on 0.0.0.0:4444
21:30:32.975 INFO - Started org.openqa.jetty.jetty.Server@3e724328

ubuntu@ip-10-0-0-35:/usr/local/automation/framework/selenium$21:31:10.116 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=true, browserName=chrome, version=}] at URL: /session)
21:31:10.164 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, browserName=chrome, version=}]
Starting ChromeDriver (v2.6.232917) on port 17624
[0.797][WARNING]: PAC support disabled because there is no system implementation
21:31:32.375 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
    at java.util.concurrent.FutureTask.get(FutureTask.java:111)
    at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:176)
    at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:112)
    at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:89)
    at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:104)
    at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:63)
    at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:205)
    at org.openqa.selenium.remote.server.JsonHttpRemoteConfig.handleRequest(JsonHttpRemoteConfig.java:192)
    at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:201)
    at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:167)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:139)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
    at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
    at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:914)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:72)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:215)
    at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)
    ... 9 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.6.232917,platform=Linux 3.2.0-48-virtual x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.99 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:129)
    ... 14 more
21:31:32.413 WARN - Exception: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.6.232917,platform=Linux 3.2.0-48-virtual x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.99 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'ip-10-0-0-35', ip: '10.0.0.35', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-virtual', java.version: '1.7.0_09'
Driver info: org.openqa.selenium.chrome.ChromeDriver
最佳答案
好的,在发布所有这些之后我才知道我做错了什么!

问题是我通过SSH从一个终端启动selenium,然后通过VNC从桌面终端运行测试脚本.显然Selenium,W​​ebdriverJS或Chromedriver不喜欢这个.

当我启动Selenium并从桌面上的终端运行测试脚本时,它工作正常.

转载注明原文:node.js – 为什么在尝试在Selenium下运行Chromedriver时Chrome无法启动? - 代码日志