Now that I’ve created some great test suites I wanted to hook the tests to my Jenkins build server. There was no tutorial that covered everything online so here’s what I did:
This will install Jenkins, Selenium standalone, Chrome and FireFox on a headless Ubuntu server.
I’m running Ubuntu 12.04. I assume you have Jenkins installed. If not, the Jenkins installation documentation is an excellent resource.
To download Chrome we need to add the Google key to for apt:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - sudo sh -c 'echo deb http://dl.google.com/linux/chrome/deb/ stable main > /etc/apt/sources.list.d/google.list'
Let’s install the required packages. The fonts aren’t really necessary but installing them prevents you from getting annoying warnings. xvfb can start a virtual X window on a server where Selenium can start the browser in to run your tests.
sudo apt-get update && sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic xvfb x11-apps imagemagick firefox google-chrome-stable
Now we need to download the Chrome driver binary for Ubuntu and we need the latest Selenium Server jar. I placed the Chrome driver in
/var/lib/chrome-driver/chrome-driver and the selenium jar in
/var/lib/selenium/selenium.jar but you can put them anywhere you like.
To start xvfb I like to have a little start/stop script like this one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
This will start a Window on display :99. This is important later on. Place the script in
/etc/init.d/. To start it automatically on boot, run:
sudo update-rc.d xvfb defaults.
Now it’s time to test if Selenium works. I presume you hava a Selenium HTML Suite plus a site you can test with.
1 2 3 4 5 6 7 8 9 10 11
These commands should now work without any errors and show you the results in the specified files in
Now let’s hook it onto Jenkins!
Make sure you have the SeleniumHQ plugin installed for Jenkins.
In Jenkins global configuration add the environment variable that specifies the display:
Then select “New Job” and then select “Build a free-style software project” and give it a name.
Fill in your SCM provider, assuming you have one so the workspace can be filled. I have my tests stored in a folder named tests in the repo.
In the “Build Steps” section, add an entry for the Chrome test and for the Firefox test. Note that in the Chrome test you have to specify the path to your Chrome driver.
Then as a post-build action add the selenium reports.
If everything went well you should see nice test graphs in your Jenkins like this: