Category Archives: Selenium / WebDriver

Running WebDriver Selenium tests on your Jenkins build server

So you have setup Jenkins as your build server and you test your project automated with Selenium WebDriver. Now you want to run the automated tests in a Jenkins job, but you get the following error:


. Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
.
. (process:26912): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
. Error: cannot open display: :1

This post explains how to fix this. The reason is that the user that runs your Jenkins service does not have a display. Therefore there is no possibility to open a browser like Firefox.

In order the facilitate this, we will use xvfb. This is a display server that performs all graphical user interface [GUI] operations in memory and without showing any screen output.

1. Install FireFox on the machine that runs Jenkins
In /etc/apt/sources.list add the following line.

ppa:mozillateam/firefox-stable

Run the following commands to upgrade or install latest version of Firefox to work with Selenium.

sudo apt-get update
sudo apt-get install firefox

2. Install Xvfb on your server
Run the following command to install Xvfb on your server

apt-get install xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps

3. Install Xvfb in Jenkins
Install the Xvfb plugin https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin
Schermafbeelding 2015-06-21 om 19.28.28

Configure the plugin via Manage Jenkins / Configure System
Schermafbeelding 2015-06-21 om 20.45.31

4. Configure Xvfb in your Jenkins job
Schermafbeelding 2015-06-21 om 20.45.54

TimeoutException on ChromeDriver of WebDriver

When you want to run Chrome on WebDriver for your Mac, then according to according to the site http://code.google.com/p/selenium/wiki/ChromeDriver you will need to specify the path to the browser to the following location: “/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome”.

So the Java code for creating a ChromeDriver instance will be:

System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
driver = new ChromeDriver();

When trying to run this I got the following exception.

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.version: '1.6.0_45'
Driver info: driver.version: ChromeDriver
 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
 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:161)
 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
 at com.gjdb.webdriver.WebDriverRunner.doSetUp(WebDriverRunner.java:58)
 at com.gjdb.webdriver.WebDriverRunner.<init>(WebDriverRunner.java:46)
 at com.gjdb.webdriver.WebDriverRunnerTest.setup(WebDriverRunnerTest.java:14)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.junit.runners.Suite.runChild(Suite.java:128)
 at org.junit.runners.Suite.runChild(Suite.java:24)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.version: '1.6.0_45'
Driver info: driver.version: ChromeDriver
 at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
 at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
 ... 43 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:40897/status] to be available after 20002 ms
 at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
 at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
 ... 45 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
 at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
 at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
 ... 46 more
Caused by: java.util.concurrent.TimeoutException
 at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
 at java.util.concurrent.FutureTask.get(FutureTask.java:91)
 at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
 ... 47 more

This I fixed by using the ChromeDriver. Download your version on http://code.google.com/p/chromedriver/downloads/list, unzip it and use it as followed:

System.setProperty("webdriver.chrome.driver", "<unzip location>/chromedriver");
driver = new ChromeDriver();