Complete Guide for Selenium integration with jenkins Maven

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.

 

204 Comments

  1. Shiva Krishna
  2. Shoaib Patel
  3. Amit Kumar Singh
  4. Zafar
  5. Ahmed Bilal
  6. Saurabh Sahu
  7. Arunpandi
      • Ram
  8. Patricia
  9. shivkumar
      • shivkumar
  10. manish
  11. yogesh
  12. sindhu
  13. Rohit Sharma
  14. kanchana
  15. kanchana
  16. Vandana
  17. Pooja Vengurlekar
  18. praveen
  19. Naveen Balanagu
      • Naveen Balanagu
  20. Omar Careem
  21. usama awan
  22. Manmohan
      • Sofia
  23. Prashant Soni
  24. Anmol
      • Anmol
  25. Test admin
  26. Pradeep Samson
  27. Anwar
  28. pavankumar
      • pavankumar
  29. Rupesh
  30. Amod Mahajan
  31. Ranjitha
  32. Bimlesh
      • Bimlesh
  33. Ranjana
  34. Ranjana
  35. Mohanasundaram
  36. sahil
  37. kiran
  38. Jai Prakash Keswani
  39. Jai Prakash Keswani
  40. upali
  41. Neha
  42. Tejas
  43. Adeel Zahir
      • Adeel Zahir
      • Adeel Zahir
  44. Ayushi Sharma
  45. Ankita Jangra
  46. pankaj
  47. Shri
  48. Carl Jerich Lague
    • Mukesh Otwani
      • Carl Jerich Lague
  49. reddie2203
  50. Satya
  51. Ajit Singh
  52. Srikanth
  53. suresh
      • Abhi
  54. SHEKHAR
  55. shruthi
  56. shruthi
  57. Mubbashir
  58. alvin
  59. alvin
  60. Ed Nonog
  61. sree
  62. saikiran
  63. Bhushan
  64. Bhushan
  65. CGupta
  66. rachana
      • Rachana
  67. Sagar
  68. Mig
  69. Prashant
  70. Karthik
    • Mukesh Otwani
      • Karthik
  71. nitin82
      • nitin82
        • Karl El
          • Mukesh Otwani
  72. mike comtrox
  73. Manne Rakesh
    • Mukesh Otwani
  74. mike comtrox
    • Mukesh Otwani
      • mike comtrox
        • Mukesh Otwani
  75. Rajasekhar Jangala
    • Mukesh Otwani
  76. amitaks

Leave a Reply