Not only us, even your test has dependents!
In real life scenarios there are so many dependencies. It is no wonder the test execution has dependencies. If you are not sure on what I am talking about, let me explain with a example.
Scenario: You need to have kids. To do that, you need to (You may be capable of achieving the third step without the first two, but am talking about the normal procedures)
- Find a girl and fall in love
- Get Married
- Have Kids
Let us write a code to explain this using dependsOnMethods option.
package seleniumWithTestNG;
import org.testng.annotations.Test;
public class HandlingDependents {
@Test (dependsOnMethods = { "findAGirlAndFallInLove" })
public void getMarried() {
System.out.println("Get married ");
}
@Test
public void findAGirlAndFallInLove() {
System.out.println("Find your dream girl");
}
@Test (dependsOnMethods = { "getMarried" })
public void haveKids() {
System.out.println("Have Kids");
}
}
TestNG Output:
Console Output:
Find your dream girl
Get married
Have Kids
PASSED: findAGirlAndFallInLove
PASSED: getMarried
PASSED: haveKids
===============================================
Default test
Tests run: 3, Failures: 0, Skips: 0
===============================================