Wednesday 13 August 2014

Testng annotations examples and TestNG xml file


public class NewTest
{
 @Test(groups = {"functest"})
 public void testMethod1() {
 System.out.println("This is my test1");
 }
 @Test(groups = { "functest" })
 public void testMethod2() {
 System.out.println("This is my test2");
 }
 @Test(groups = {"notingroup"})
 public void testMethod8() {
 System.out.println("This is my test8");
 }
 @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");

 }
 @AfterSuite
 public void afterSuite() {
 System.out.println("afterSuite");

 }
 @DataProvider(name = "test1")
 public static Object[][] primeNumbers()
    {
     return new Object[][] { { 2}, { 6}};
 }
 @Test(dataProvider = "test1")
 public void testPrimeNumberChecker(Integer inputNumber)
    {
    System.out.println(inputNumber + " " + inputNumber);
 }
 @Factory
 public static Object[] data()
    {
                return new Object[]
                        {
                        new NewTest(),
                        new NewTest()
                        };
               
}
      @Parameters({ "browser123"})
     @Test(groups = {"functest"})
    public void chekPara(String browser123)
    {
        System.out.println(browser123);
        Reporter.log("Application Opened");
    }
 }

For TestNG xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
    <test name="test1">
            <parameter name="browser123" value="www.google.com"></parameter>
        <groups>
        <run>
        <include name="functest" />
        <include name="notingroup" />
        </run>
    </groups>

    <classes>
        <class name="NewTest" />
    </classes>
    </test>
</suite>

Powered By- selenium blogs Hitesh Singh

No comments:

Post a Comment