Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
114 views
by The go-to Tester (344 points)
How can we set Dependencies in TestNG while running a suite of test cases

1 Answer

0 like 0 dislike
by The go-to Tester (473 points)
selected by
 
Best answer

We can set dependency in testNg by writing the paramter dependsOnMethods= in the @Test annotation.

Supposing you are testing online email application using selenium WebDriverand you have two @Test methods In your class : 1) For LogIn and 2) For Check Mail. Now due to the some reasons (Invalid credentials), LogIn @Test method fails. In this case you not need to execute Check Mail @Test method because how can you check emails without LogIn In email application? In this case, You can use dependsOnMethods with @Test annotation of  Check Mail method to skip Its execution.

@Test

public void Login() {

  Assert.assertTrue(5>6, "Condition Is False.");
    } 

@Test(dependsOnMethods={"Login"})

    public void checkMail() {
  System.out.println("checkMail Test code.");   
    }


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...