Configuration File testng.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suites" parallel="none"> <listeners> <listener class-name="com.uc.test.selenium.util.Listener"></listener> </listeners> <test name="Simple Test"> <classes> <class name="com.uc.test.selenium.tests.Test_Login"/> </classes> </test> <!-- test name="ALL"> <packages> <package name="com.uc.test.selenium.tests" /> </packages> </test --> </suite> <!-- Suite -->
Imports
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test;
Class Decaration
public class Test_Login { }
- Class must be public for TestNG to hook into it
- likewise all the Annotated methods must be public also
Annotations
When are the methods calls by TestNG?
- BeforeClass
- BeforeSuite
- BeforeMethod
- Test
- AfterMethod
- BeforeMethod
- Test
- AfterMethod
- BeforeMethod
- AfterSuite
- BeforeSuite
- BeforeMethod
- Test
- AfterMethod
- BeforeMethod
- Test
- AfterMethod
- BeforeMethod
- AfterSuite
- BeforeSuite
- AfterClass
@BeforeClass
@BeforeClass
public void beforeClass() throws Exception {
//before everything
}
@BeforeSuite
@BeforeSuite
public void beforeSuite() throws Exception {
//before each suite, if defined
}
@BeforeMethod
@BeforeMethod
public void beforeMethod() throws Exception {
// before each test
}
@Test
@Test
public void test_1() throws Exception {
// test logic
}
@AfterMethod
@AfterMethod
public void afterMethod() throws Exception {
// after each test
}
@AfterSuite
@AfterSuite
public void afterSuite() throws Exception {
//after each suite, if defined
}
@AfterClass
@AfterClass
public void afterClass() throws Exception {
//after everything
}
- Log in to post comments
