How to Install and Setup Jenkins Testing Tool for Automated Testing


It is time for us to get to know what is Jenkins - an open source continuous integration tool for software development. We will explore how to use it for running automatic tests on a remote server. This is an interesting topic because it is quite boring to use our local machine and wait until the tests finally pass… or fall.

We have:

  • Ruby on Rails project
  • MySQL Database in project
  • Cucumber with Capybara tests
  • Ubuntu server

How to run Jenkins on a Ubuntu server

To get started, let's set up a fully functional Jenkins server. We need to install Jenkins on Java7, Tomcat7 server. It is also required to set up MySQL server, Firefox, Chrome, Xvfb. Xvfb is a virtual frame buffer for X and it is needed to run the GUI applications on virtual Xs.

Let’s start:

sudo apt-get install mysql-server firefox xvfb tomcat7 git curl gawk 
g++ make libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev 
libncurses5-dev automake libtool bison pkg-config libffi-dev postfix

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

pushd /tmp
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f

Change the option JAVA_HOME in a file /etc/default/tomcat7:


Don’t forget to amend the startup Tomcat7, if you use DigitalOcean droplets.

To install Jenkins, you need to download it, rename as ROOT.war and put in the /var/lib/tomcat7/webapps directory.

The directory /var/lib/tomcat7/webapps/ROOT should be deleted.

For the proper work of Jenkins, it is needed to create several directories:

mkdir -p /usr/share/tomcat7/.rvm mkdir -p /usr/share/tomcat7/.jenkins chown -R tomcat7:tomcat7 /usr/share/tomcat7 sudo service tomcat7 restart

The access to Jenkins can be obtained from http://your_server_IP:8080.

Configuring Jenkins for Cucumber testing automation tool

To set up Jenkins for passing cucumber’s tests you need to install some plugins for Jenkins from Control Panel plug-ins, such as: Git Plugin, Rvm, Xvfb plugin.

Then go into the Jenkins Setting Menu, into system Configuration Xvfb installation section: Add Xvfb installation Name: default Directory in which to find Xvfb executable: /usr/bin

Now it's time to create a new Item for Jenkins - issue with free configuration. Source Code Management: select Git, set up Repository URL, Credentials. Branches to build: specify the branch that you want to test. Build Environment:

Start Xvfb before the build, and shut it down after:

Xvfb installation - default
Timeout in seconds - 0
Xvfb screen - 1440x900x24
Xvfb display name offset - 1

Run the build in a RVM-managed environment:

<Ruby version>  @project_name

Specify the command shell:

export RAILS_ENV=test
export TEST_ENV_NUMBER=_cucumber_dev_${BUILD_NUMBER}
echo "
    adapter: mysql2
    encoding: utf8
    pool: 10

    database: project_name_test<%= ENV['TEST_ENV_NUMBER'] %>
    host: localhost
    username: root
    password: * ***** *
" > config/database.yml

bundle install
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec cucumber
bundle exec rake db:drop

After saving the changes, you can run the first build. The above settings are sufficient for minimum requirements. But we will not dwell on this and move on.

Configuring e-mail notifications

For receiving the results of build implementation, you can set up e-mail notifications. To do this, you need to add a new step after build “Email notifications”. It is also necessary to configure SMTP server. This can be done via Jenkins global settings in the “Mail notification” section. If you use Gmail, the server settings will be as follows:

Server SMTP - Use authentication for SMTP Username - *Password - ****** use SSL Port SMTP - 465 Reply-To Address -

When all settings are entered it is possible to test them. Use "Check the installation by sending a message to the administrator", provide your email address and click "Test configuration."

If you are using Gmail SMTP server you may get errors when sending a test message. This happens due to the security settings of your Google account. To allow sending e-mails from your account you need to click on the link

Setting SCM polling interval

It is also possible to specify a trigger for Jenkins to perform a build. By enabling "Poll SCM of changes" in the configuration page, you can set the interval for checking. If you enter a value "* * * * *" in the Schedule text box, Jenkins will poll the repository for changes every minute and run the build whenever something new shows up. For more details about setting the frequency, see the documentation on cron service. The principle of its configuration is identical.

P.S. There is a variety of plug-ins which you can use with Jenkins continuous integration tool. They are continuously updated and you can choose the best of them to expand the capabilities of your web service.

That’s all for now. In the next article we will learn how to run Selenium Grid to start parallel tests on different servers with a significant acceleration of their performance.

Special thanks to Dmitry Lyalyuevu for co-authoring.