Friday 27 November 2015

Continuously Integrate your Framework with Jenkins

Prerequisites :
        
        - You first need to download Jenkins. You can get that from here http://jenkins-ci.org .
        - Download ' Jenkins.war' file and save it. (In my case I kept in my project home directory)

Configuration with Selenium:
      
        - Open the command prompt and go to the location where Jenkins stored.
        - Run the command 'java -jar jenkins.war'

Check:
      
        - Once Jenkins server is up and running, you will get success message.
        - You can navigate to below url for Jenkins UI

           http://localhost:8080 

        - Now Jenkins in up and running.

Steps:
       
       - Now Click on > Manage Jenkins and then Configure System.
       - Here navigate to JDK section and Click on Add JDK button.
       - Uncheck Install automatically check box so Jenkins will only take java which we have mention above.
       - Give the name as JAVA_HOME and Specify the JDK path.
       - Once done click on save and apply.

Execute the Selenium build using Jenkins:

       - We can execute test-cases in Jenkins using four ways

            1.Execute Windows batch command
            2.Execute shell
            3.Invoke Ant
            4.Invoke top-level Maven targets.

            We are going for 'Execute Windows batch command'. For that we need to create a batch file first then we will               add the same batch file to Jenkins 
   
Create a Batch File:

        - Here we need to set class path of TestNG so that we can execute testng.xml files  

          Our project structure should be like this

          


           - Open command prompt and set the class path
             Here we will set the path of bin folder and libs folder (inside libs we have all libraries)

             Home directory > set class path=D:\Your Location\bin;D:\Your Location\libs\*;    
             
           - Open notepad and type the below command and save as run.bat file 

              java -cp bin;libs/* org.testng.TestNG testng.xml 
           
              Save this file at your project(Root level)


Create a job in Jenkins:

           - Go to URL type http://localhost:8080
           - Click on new item.
           - Give the Job-Name, select Build a free-style software project and Click on OK  button.
           - Navigate to Advanced Project Options > Check the use custom Work-space > in directory we will specify the                   project home directory
           - Important part now specify the Add Build step >Click on Execute Windows batch command.
           - In the section please specify the batch file which we created and click on Apply and save.

             Click on Build now option and check the Console Output for results.

Schedule your build in Jenkins:

           - Jenkins comes with very good functionality in which we can schedule jobs which we created.
             Open job which we created now and Click on configure > select the check box build                                                        periodically.

           - Specify the time here we need to careful about the syntax

             Jenkins works on Cron pattern.

             It accepts 5 parameter, 

             * * * * *

             Here first parameter- specify minute and range will vary from 0-59

             Here second parameter- specify hours and range will vary from 0-11

             Here third parameter- specify day and range will vary from 0-7 here 0 and 7 will be Sunday

             Here fourth parameter- specify month and range will vary from 1-12

             Here fifth parameter- specify year so here you can specify *   

Finally, we have executed our test case successfully. If you have any issue while running Jenkins please comment below.
OR mail me @deshpandeaditya111@gmail. 

Thank you.