1
votes

I have a scenario where many test suites are added to TestNG object for running. I have a testMethod() in a class TestClass. I am using dataProvider also.

I want to know inside the test method which is the current TestSuite ??

How can I achieve without disturbing my DataProvider parameters for the TestMethod ??

2

2 Answers

0
votes

Here is the way Cedric implemented it after much convincing as you can see in this thread from a long time ago:

  @DataProvider(name = "A")
  protected Object[][] dp(ITestContext tc) {
    return new Object[][] { 
        { tc }
    };
  }

  @Test(dataProvider = "A")
  public void testA(ITestContext tc) {
    System.out.println("SUITE NAME:" + tc.getSuite().getXmlSuite().getName());
  }
0
votes

Got the Answer.

From the book by Beust I got my answer.

There are different ways to define a dataProvider method:

@DataProvider
public void create() { ... }
@DataProvider
public void create(Method method) { ... }
@DataProvider
public void create(ITestContext context) { ... }
@DataProvider
public void create(Method method, ITestContext context) { ... }

And the last method helped me solve my problem. This method gives the method reference that is going to be called as well as the Test Context.