Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor webdriver-manager takes forever to start Selenium

I managed to get Protractor tests running through a Jenkins build task on a CI server, but I'm having the problem that when I run webdriver-manager start it takes forever before the Selenium server starts.

Eventually it starts and the console shows:

INFO - Started SocketListener on 0.0.0.0:4444

but this sometimes takes up to about 5 minutes, whereas when I try the same on a Vagrant VM it starts immediately.

I'm running headless Protractor tests so I use xvfb-run to run webdriver-manager start.

Here's the shell script I use:

#!/bin/sh
export DISPLAY=:1

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

xvfb-run webdriver-manager start --standalone 

This immediately starts the Selenium server on the Vagrant VM, but it takes a long time on the CI server. Here's the output of the script on the CI server:

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

After some minutes it finally runs and I can execute the Protractor tests, but this is very annoying and is not suitable for running tests on a CI server.

On the Vagrant VM the Selenium server starts immediately and the output is identical up to this point:

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

Both machines run Ubuntu 14.04 but the kernel version and version of Java are slightly different (see output), Protractor version on the CI server is 2.1.0, on the VM 1.8.0.

Could this be the problem or am I missing something here?

like image 664
Danny Moerkerke Avatar asked May 31 '15 20:05

Danny Moerkerke


2 Answers

The issue seems to be related to the source of randomness Selenium is using.

More info here: https://code.google.com/p/selenium/issues/detail?id=1301

TL;DR solution: append -Djava.security.egd=file:///dev/urandom to the java command that launches selenium. You may have to edit webdriver-manager's config.

like image 133
jdelman Avatar answered Oct 10 '22 08:10

jdelman


For those who are using gulp-protractor. You can pass on the java.security.egd in the seleniumArgs property.

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

In order to get chrome to work on docker I had to run in privileged mode. In the docker compose:

privileged: true
like image 40
Philippe Avatar answered Oct 10 '22 09:10

Philippe