below are the sample demo code for testng beginners
package test;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestNgDemo {
@BeforeSuite
public void f6() {
System.out.println("Before suite is executed");
}
@BeforeClass
public void f5() {
System.out.println("Before class is executed");
}
@BeforeMethod
public void f4() {
System.out.println("Before Method is executed");
}
@Test(groups={"sanity"})
public void f() {
System.out.println("Test is executed");
}
@Test(groups={"regression"},priority=2)
public void test2() {
System.out.println("Test 2 is executed");
}
@Test(dependsOnMethods ={"test4"},groups={"regression"},priority=1)
public void test3() {
System.out.println("Test 3 is executed");
}
@Test(groups={"regression"})
public void test4() {
System.out.println("Test 4 is executed");
String project="PNC";
System.out.println(project);
}
@Parameters("browser")
@Test(groups={"regression"},priority=3)
public void test5(String browser) {
System.out.println("Test 5 is executed");
System.out.println("Browser: "+browser);
}
@AfterMethod
public void f3() {
System.out.println("After Method is executed");
}
@AfterClass
public void f7() {
System.out.println("after class is executed");
}
@AfterSuite
public void f8() {
System.out.println("after suite is executed");
}
}
Below are testng xml code for ref with all the annotations
<?xml version="1.0" encoding="UTF-8"?>
<suite name="example suite 1" parallel="methods" thread-count="2" >
<test name="Regression suite 1" >
<!-- <parameter name = "browser" value="chrome"/> -->
<groups>
<run>
<include name = "regression" />
</run>
</groups>
<classes>
<class name="test.TestNgDemo"/>
</classes>
</test>
<test name="Regression suite 2" >
<parameter name = "browser" value="firefox"/>
<groups>
<run>
<include name = "regression" />
</run>
</groups>
<classes>
<class name="test.TestNgDemo"/>
</classes>
</test>
<test name="Regression suite 3" >
<parameter name = "browser" value="IE"/>
<groups>
<run>
<include name = "regression" />
</run>
</groups>
<classes>
<class name="test.TestNgDemo"/>
</classes>
</test>
</suite>
sdhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh lakjfakdj kjjjjjjjjjjjjjjjjjjjjj ksjkjjkdj
dkfjekjfkjk kdjfkjkjkkkkkkkkkkkkkkkkkkkkkkkkkk jdkjfakjdfk dfajlkfjak kjdkjakj jkdjfklajkdfjak kjekla dkfjlakjfk ljkdjfak lkljkdjfa k j kajkdjfdkajfkj dnflakjkdlj arjkjakfj qeieajfdlkjafkj kdjakfjd ajf
Aucun commentaire:
Enregistrer un commentaire