量角器webdriver-manager永远需要启动Selenium

时间:2015-05-31 20:02:15

标签: selenium jenkins protractor

我设法通过CI服务器上的Jenkins构建任务运行Protractor测试,但我遇到的问题是,当我运行webdriver-manager start时,它需要在Selenium服务器启动之前永远。

最终它启动,控制台显示:

INFO - Started SocketListener on 0.0.0.0:4444

但这有时需要大约5分钟,而当我在Vagrant VM上尝试相同时,会立即启动。

我正在运行无头量角器测试,因此我使用xvfb-run来运行webdriver-manager start

这是我使用的shell脚本:

#!/bin/sh
export DISPLAY=:1

Xvfb $DISPLAY -ac -screen 0 1280x1024x8 &
sleep 1

xvfb-run webdriver-manager start --standalone 

这会立即启动Vagrant VM上的Selenium服务器,但在CI服务器上需要很长时间。 这是CI服务器上脚本的输出:

jenkins@vps1:~/workspace/cms$ ./runWebdriver 
Initializing built-in extension Generic Event Extension
Initializing built-in extension SHAPE
Initializing built-in extension MIT-SHM
Initializing built-in extension XInputExtension
Initializing built-in extension XTEST
Initializing built-in extension BIG-REQUESTS
Initializing built-in extension SYNC
Initializing built-in extension XKEYBOARD
Initializing built-in extension XC-MISC
Initializing built-in extension SECURITY
Initializing built-in extension XINERAMA
Initializing built-in extension XFIXES
Initializing built-in extension RENDER
Initializing built-in extension RANDR
Initializing built-in extension COMPOSITE
Initializing built-in extension DAMAGE
Initializing built-in extension MIT-SCREEN-SAVER
Initializing built-in extension DOUBLE-BUFFER
Initializing built-in extension RECORD
Initializing built-in extension DPMS
Initializing built-in extension Present
Initializing built-in extension DRI3
Initializing built-in extension X-Resource
Initializing built-in extension XVideo
Initializing built-in extension XVideo-MotionCompensation
Initializing built-in extension SELinux
Initializing built-in extension GLX
jenkins@vps1:~/workspace/cms$ seleniumProcess.pid: 27952
21:21:21.633 INFO - Launching a standalone server
Setting system property webdriver.chrome.driver to /var/lib/jenkins/.nvm/versions/io.js/v2.0.2/lib/node_modules/protractor/selenium/chromedriver
21:21:21.760 INFO - Java: Oracle Corporation 24.79-b02
21:21:21.760 INFO - OS: Linux 3.13.0-53-generic amd64
21:21:21.810 INFO - v2.45.0, with Core v2.45.0. Built from revision 5017cb8
21:21:21.960 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:21:22.108 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
21:21:22.109 INFO - Version Jetty/5.1.x
21:21:22.111 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
21:21:22.112 INFO - Started HttpContext[/selenium-server,/selenium-server]
21:21:22.112 INFO - Started HttpContext[/,/] <-- this is where it hangs

几分钟后它终于运行了,我可以执行Protractor测试,但这非常烦人,不适合在CI服务器上运行测试。

在Vagrant VM上,Selenium服务器立即启动,输出完全相同:

19:47:08.507 INFO - Java: Oracle Corporation 24.65-b04
19:47:08.509 INFO - OS: Linux 3.13.0-44-generic amd64
19:47:08.536 INFO - v2.45.0, with Core v2.45.0. Built from revision 5017cb8
19:47:08.663 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
19:47:08.760 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
19:47:08.762 INFO - Version Jetty/5.1.x
19:47:08.763 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
19:47:08.764 INFO - Started HttpContext[/selenium-server,/selenium-server]
19:47:08.765 INFO - Started HttpContext[/,/]
19:47:08.800 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@14b43af3
19:47:08.801 INFO - Started HttpContext[/wd,/wd]
19:47:08.807 INFO - Started SocketListener on 0.0.0.0:4444
19:47:08.808 INFO - Started org.openqa.jetty.jetty.Server@16692a88

两台机器都运行Ubuntu 14.04,但内核版本和Java版本略有不同(见输出),CI服务器上的Protractor版本是2.1.0,在VM 1.8.0上。

这可能是问题还是我错过了什么?

2 个答案:

答案 0 :(得分:6)

这个问题似乎与Selenium正在使用的随机性源有关。

此处有更多信息:https://code.google.com/p/selenium/issues/detail?id=1301

TL; DR解决方案:将public class CatShelter : ICatShelter { public List<Cat> Animals { get; set; } } 附加到启动selenium的-Djava.security.egd=file:///dev/urandom命令。您可能需要修改java的配置。

答案 1 :(得分:2)

对于那些使用gulp-protractor的人。您可以在seleniumArgs属性中传递java.security.egd。

seleniumArgs: ['--proxy=http://xxx:8080', '-Djava.security.egd=file:///dev/urandom']

为了让chrome能够在docker上工作,我必须以特权模式运行。在docker撰写:

privileged: true