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

2 comments:

Java Program 5: How to reverse given string and each word of it?

Let us understand the problem with an example, suppose "Learn Core Java" is the given string then the expected output should be &...