1

How to use dependency in TestNG with two test cases from two different classes? For Example, I have two classes:

package com.test.class

public class A{

  @Test
  public void testA(){

  }
}

package com.test.class

public class B{

  @Test
  public void testB(){

  }
}

The method testB() is depending on the method testA(), but they are in different class. I've tried to use dependsOnMethods,dependsOnGroups and XML dependencies. None of them worked. Help me solve this!

  • There is no direct way. You can do one thing. Set a flag in testA() method. Verify that flag as True in testB(). If True then run ur code otherwise throws exception. – Sagar007 Feb 5 '18 at 3:47
2

In the @Test configure the group settings

package com.test.class

public class A {

  @Test (groups = "A")
  public void testA() {
    // Tests
  }
}

in the second code

package com.test.class

public class B {

  @Test (groups = "B", dependsOnGroups = "A")
  public void testB() {
    // Tests
  }
}

Then in the XML create a tag and add all the groups that are created.

When running the second code will depends upon the first code.

0

Put the method in a group and use dependsOnGroups

This may be help you TestNG dependsOnMethods from different class

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.