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 automationFramework;
import org.testng.annotations.Test;
public class Dependent {
@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)");
}
No comments:
Post a Comment