Here is a knowledge share of running test scripts via Jenkins. You would now have a brief guidelines and document demo of creating sample test scripts. We would be using Eclipse IDE/Net beans IDE and I have used Eclipse IDE and TestNG in this demo.
Creating Sample Test Script:
- Use Eclipse IDE/ Net beans IDE.
- In my demo I have used Eclipse IDE & TestNG.
SAMPLE CODE & ECLIPSE CONSOLE OUTPUT:
- After creating sample script Right Click on the Project à Go To TestNG & click on Convert to TestNG button.
- testng.xml file is created and stored in Eclipse workspace.
Now, you are required to open browser & go to the given URL – https://jenkins-ci.org/ and follow the steps below.
- Click on the Latest and greatest (1.630) link as highlighted in below image
- The latest version of Jenkins is 1.630
- Jenkins.war file should be downloaded in your default download location.
- Open Command Prompt & follow the following steps to configure Jenkins.
- Go to the particular directory where Jenkins.war is installed & enter the following command java –jar Jenkins.war
You will get Jenkins is fully up and running in Command Prompt if Jenkins configured correctly.
Open Jenkins to view:
- Open browser go to the given URL – http://localhost:8080/
- Normally Jenkins uses 8080 port to run.
- Jenkins Dashboard will displayed with Welcome to Jenkins! Message
Integrating Selenium with Jenkins:
Step 1: Initially your Eclipse IDE workspace contains following items:
- bin folder
- src folder
- test output folder
- testng.xml file
Step 2: You need to add new directory called lib which contains all library jar files.
Step 3: Open Command Prompt & Go to the Jenkins Project workspace created by Eclipse IDE. Use the following command to set classpath.
Step 4: Create new Text Document. Open the newly created Text Document and enter following code into it.
java -cp bin;lib/* org.testng.TestNG testng.xml
Step 5: While saving the text document give file name within the double quotes as shown below.
Success! New run windows batch file is created.
Creating New Job in Jenkins:
- Enter item name as Jenkins Demo, Select Freestyle project radio button & click on OK button.
- Click on the Advanced button Present in Advanced Project Options & Select Use Custom Workspace checkbox
- Enter the directory path where eclipse project is saved(Eclipse IDE Workspace where src, bin, lib & testing.xml files are stored)
- In Build section click on Add build step drop down & select Execute windows batch command.
- Enter command as run.bat (windows batch file created in workspace)
- Click on Apply & than Save button
Project Jenkins Demo is successfully added.
- Click on Build Now button. New build is successfully created & Build History updated the Build Report
- Click on Build Report newly generated by Jenkins.
- Jenkins Console Output is displayed as shown below.