Automated testing on Jenkins + Selenium basis

Automated testing on Jenkins + Selenium basis

Hello everyone! At some point, the project evolves to the stage, when you start thinking about some new step in its development. It is quite clear, that you put yourself questions like “What is to be done at the website first of all? Better control on quality assurance testing?”. If so, it is high time to consider implementing CI.

What is CI? CI (literally “Continuous integration system”) — is a system allowing to make automatic certain processes of website development and quality assurance of your project. This in its turn promises more “profit” and less headache in case of project’s regress.

There are different CI systems, as for example, Jenkins (was called Hudson in the past. This system will be discussed in this post), Strider, Teamcity, Travis etc. As for Jenkins, it was chosen for its simplicity and flexibility characteristics, which is better, than in other systems. In this blog post, we will put an emphasis on Jenkins’ testing possibilities, and especially — implementing a combination of Jenkins and Selenium IDE tests. Take into a count, that our OS is Ubuntu, so we will concentrate on it for setting up process.

So first of all we should install Jenkins. Before this, we have to add package repository to those already existing Ubuntu (for normal installation and updating). To do this, write the following in a command line:

sudo wget -q -O - | sudo apt-key add -

echo deb binary/ > /etc/apt/sources.list.d/jenkins.list

Now we can install Jenkins itself. To do this, use the following commands:

sudo apt-get update

sudo apt-get install jenkins

This CI is being installed for 8080 port by default, so to enter its administration panel use this link:


If the weather and stars position was OK, you’ll see the following page:

Jenkins main page

Pic.1. Jenkins main page

Nota bene: you can change your host’s name for something more attractive, for example, “jenkins.local”.

Great, the first stage is accomplished. Let’s postpone closer acquaintance with the main page and install the rest of the components first. Let’s start with Selenium RC. In fact, this is a core, which would perform our selenium tests. Moreover, we would be able to perform this not just with usual Firefox, but (having installed needed drivers) with Chrome, IE and even Safari. There’s no need to install it. All you have to do is download an appropriate jar file, which could be found on the project's official website. Let’s put it here:


Now we have to install just xvfb, a program for virtual creating and control of windows (not to allow Jenkins browser screen to interact with previous session in the same browser). To do this, apply the following commands:

sudo apt-get update && sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic xvfb x11-apps imagemagick firefox

As you have probably noticed, we also installed the correct fonts in addition to the program itself, which are needed for its proper work. Now we have to add it into OS’ autoran settings. It should be done in such a way, to enable the launch of xvfb everytime, when the OS starts. To do this we create a script and put it into “etc/init.d/” directory. The script will look like this:


if [ -z "$1" ];then

echo "`basename $0` {start|stop}"



case "$1" in


/usr/bin/Xvfb :99 -ac -screen 0 1024x768x8



killall Xvfb



In such a way, xvfb will launch a window with 1024x768x8 resolution and 99 identifiers (you can vary it between 0 and 99). After putting in the text editor mentioned script, save it and name “Xvfb”. Now set up the program’s automatic launch when the OS starts. To do this write-in the command line the following: “sudo update-rc.d xvfb defaults”.

Before linking it to Jenkins, we should check if everything is working well: if browsers driver is in correct place, if there is jar file of Selenium RC server and if the prepared Selenium IDE tests will be performed under our CI. You may have a question, “Why would Selenium RC load the test not in the same way, as it does Selenium IDE?”. Well, there is a difference in work of these two programs. We can take into a count the age of Selenium RC (which wasn’t updated for few years already), the specifications of core work (while IDE supports just Firefox, RC can launch the tests for different browsers, even for Safari and IE), but that already sounds like a topic for yet another blog post.

So, to check, how does our “Tower of Pisa” works, execute the following command in your command line:

java -jar /var/lib/selenium/selenium-server.jar -htmlSuite *firefox "/way/to/your/test/file-complect/.html" "/tmp/firefox-results.html"

And that’s how it looked after test setting up at our work station:

java -jar /var/lib/selenium/selenium-server.jar -htmlSuite *firefox "/var/lib/selenium-jenkins/suite.html" "/tmp/firefox-results.html"

If you accomplished the previous steps correctly, you will see two windows — one with Firefox session and other with Selenium RC tests set (its interface may remind you of those of Selenium IDE). After that, those tests should be launched and performed automatically. All you have to do now is to enjoy observing those charming action (of course, if the tests don’t contain any mistakes. In that case, your joy will finish, haven’t even started).

And now let’s proceed to our local Jenkins. First of all install theSeleniumHQ plugin. To do this, head from the main menu to the corresponding page (or write /pluginManager/ in URL) and choose the option Available. Tick the plugin we were looking for and click the button Download now and Install after restart below.

The list of plugins is impressive

Pic.2. The list of plugins is impressive

Now announce the main variables to assign to browser windows in the sessions, which should be launched, correct ID (that’s why we installed Xvfb). To do this, head to the page Configure System from the main menu (or just add /configure to your local CI’s address). Tick the check-box Environment Variables and write “DISPLAY” in this field (without brackets). Write “99” in the field Value (also without the brackets) and save the page.

Announce the global variables

Pic.3. Announce the global variables

Now we create a new project to attach this collection to its automatic launch. Having headed to the main page of our CI, choose New Job (the link is in the upper left corner). After that, you should see the following form:

The form for creating the new project

Pic.4. The form for creating the new project

In the upper field, enter the name of our project. Choose the radio-button: “Build a free-style software project”. In the project settings (/job/project_name/configure) enable the checkbox Build and fill in the fields as it is shown in the example:

Set up the build

Pic.5. Set up the build

These settings let Jenkins know, that the tests will be performed in the Firefox browser and that the homepage of the needed site (in other words, those, where the tests are to be performed) could be found at the The system is being pointed, that the file with the testing collection would be situated here: “.../project_name/tests/suite.html”. After the testing of build is completed, we will get a file with report “reports.html”, which will be moved to the folder “/project_name/tests/reports/results.html” (the folders in the field reports are defined in correspondence to Jenkins’ workspace, which in this case would be “/var/lib/jenkins/jobs/project_name/reports”).

So the main set up of Jenkins is completed. To proceed the tests from now on you should just click the icon, which generally looks like Play button, and Jenkins will launch the tests automatically.

In fact, there are other characteristics, that could be announced for or after our build launch — that is a timeframe of tests launch, the possibility to create a newsletter for team members to inform them about the problems with builds (or provide them with certain amount of spam). You also can attach Jenkins to the common repository, check the code for accordance to the standards etc. But it all would require much time for familiarization and proper setting up. It also would be good to study the existing set of plugins, which could significantly extend the opportunities of Jenkins for QA testers.

All in all, Jenkins may fully satisfy the needs and solve many problems arising during development process of the projects with different complexity level. Using it, you can build the testing system, providing you with stable regress-testing for years.

15 votes, Rating: 3.8

Subscribe to our blog updates