Running Testng Programs from Jenkins!!!
Step 1- Lets create a windows batch which is required to invoke from Jenkins.
To create batch file we need to set classpath of testng so that we can execute testng.xml files.
Our project structure should look like
Open command and set the classpath and execute the program from command line
While setting classpath we will set the path of bin folder and libs folder (inside libs we have all libraries).
Setting the classpath as below:
C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject> set classpath=C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\bin;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\testng-6.8.5.jar;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\jcommander-1.29.jar
C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject>java org.testng.TestNG testng.xml
Open notepad and type the below commands and save as .bat file –Copy the run.bat in the project directory. Contents of the run.bat as follows:
set classpath=C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\bin;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\testng-6.8.5.jar;C:\MyHome\ide-home\workspace-3.6\h2k\TestngProject\lib\jcommander-1.29.jar
java org.testng.TestNG testng.xml
Step 2- Now create a job in Jenkins which will execute our Testcases.
a. Open Jenkins on browser (type http://localhost:8080)
Click on new item
b. Specify the name of Job-Name, select Build a free-style software project and Click on OK button .
c. Navigate to Advanced Project Options > Check the use custom workspace > in directory specify the project home directory.
d. Now the final and most important part specify the Add Build step >Click on Execute Windows batch command.
e. In the command section specify the batch file which we created and click on on Apply and save
Step 3- Now finally run the Build > Click on Build now.
Step 4- Check Build history and Console output and verify the output.
How to schedule buid in Jenkins
0 comments:
Post a Comment