Downloading Jenkins

Download Jenkins

Step 1- Navigate to Below URL   http://jenkins-ci.org













Step 2-Download Jenkins.war and save into desktop

Open Command prompt and navigate till project home directory and Start Jenkins server

This is how to run jar files from the command line.

















Step 3- Once Jenkins server is up. You will get above success message. 

Open any browser and type the url http://localhost:8080

Note- By default Jenkins will start on 8080 port number

 Now Jenkins in up and running so now we have to configure Jenkins so that we can execute our test case via Jenkins

Step 4- Once Jenkins is running so we are done but before moving to create build we need to configure Jenkins Click on --> Manage Jenkins.



Click on Configure System.










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.










Running Testng Programs from Jenkins!!!

Order of TestNG Annotations!!!!!













The Order of the below Testng Annotations is important. Lets look into them below:
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeGroups
@BeforeMethod
@AfterMethod
@AfterGroups
@AfterClass
@AfterTest
@AfterSuite

Example for @BeforeMethod & @AfterMethod:


Scenario1:

Suppose for every test-case to execute the pre-condition as login and post-condition as log-out then we have to use as follows:

LoginApp.java

public class LoginApp 
{
        @BeforeMethod
         public void Login()
        {
              System.out.println("In Login Method");
         }
          @AfterMethod
          public void Logout()
         {
               System.out.println("In Logout Method"); 
         }
        @Test
         public void testcase1()
        {
               System.out.printl("testcase1");
         }
         @Test
         public void testcase2()
        {
               System.out.printl("testcase2");
         }
}

Order of Execution:

Login()
testcase1()
Logout()
Login()
testcase2()
Logout()


Example for @BeforeClass & @AfterClass:

Scenario2:

Suppose for all the test-cases the pre-condition say creating a driver instance should be invoked only and the post-condition say quitting the browser once after the execution of all the @Test methods is done.

LoginApp.java

public class LoginApp 
{
         WebDriver driver;
        @BeforeClass
         public void invokeBrowser()
        {
             driver = new FirefoxDriver();
             driver.get("http://www.Facebook.com");
         }
          @AfterClass
          public void closeBrowser()
         {
              driver.quit();
         }
        @Test
         public void testcase1()
        {
               System.out.printl("testcase1");
         }
         @Test
         public void testcase2()
        {
               System.out.printl("testcase2");
         }
}

Order of Execution:

invokeBrowser()
testcase1()
testcase2()
closeBrowser()

Example for @BeforeTest & @AfterTest:

Scenario 3:
Suppose for example if we want to execute the same program on multiple browsers say IE and FF. In those cases we should have configuration file should be written as follows:


Inserting an Image as a hyperlink in Testng Reporter Log