Question

I want my test cases to execute priority wise, but all the test cases which depends on 'Method1' are executing first, so my other testcases are failing.

@Test(dependsOnMethods = {"verifyLogin"}, priority = 0, description = "verify a page access")

  public void Method1() 

@Test(dependsOnMethods = {"Method1"}, priority = 1, description = "verify b page access")

  public void Method2() 

@Test(dependsOnMethods = {"Method1"}, priority = 2, description = "verify c page access")

  public void Method3()

@Test(dependsOnMethods = {"Method3"}, priority = 3, description = "verify d page access")

  public void Method4()

 @Test(dependsOnMethods = {"Method1"}, priority = 4, description = "verify e page access")

  public void Method5()

So the methods 1,2,3 and 5 are executing first, but I want method 4 to execute before 5 as it depends on method 3.

Thanks.

Was it helpful?

Solution

I faced similar problem in my framework test classes. usually if we use both dependsOnMethods or priority in our test class testng executes test with priority first but doesn't apply priority to tests having dependsOnMethods. Tests with 'dependsOnMethod' attribute will run in the last as per their dependencies/priorities. Test case execution order will be like below:

  1. Test cases without dependencies according to priorities.
  2. Test case with dependencies in order of test methods they are dependent on and priority.

Hence,In your case it will execute test cases having dependency on 'method1' first and than test case having dependency on 'method3'. To solve this problem you need understand in which sequence you tests are going to executed based on priorities and dependsOnMethods. You have to adjust both attributes accordingly. You can also make one test case dependent on multiple test methods for example in your case you can make test case 4 dependent on 'method1' as well as 'method3'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top