Selenium simple example for TestNG with different Annotations
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class testng_example1 {
@BeforeSuite
public void BeforeSuite()
{
System.out.println("BeforeSuite will be executed before the entire test");
}
@AfterSuite
public void AfterSuite()
{
System.out.println("AfterSuite will be executed after the entire test");
}
@Test
public void testmehtod1()
{
System.out.println("welcome to testng method1");
}
@Test
public void testmehtod2()
{
System.out.println("welcome to testng method2");
}
@BeforeTest
public void BeforeTest()
{
System.out.println("BeforeTest will be executed before the testcases of that class ");
}
@AfterTest
public void AfterTest()
{
System.out.println("AfterTest will be executed after the testcases of that class ");
}
}
BeforeSuite will be executed before the entire test
BeforeTest will be executed before the testcases of that class
welcome to testng method1
welcome to testng method2
AfterTest will be executed after the testcases of that class
PASSED: testmehtod1
PASSED: testmehtod2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
AfterSuite will be executed after the entire test
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class testng_example1 {
@BeforeSuite
public void BeforeSuite()
{
System.out.println("BeforeSuite will be executed before the entire test");
}
@AfterSuite
public void AfterSuite()
{
System.out.println("AfterSuite will be executed after the entire test");
}
@Test
public void testmehtod1()
{
System.out.println("welcome to testng method1");
}
@Test
public void testmehtod2()
{
System.out.println("welcome to testng method2");
}
@BeforeTest
public void BeforeTest()
{
System.out.println("BeforeTest will be executed before the testcases of that class ");
}
@AfterTest
public void AfterTest()
{
System.out.println("AfterTest will be executed after the testcases of that class ");
}
}
Output :
BeforeSuite will be executed before the entire test
BeforeTest will be executed before the testcases of that class
welcome to testng method1
welcome to testng method2
AfterTest will be executed after the testcases of that class
PASSED: testmehtod1
PASSED: testmehtod2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
AfterSuite will be executed after the entire test
No comments:
Post a Comment