Ankit_Add

Tuesday, November 28, 2017

Running a Selenium Java project using Jenkins and Maven

jenkins-logo
Jenkins is a multi-purpose Continuous Integration server.

In this post, we will install Jenkins on a Linux machine (Ubuntu / Debian Distro) and we will configure it to run a selenium project. The same principal applies to Windows operating system.

How to run a selenium java project using Jenkins on Linux?
The steps are as follows:
1. Install Jenkins on Linux machine
2. Make your Selenium Java project into a Maven Selenium Java project
3. Configure Jenkins to run Selenium project

Step 1.  Install Jenkins on Linux machine
The simple way to install Jenkins on Linux (an ubuntu machine) is installing it from commandline (terminal in Ubuntu):


wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
view rawinstall-jenkins hosted with ❤ by GitHub
After you install it this way you can manage Jenkins via the terminal as follows:

# To stop Jenkins service
sudo service jenkins stop
# To start Jenkins service
sudo service jenkins start
# To restart jenkins service
sudo service jenkins restart
view rawmanaging-jenkins hosted with ❤ by GitHub


You can visit http://localhost:8080 to see whether you can access Jenkins via the web browser

Step 2 . Make your Selenium Java project into a Maven Selenium Java project
I have created my sample Selenium Google Search project which was implemented in Java using TestNG into a Maven project

A sample project is here : Sample Selenium Java project which uses maven

Step 3. Configure Jenkins to run Selenium project
This step has further steps:
1.  Install Java  and Maven so that Jenkins can use them

Visit http://localhost:8080/configure

java-maven-installation-jenkins
Install Java and Maven for Jenkins(click to enlarge)
If you choose the install automatically checkbox, Jenkins installs the required Java and Maven installations for you.

2. Tell Jenkins where is your project
In Jenkins, create a new project  and select Maven Project.

After this step, you need to tell Jenkins where is your project on your local machine.
Before this step make sure you have given suitable rights to your root project directory using chmod command.

If you are using a custom workplace, you will need to Configure Jenkins as shown here.

3. Run your project using the build now option in Jenkins

You will get some issues as follows:
1. Cannot access pom files  - This issue is due to lack of  proper access rights

2. Cannot open display (error while running jenkins on linux machine)

How to solve Cannot open display in jenkins/hudson in Linux machine?
The solution is simple.

Open jenkins shell script located at: /etc/init.d/jenkins 

Add the following lines as follows before PATH variable:

##Hack by Sundeep##
/usr/bin/X :0 vt7 -ac
export DISPLAY=:0
xhost +

How to upgrade your website or blog from http to https for free

Cloudfare SSL


Cloudfare offers a free SSL certificate  that enables a website publisher to host content using the https protocol on a website.

It also allows a blogger blog which has a custom domain to upgrade to https.

What are the advantages of https?

  1. Websites are more secure
  2. Google assigns a higher ranking to https websites
  3. Websites are faster


How to install  Cloudfare certificates?
In order to install the Cloudfare SSL certificate so that all content is served via https, a website owner needs to change the DNS nameservers to that provided by Cloudfare as below:

Cloudfare NameServers

The best thing is that existing MX, A, TXT records are backed up and nothing gets deleted.

You then need to enable SSL in the Crypto tab in Cloudflare console:

Enable SSL in Cloudflare


As soon as you enable this option, the website will be served via HTTPS protocol.  Users will see a lock option in the address bar as below:



You can easily force all mixed content to be served via https using the below setting:

force https setting

The advantage is that if a website owner has uploaded an image which was served by http and is now available on https, Cloudflare detects this and automatically serves such content via https.