2

I am lagging behind to understand the concept of dependsOnMethods and priority. I googled but I didn't get enough info about this. A one line answer will be greatly appreciated. Can we write multiple methods with the same priority?

  • 1
    When we use Depends On the subsequent methods will be skipped when your methods fail. In case of priority all the test cases will run. – Anamika Singh Nov 19 '18 at 10:32
4

Yes, definitely we can write multiple methods with same priority but disadvantage of using this-There is no guarantee which method will run first, So- Instead of this,you can use 'dependsOnGroups' annotation from TestNG which you can easily perform stepwise operations.

@Test(priority=1)
 public void Login() 
{ 
  System.out.println("LogIn Test code.");
  Assert.assertTrue(5>6, "Condition Is False.");
}

@Test(priority=1, dependsOnMethods={"Login"}) 
public void checkMail() 
{ 
  System.out.println("checkMail Test code.");
}

@Test(priority=1,dependsOnMethods={"Login","checkMail"}) 
public void LogOut() 
{ 
  System.out.println("LogOut Test code.");
}

----------------------
Instead of this you can use -'dependsOnGroups' annotation.

@Test(groups = { "A" })
   public void login() 
  {
      System.out.println("PrintMessage()");
  }
.
.
.
.

@Test(dependsOnGroups = { "A" }) 
public void LogOut() 
{ 
  System.out.println("LogOut Test code.");
}
  • Test(priority=1,dependsOnMethods={"Login","checkMail"}) how this will work ? is it execute login method then checkmail? – sameer joshi Apr 21 '16 at 9:32
  • This test will run unless & until- "Login","checkMail" these two methods successfully run & pass. If one method gets failed last method i.e-logout test will not run. It means logout test is depends on both tests. – Bharat Mane Apr 21 '16 at 9:41
  • @sameer.....got it ? let me know if you have any doubts – Bharat Mane Apr 21 '16 at 9:43
2

Yes, you can write multiple methods with the same priority (quite similar to not use any priority - all methods has the same default priority). About dependsOn annotation in a few words:

dependsOnMethods

There is no guarantee on the order on which the methods depended upon will be run, but you are guaranteed that all these methods will be run before the test method that contains this annotation is run.

More complex answer you can find here: https://stackoverflow.com/a/36713748/4855333

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.