[フレーム]

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Advance Selenium / Complete Guide for Selenium integration with jenkins Maven

Complete Guide for Selenium integration with jenkins Maven

by 249 Comments

[画像:Selenium integration with jenkins]

Jenkins is CI (Continuous Integration) tool which will help you to run test in easy manner, In this post, we will talk about Selenium integration with Jenkins and different usage of the same.

Before starting if you have Eclipse , TestNG and if you are using Excel sheets or CSV File, then these jars should be ready.

Selenium integration with Jenkins using Plain Java project

[フレーム]

If you are using Maven project and if you want to run maven project using Jenkins then some process will change.

Selenium Integration with Jenkins using Maven project

[フレーム]

We will divide this post into Following section

1- Download Jenkins

2- Configure Jenkins for Running Build

3- Execute Selenium build using Jenkins

4- Schedule Jobs in Jenkins to run periodically

Selenium integration with Jenkins

Part 1- Download Jenkins

Step 1- Open your web browser and then Navigate to Below URL
http://jenkins-ci.org this is the official website of Jenkins

Note- Below post will only work if you work with 1.6 version you can download from below url.

(Download 1.654)

https://updates.jenkins-ci.org/download/war/
Step 2- Now download Jenkins.war file and save into desktop or any other location depends on your choice

Selenium integration with jenkins
Run Selenium with Jenkins

Step 3- Once download complete. You will get Jenkins.war file that we need to execute

Selenium integration with Jenkins
Selenium integration with Jenkins

Now let’s navigate to another section

Part 2-How to configure Jenkins for Selenium

Go to the location where Jenkins.war is available. In my case, I kept in my project home directory

Selenium integration with jenkins
Selenium integration with Jenkins

Step 2- Open Command prompt knows as CMD and navigate to project home directory and Start Jenkins server

Start- cmd> Project_home_Directory> java -jar Jenkins.war

Selenium integration with jenkins
Selenium integration with Jenkins
Selenium integration with jenkins
Selenium integration with Jenkins

Step 3-

Once Jenkins server is up and running, you will get above success message.
By default Jenkins runs on 8080 port so you can navigate to below URL for Jenkins UI
Open any browser and type the URL http://localhost:8080

Now Jenkins in up and running so now we have to configure Jenkins so that we can execute our test case via Jenkins.

Step 4-

Once Jenkins is running so we are almost done but before moving to create build we need to configure Jenkins so that Jenkins can identify other tools as well like Java, Maven etc.

Click on > Manage Jenkins

Configure
Configure

Click on Configure System

Selenium integration with jenkins

Selenium integration with Jenkins

Here we are telling Jenkins that our java is located at this location so we don’t have to worry about the explicit path.

Navigate to JDK section and Click on Add JDK button

Selenium integration with jenkins

Selenium integration with Jenkins

Uncheck Install automatically check box so Jenkins will only take java which we have mentioned above.

Selenium integration with jenkins

Selenium integration with Jenkins

Give the name as JAVA_HOME and Specify the JDK path

Selenium integration with jenkins

In Jenkins, we have a very good feature that you can configure email notification for the user.

This is optional but if you want to configure Email notification then you have to do little setting while configuring Jenkins

Refer below screenshot you can change login details and click on Apply.

Selenium integration with jenkins

Once done click on save and apply.

Congrats, your Jenkins is configured now.

Part 3- Execute Selenium build using Jenkins

We can execute test cases in Jenkins using 4 ways refer the below screenshot

Selenium integration with jenkins

In this post, we will execute using Window batch command

Step 1- Create a batch file first then we will add the same batch file to Jenkins

a-To create the batch file we need to set classpath of TestNG so that we can execute testng.xml files

our project structure should look like

Selenium integration with jenkins

b- Open command prompt and set the classpath-

While setting classpath we will set the path of bin folder and libs folder (inside libs we have all libraries)

Home directory > set classpath=C:\Users\Learn-automation\bin;C:\Users\Learn-automation\libs\*;

Note- Please make the changes as per your system

c- Open notepad and type the below command and save as .bat file –

In my case, I have saved as run.bat

java -cp bin;libs/* org.testng.TestNG testng.xml

Selenium integration with jenkins

Selenium integration with Jenkins

Step 2-

Create a job in Jenkins which will execute our build
Open Jenkins on browser (type http://localhost:8080)

a- Click on the new item

Selenium integration with jenkins

b- Give the Job-Name, select Build a free-style software project and Click on OK button

Selenium integration with jenkins

c- Navigate to Advanced Project Options > Check the use custom workspace > in directory we will specify the project home directory

Selenium integration with jenkins

Selenium integration with Jenkins

d- Important part now specify the Add Build step >Click on Execute Windows batch command

Selenium integration with jenkins

e-In the section please specify the batch file which we created and click on Apply and save

Selenium integration with jenkins

Step 3- you can finally run the Build > Click on Build now option

Selenium integration with jenkins

Step 4- Check Build history and Console output and verify the output

Selenium integration with jenkins

Selenium integration with jenkins

Selenium integration with jenkins

Part 4-Schedule your build in Jenkins for periodic execution

Jenkins comes with very good functionality in which we can schedule jobs which we created

You can schedule build for existing jobs which already created and while creating new project also we can specify the same.

Let’s schedule the job. Refer the below screenshot

Step 1-

Open job which we created now and Click on configure > select the check box build periodically

Selenium integration with jenkins

Step 2-

Specify the time here we need to careful about the syntax

Jenkins works on Cron pattern for more info about cron refer cron link http://en.wikipedia.org/wiki/Cron

Jenkins will accept 5 parameter lets discuss one by one

* * * * *

Here the first parameter- specify minute and range will vary from 0-59

Here the second parameter- specify hours and range will vary from 0-11

Here the third parameter- specify day and range will vary from 0-7 here 0 and 7 will be Sunday

Here the fourth parameter- specify month and range will vary from 1-12

Here the fifth parameter- specify year so here you can specify *

Example 1- if you specify 00 22 * * * it means your build will run daily @ 10 PM

Example 2- if you specify 50 * * * * it means your build will run daily 50 min after every hour

Example 3- if you specify 00 22 1 * * it means your build will run every Monday @ 10 PM
Selenium integration with jenkins

Finally, we have executed our test case successfully. If you have any issue while running Jenkins please comment below post if you are finding some issues.

Thanks for visiting my blog. Keep in touch. Have a nice day 🙂

Would love to hear from you.

Reader Interactions

Comments

  1. Piyush says

    In case of mac,i am unable to do below step

    Home directory > set classpath=C:\Users\Learn-automation\bin;C:\Users\Learn-automation\libs\*;

    on mac getting below error

    piyush@Piyushs-MBP SeleniumProject % set classpath=/Users/piyush/IdeaProjects/SeleniumProject/bin;/Users/piyush/IdeaProjects/SeleniumProject/libs/*;
    zsh: no matches found: /Users/piyush/IdeaProjects/SeleniumProject/libs/*

    Do i need to manually create the libs and bin folders in my project structure?

    Note:i am using maven project.

  2. Tester_br says

    Hi Mukesh,

    Thanks for this guide, it’s really helpful.

    Could you please give more details about libs and bin folders? What do we need to add to them?

    Thank you!

    • Mukesh Otwani says

      Hi Villa,

      Thanks for approaching me. bin folder contains .class files which are java executables and libs contains dependencies which are required during runtime. That is why we setting classpath of these folders. This is old approach. I would recommend you to go with maven which is easy to maintain

  3. Venkatesh says

    Hi Mukesh,

    How to execute shell command used on Jenkins Slave : Chrome Browser Parameterization. If you have any idea or video link please share me.

    Already code is hardcoded in shell command for my project

AltStyle によって変換されたページ (->オリジナル) /