Selenium Webdriver and Jenkins

This post has been hold for quite long time because several reasons: there are bunch of articles covering this setup, there are a lot of questions posted in Q&A site on the similar topic. But then I decided to post it with hope it will help other who face similar problem with selenium web driver.


Firefox version versus webdriver version (selenium-standalone-server.jar) is somehow overlapping each other in a way that firefox version increases every now and then and most of the time our firefox automatic update is enabled, while even the newest web driver does not support the newest firefox. So, just take this recipe: Selenium server 2.31 only support firefox up to  version 17.0. I don’t really know what could it be with the older version of both, most likely it will work.

Jenkins Master Setup

Normally I have several jenkins’ executor (slave/node) to run specific task. Especially for web automation test, I use one dedicated node just to run the tied jenkins’ job only. Following is the setup for the slave machine:

OS      : Ubuntu 12.04.1 LTS
X       : Xvfb
Firefox : Firefox 16.0
Java    : 1.7.0_15
          OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04.1)
          OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

Here is the Jenkins’ slave setup:


It’s also important to take note on the slave launch method, after some consideration and learning from experiences, I choose to launch slave agent via SSH. I used to use root account for this, but I found out somehow firefox has an issue whenever executed by root. I don’t think that this is known problem, so I choose to use non-root user for this purpose (jenkins).


Jenkins Slave Setup

On the slave you need to have `jenkins` user with /var/lib/jenkins as its HOME directory.

# adduser --home /var/lib/jenkins --disabled-password jenkins
# chown -R jenkins:jenkins /var/lib/jenkins

SSH key pair also needed and make sure that master’s public key is put inside slave’s authorized_keys. Also you need to install ssh-askpass

# ssh-keygen
# cat /path/to/master_public_key >> /var/lib/jenkins/.ssh/authorized_keys
# sudo apt-get install ssh-askpass

As you may see, DISPLAY is set to :1, this is related with the display used by Xvfb. This is how Xvfb is started:

/usr/bin/Xvfb :1 -screen 0 1024x768x24

There is also a little note that is important if you use ThoughtWorks’s Twist, you will need to define the hostname in the host file.

# /etc/hosts       localhost qa-auto-1

From my trials, I found some keys to make the testing setup stable enough for the long run:

  1. Make sure firefox version is not updated unless selenium server is updated, and make sure the version mix-match for compatibility. For my own setup, I stick with Firefox 16.0 and Selenium Server 2.31
  2. Do not execute testing job with root account. There is either known or unknown problem when firefox is executed with root.
  3. In particular if you use Twist, you will need to define your hostname to your host file.
  4. Make sure X is always available, I put a cron job to monitor whether X is running or not, then do the task respectively.