TestNG – Dependent Test:
Sometimes, you may need to invoke methods in a Test case in
a particular order or you want to share some data and state between methods.
This kind of dependency is supported by TestNG as it supports the declaration
of explicit dependencies between test methods.
TestNG allows you to specify dependencies either with:
·
Using attributes dependsOnMethods in
@Test annotations OR
·
Using attributes dependsOnGroups in
@Test annotations.
Take a look over the below example:
package Others;
import
org.testng.annotations.Test;
public class TestNG_DependTest {
@Test (dependsOnMethods =
{ "OpenBrowser" })
public void SignIn() {
System.out.println("This will
execute second (SignIn)");
}
@Test
public void OpenBrowser() {
System.out.println("This will
execute first (Open Browser)");
}
@Test (dependsOnMethods =
{ "SignIn" })
public void LogOut() {
System.out.println("This will
execute third (Log Out)");
}
}
Output:
This will execute first (Open Browser)
This will execute second (SignIn)
This will execute third (Log Out)
PASSED: OpenBrowser
PASSED: SignIn
PASSED: LogOut
No comments:
Post a Comment