0

配置:Mac OS X 10.8.5、java 1.6.0_65、Selenium 2.37、Jenkins 1.538、Chrome 30.0.1599.101、ChromeDriver v2.6.232908 和 Firefox 25.0。我正在使用 PHPUnit 3.7.28 和 PHP 5.3.22(使用 PHPUnit_Extensions_Selenium2TestCase)运行测试。

(1) 如果我像这样手动启动 Selenium:

 $ java -jar ~/Downloads/selenium-server-standalone-2.37.0.jar  -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver

我可以按预期运行测试。

(2) 但是,如果我通过 Jenkins 启动 Selenium:

 # launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist 

然后运行我的测试,我得到一个错误:

$ phpunit --verbose tests/classes/core/admin_campaignhome_loads.php 
PHPUnit 3.7.28 by Sebastian Bergmann.

E

Time: 20.56 seconds, Memory: 5.25Mb

There was 1 error:

1) AdminTest::testLoginToBackend
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: unknown error: Chrome failed to start: exited normally
  (Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.8.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.53 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'Pauls-iMac.local', ip: '192.168.1.18', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.6.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver

/usr/local/php5-20130308-201415/lib/php/PHPUnit/TextUI/TestRunner.php:349
/usr/local/php5-20130308-201415/lib/php/PHPUnit/TextUI/Command.php:176
/usr/local/php5-20130308-201415/lib/php/PHPUnit/TextUI/Command.php:129

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

(3) 通过 Jenkins 的 Firefox + Selenium 让我可以按预期运行测试。

jenkins.log 有以下内容:

14:51:11.439 INFO - Executing: [new session: {browserName=chrome}] at URL: /session)
14:51:11.440 INFO - Creating a new session for Capabilities [{browserName=chrome}]
Starting ChromeDriver (v2.6.232908) on port 33014
14:51:31.972 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: 'Pauls-iMac.local', ip: '192.168.1.18', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.6.0_65'
Driver info: driver.version: unknown
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.java:83)
    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: 'Pauls-iMac.local', ip: '192.168.1.18', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.6.0_65'
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:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:169)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    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 normally
  (Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.8.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.53 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'Pauls-iMac.local', ip: '192.168.1.18', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.6.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    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
14:51:31.974 WARN - Exception: unknown error: Chrome failed to start: exited normally
  (Driver info: chromedriver=2.6.232908,platform=Mac OS X 10.8.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.53 seconds
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'Pauls-iMac.local', ip: '192.168.1.18', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.6.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
4

1 回答 1

1

这是因为 jenkins 启动的实例没有 chrome 功能

看着

http://localhost:4444 

看看它的能力

您可以添加其他功能

java -jar selenium-server-standalone-2.37.0.jar -role node \
    -hub http://localhost:4444/grid/register  \
    -browser "browserName=chrome,version=25,maxInstances=5" \
    -Dwebdriver.chrome.driver="/usr/local/bin/chromedriver" \ 
    -host localhost \
    -port 5556

您可以使用不同的-port设置从同一台机器启动多个功能,甚至可以通过-hub将 selenium 服务器的真实地址更改为从不同的机器连接


编辑

我在没有连接我的 chrome 驱动程序的情况下重新创建了您的问题

-Dwebdriver.chrome.driver='...'

我在 v2.33.0

13:18:44.922 WARN - 抛出异常 java.util.concurrent.ExecutionException:org.openqa.selenium.WebDriverException:java.lang.reflect.InvocationTargetException 构建信息:版本:'2.33.0',修订:'4e90c97',时间:'2013-05-22 15:32:38' 系统信息:os.name:'Linux',os.arch:'amd64',os.version:'3.2.0-55-generic',java.version: '1.7.0_45' 驱动程序信息:driver.version:在 java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at org. openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:176)

所以我怀疑你使用的 Selenium-jenkins 插件没有设置 chromedriver 或者它有一个无效的。有一个日志要检查(我的 Jenkins 上没有硒网格了)或者可能将 chromedriver 的路径添加到你的路径中,如在这个线程中https://groups.google.com/forum/?fromgroups# !topic/硒用户/-3LJ3wma3RE

于 2013-11-06T22:42:03.913 回答