Selenium Webdriver& Chrome驱动程序 - 无法运行Chrome驱动程序

时间:2014-02-22 05:31:59

标签: ruby google-chrome selenium

我正在尝试运行一个ruby文件,它将使用selenium webdriver启动chrome驱动程序。我有selenium独立服务器2.35.0。和chromedriver可执行文件安装。我正在通过运行来启动服务器,

java -jar ./selenium-server-standalone-2.35.0.jar -Dwebdriver.chrome.bin=/usr/bin/google-chrome -Dwebdriver.chrome.driver=/home/./chromedriver &

两个会话正在启动,Chrome驱动程序无法启动。

05:07:34.328 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=tr
ue, cssSelectorsEnabled=true, browserName=chrome, nativeEvents=false, rotatable=
false, takesScreenshot=false, version=, chrome.switches=[--ignore-certificate-er
rors]}] at URL: /session)
05:07:34.329 INFO - Creating a new session for Capabilities [{platform=ANY, cssS
electorsEnabled=true, javascriptEnabled=true, browserName=chrome, nativeEvents=f
alse, rotatable=false, takesScreenshot=false, chrome.switches=[--ignore-certific
ate-errors], version=}]
Starting ChromeDriver (v2.2) on port 9143
05:07:54.887 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException:
 java.lang.reflect.InvocationTargetException
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
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(DefaultSessi
on.java:176)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSessio
n.java:112)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(Defaul
tSession.java:89)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(De
faultDriverSessions.java:89)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSessio
n.java:63)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConf
ig.java:205)
        at org.openqa.selenium.remote.server.JsonHttpRemoteConfig.handleRequest(
JsonHttpRemoteConfig.java:192)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverS
ervlet.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.jav
a:428)
        at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler
.java:677)
        at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.j
ava: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:9
86)
        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.InvocationT
argetException
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructo
r(DefaultDriverFactory.java:72)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(De
faultDriverFactory.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:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
        at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructo
r(DefaultDriverFactory.java:62)
        ... 9 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed
to start: exited abnormally
  (Driver info: chromedriver=2.2,platform=Linux 3.2.0-38-virtual x86_64) (WARNIN
G: The server did not provide any stacktrace information)
Command duration or timeout: 20.56 seconds
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.
java:191)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHa
ndler.java:145)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:554)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriv
er.java:216)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.jav
a:111)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.jav
a:115)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)

        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:129)

        ... 14 more
05:07:54.889 WARN - Exception: unknown error: Chrome failed to start: exited abn
ormally
  (Driver info: chromedriver=2.2,platform=Linux 3.2.0-38-virtual x86_64) (WARNIN
G: The server did not provide any stacktrace information)
Command duration or timeout: 20.56 seconds
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver

An error occurred in an after hook
  NoMethodError: undefined method `quit' for nil:NilClass
  occurred at /home/deploy/deployment/ih2/spec/monitoring_script/NineMonitoring.
rb:24:in `block (2 levels) in <top (required)>'

F

Failures:

  1) MonitoringScript test_script
     Failure/Error: @driver = Selenium::WebDriver.for( :remote, :url => 'http://
localhost:4444/wd/hub', :desired_capabilities => @caps )
     Selenium::WebDriver::Error::UnknownError:
       unknown error: Chrome failed to start: exited abnormally
         (Driver info: chromedriver=2.2,platform=Linux 3.2.0-38-virtual x86_64)
(WARNING: The server did not provide any stacktrace information)
       Command duration or timeout: 20.56 seconds
       Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:
42:01'
       System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-vi
rtual', java.version: '1.7.0_25'
       Driver info: org.openqa.selenium.chrome.ChromeDriver (org.openqa.selenium
.WebDriverException)
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):-2:in `newInstance0'
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):57:in `newInstance'
     # [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingC
onstructorAccessorImpl.java):45:in `newInstance'
     # [remote server] java.lang.reflect.Constructor(Constructor.java):526:in `n
ewInstance'
     # [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java
):191:in `createThrowable'
     # [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java
):145:in `throwIfResponseFailed'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):554:in `execute'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):216:in `startSession'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):111:in `<init>'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):115:in `<init>'
     # [remote server] org.openqa.selenium.chrome.ChromeDriver(ChromeDriver.java
):150:in `<init>'
     # [remote server] org.openqa.selenium.chrome.ChromeDriver(ChromeDriver.java
):129:in `<init>'
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):-2:in `newInstance0'
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):57:in `newInstance'
     # [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingC
onstructorAccessorImpl.java):45:in `newInstance'
     # [remote server] java.lang.reflect.Constructor(Constructor.java):526:in `n
ewInstance'
     # [remote server] org.openqa.selenium.remote.server.DefaultDriverFactory(De
faultDriverFactory.java):62:in `callConstructor'
     # [remote server] org.openqa.selenium.remote.server.DefaultDriverFactory(De
faultDriverFactory.java):56:in `newInstance'
     # [remote server] org.openqa.selenium.remote.server.DefaultSession$BrowserC
reator(DefaultSession.java):215:in `call'
     # [remote server] org.openqa.selenium.remote.server.DefaultSession$BrowserC
reator(DefaultSession.java):1:in `call'
     # [remote server] java.util.concurrent.FutureTask$Sync(FutureTask.java):334
:in `innerRun'
     # [remote server] java.util.concurrent.FutureTask(FutureTask.java):166:in `
run'
     # [remote server] org.openqa.selenium.remote.server.DefaultSession$1(Defaul
tSession.java):169:in `run'
     # [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecuto
r.java):1145:in `runWorker'
     # [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPool
Executor.java):615:in `run'
     # [remote server] java.lang.Thread(Thread.java):724:in `run'
     # ./NineMonitoring.rb:11:in `block (2 levels) in <top (required)>'

Finished in 20.75 seconds
1 example, 1 failure

Failed examples:

rspec ./filename.rb:28 # filename test_script

这是在我使用

运行文件之后
bundle exec rspec filename.rb

我是新手,无法弄清楚出了什么问题。而且我也试图让它无头,所以我有Xvfb运行。有人可以帮我指出我犯的错误并开始使用chromedriver吗?

更新:

在提出建议后,我更新了ChromeDriver并收到以下错误:

10:19:44.378 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=tr
ue, cssSelectorsEnabled=true, browserName=chrome, nativeEvents=false, rotatable=
false, takesScreenshot=false, version=, chrome.switches=[--ignore-certificate-er
rors]}] at URL: /session)
10:19:44.417 INFO - Creating a new session for Capabilities [{platform=ANY, cssS
electorsEnabled=true, javascriptEnabled=true, browserName=chrome, nativeEvents=f
alse, rotatable=false, takesScreenshot=false, chrome.switches=[--ignore-certific
ate-errors], version=}]
Starting ChromeDriver (v2.9.248304) on port 21908
[0.723][WARNING]: PAC support disabled because there is no system implementation

An error occurred in an after hook
  NoMethodError: undefined method `quit' for nil:NilClass
  occurred at /home/deploy/deployment/ih2/spec/monitoring_script/NineMonitoring.
rb:24:in `block (2 levels) in <top (required)>'

While running the file:

Failures:

  1) MonitoringScript test_script
     Failure/Error: @driver = Selenium::WebDriver.for( :remote, :url => 'http://
localhost:4444/wd/hub', :desired_capabilities => @caps )
     Timeout::Error:
       Timeout::Error
     # ./testfile.rb:11:in `block (2 levels) in <top (required)>'

Finished in 1 minute 0.19031 seconds
1 example, 1 failure

任何人都可以帮我弄清楚出了什么问题吗?

1 个答案:

答案 0 :(得分:2)

使用Java 1.6就可以了。

尝试Selenium-server-standalone-2.37.0.jar后;谷歌浏览器33.0.1750.117; chromedriver_linux64_2.2; Java版“1.7”,发现java版本没有与其他版本一起使用。因此解决了我的问题。