Saturday, July 8, 2017

Execute Selenium Test Cases from Jenkins

In the previous post Jenkins Installation and Java Configuration for Windows we have learned installing Jenkins on windows machine and configuring Java in it. In this post we will learn executing the Selenium tests from Jenkins tool.

Step 1: Create a Selenium + TestNG project in Eclipse. And download Selenium and TestNG jar files.

Go to project root directory and create libs folder in it. Add keep the downloaded jar files in libs folder as shown in the below image.

You can download Selenium Jar file from click here. And the TestNG jar files (testng.jar and jcommander.jar) can be taken from the eclipse plugins location as show below.

Step 2: Add these three jar files in the Java Build Path, by right clicking on the project--> Build Path--> Configure Build Path --> Add External Jars, select the jars from "libs" folder. 

Step 3: Create a sample test in the project as shown in the below screen.

You may copy and paste the below code

Step 4: Create testng.xml file. Right click on the package--> TestNG--> Convert to TestNG. Give the name and finish it.

Click here to know how to create a testng.xml file. We should see the testng.xml file in the project home directory as shown in the below image

Step 5: Create a batch file, open a notepad and enter below code in it and save it as "build.bat".
java –cp bin;libs/* org.testng.TestNG testng.xml

The batch file build.bat should be created in the project home directory. If you double click the batch file the execution starts.

Step 6: Go to Jenkins dashboard and click on the New Item to create a new job

Step 7: Enter sample name say FirstSeleniumTest and select Freestyle Project. Click OK

Step 8: Enter some description and click on Advanced…

Step 9: Select Use custom workspace checkbox and enter the project home directory path in the Directory text filed

Step 10: Go to Build section and then Select Execute Window batch command from the drop down list

Step 11: Enter the batch file name build.bat in the command text filed. Click Apply and then Save

Step 12: You will be navigated to the project page in Jenkins. Click on the Build Now to start the tests execution

Step 13: And then go to Console Output. You will see test case execution results in the console output

You ca observe the browser title, print statements outputs given in the program in the console output.

That’s it that is how we can run the Selenium Tests from Jenkins. Thanks!! 

#HappyLearning #HappyTesting


  1. Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

  2. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. test machine


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...