In this post, we will see TestNG Annotations in Selenium | Before and After Method, Class, Test, Suite
Program Code (Program 1.java):
package mytest;
import org.testng.annotations.Test;
public class Program1 {
@Test
public void AdmissionLogin()
{
System.out.println("Admission Login");//code for testcase
}
@Test
public void AdmissionBrokenlinks()
{
System.out.println("Admission Broken links"); //code for testcase
}
}
Program Code (Program 2.java):
package mytest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Program2 {
@BeforeMethod
public void beforeMethod()
{
System.out.println("Before Method...");
}
@AfterMethod
public void afterMethod()
{
System.out.println("After Method...");
}
@BeforeClass
public void beforeClass()
{
System.out.println("Before Class...");
}
@AfterClass
public void afterClass()
{
System.out.println("After Class...");
}
@BeforeTest
public void beforeTest()
{
System.out.println("Before Test...");
}
@AfterTest
public void afterTest()
{
System.out.println("After Test...");
}
@BeforeSuite
public void beforeSuite()
{
System.out.println("Before Suite...");
}
@AfterSuite
public void afterSuite()
{
System.out.println("After Suite...");
}
@Test
public void PlacementLogin()
{
System.out.println("Placement Login");//code for testcase
}
@Test
public void PlacementBrokenlinks()
{
System.out.println("Placement Broken links"); //code for testcase
}
}
Program Code (Program 3.java):
package mytest;
import org.testng.annotations.Test;
public class Program3 {
@Test
public void FacultyLogin()
{
System.out.println("Faculty Login");//code for testcase
}
@Test
public void FacultyBrokenlinks()
{
System.out.println("Faculty Broken links"); //code for testcase
}
}
Program Code (testng.xml):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Admission">
<classes>
<class name="mytest.Program1"></class>
</classes>
</test>
<test name="Placement and Faculty">
<classes>
<class name="mytest.Program2"></class>
<class name="mytest.Program3"></class>
</classes>
</test>
</suite>
Watch on YouTube: https://www.youtube.com/watch?v=iet0q6ZZsKI
No comments:
Post a Comment