Thursday, January 7, 2016

TestNG printing data provider parameter to report and Reporter Interface



Test NG. Use of Reporter.Log, Data Provider, Getting the data provider parameter on reports




      @DataProvider(name = "dp")  
      public String[][] dp() {  
           String testCaseName[][] = { { "T_Name01"},{"T_Name02" }};  
           return testCaseName;  
      }  
      String testCaseNamePrint = "Test_Case_01";  
      WebDriver driver;  
      @Test(enabled = true, dataProvider = "dp", dataProviderClass = sudas.com.se.study.SandBoxTest.class)  
      public void testCase01(String testCaseNamePrint) {  
           driver.navigate().to("http://www.google.co.in");  
 Reporter.log("This is my Test", true);

      }  
      @Test  
      public void testCase02() {  
           System.out.println("Test Case 02");  
      }  
      @Test  
      public void testCase03() {  
           System.out.println("Test Case 03");  
      }  
      @Test  
      public void testCase04() {  
           System.out.println("Test Case 04");  
      }  
      @BeforeMethod  
      public void beforeMethod() {  
           System.out.println("@BeforeMethod");  
      }  
      @AfterMethod  
      public void afterMethod() {  
           System.out.println("@AfterMethod");  
      }  
      @BeforeClass  
      public void beforeClass() {  
           System.out.println("@BeforeClass");  
      }  
      @AfterClass  
      public void afterClass() {  
           System.out.println("@AfterClass");  
      }  
      @BeforeTest  
      public void beforeTest() {  
           System.out.println("@BeforeTest");  
      }  
      @AfterTest  
      public void afterTest() {  
           System.out.println("@AfterTest");  
      }  
      @BeforeSuite  
      public void beforeSuite() {  
           System.out.println("@BeforeSuite");  
           driver = new FirefoxDriver();  
      }  
      @AfterSuite  
      public void afterSuite() {  
           System.out.println("@AfterSuite");  
      }  

1 comment:

  1. Nice article. Thank you for this. I had few doubts, would be great if you could help.
    1) Reporter.log("This is my Test", true); , where is this Reported class taken from and what does it do ?
    2) Is dataProviderClass attribute mandatory ? What is the purpose of explicitly mention it ?

    Thanks
    Sagar

    ReplyDelete