Selenium integration with Jenkins in Ubuntu

Selenium integration with Jenkins in Ubuntu

Jenkins is open-source integration tool written in Java. It can be run on cross-platforms-  Windows, Linux, Mac OS and Solaris environments. Advantage of Jenkins is in its ability to checkout test scripts from repositories in SVN, Github, Bitbucket and build the test from test scripts . Jenkins can be configured to schedule test runs like cron jobs as and when desired .

Prerequisites for Selenium integration:

Ubuntu server, Jenkins

Java , Maven, Packages for Chrome and Firefox

Here we go creating the environment with the above prerequisites

Ubuntu Server Information:

Execute below command on terminal:

cat /etc/lsb-release 
	DISTRIB_ID=Ubuntu
	DISTRIB_RELEASE=14.04
	DISTRIB_CODENAME=trusty
	DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"

Java installation:
Execute below command on terminal:

sudo apt-get install -y openjdk-7-jdk

Maven installation:
Execute this command on terminal:

sudo apt-add-repository -y ppa:andrei-pozolotin/maven3
sudo apt-get update
sudo apt-get install -y maven3

Jenkins installation:
Install Jenkins from Debian package repository of Jenkins . To use this repository, first add the key to your system:

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

Next, add the following entry in /etc/apt/sources.list:

deb http://pkg.jenkins-ci.org/debian binary/
sudo apt-get update
sudo apt-get install jenkins
service jenkins start

Packages installation for Firefox & Chrome browser:

yum install wget unzip
wget http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
cp chromedriver /usr/bin/
chmod 755 /usr/bin/chromedriver
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-chrome.list'

Accept installation of fonts ( though they are not really necessary) to avoid annoying warnings.

xvfb can start a virtual X window on a server where Selenium can start the browser to run the tests.

Xvfb or X virtual frame buffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in memory without any output screen.

Installation:

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

Configurations at Jenkins:
Plugins: Github, Xvfb

jenkins-fig-1

 

Step 1 ? Go to Manage Plugins by clicking “Manage Jenkins”

jenkins-fig-2

Step 2 ? Find the Xvfb Plugin and choose to install. Restart the Jenkins instance

Step 3 ? Again Go to Manage Plugins & Find the GitHub Plugin and choose to install. Restart the Jenkins instance

jenkins-fig-3

Step 4 ? Go to Configure system

Make sure Maven, Xvfb, Global properties configured properly in jenkins –

jenkins-fig-4

 

 

jenkins-fig-5

Steps to run Selenium  with Jenkins (a sample  web test case) :

Test case is to launch the chrome browser and navigates to  the bimarian web site (http://bimarian.com)

Create Maven project:
Click on “New Item” in Jenkins, give item name as “selenium-web-test” & select “Maven project” then click  OK ,it will navigate to project configuration page

jenkins-fig-6

In configuration page – select “Git” in Source Code Management & provide Repository URL –https://github.com/harikrishna1210/selenium-web-test.git

jenkins-fig-7

Chrome browser  runs on Headless Linux server – so we need Xvfb to display the screen virtually. Xvfb plugin already installed will take care of start/stop Xvfb in build process . Select Start Xvfb before the build, and shut it down after” in Build Environment and click on advanced button then configure properties as shown below: (refer the screenshot)

  • Xvfb specific display name: 99
  • I’m running this job in parallel on same node: select checkbox
  • Timeout in seconds: 0
  • Xvfb screen: 1024x768x8
  • Xvfb display name offset: 1

jenkins-fig-8

Configure Build with  properties mentioned below (refer below screenshot)
Root POM: xml
Goals and options: clean test

jenkins-fig-8

Save the project

Execute “Build Now” & check the build status

 

Leave a Reply