running same test with different dataprovider in testng

1.8k views Asked by At

For example:

  • Data provider 1: dataA
  • Data provider 2: dataB, dataC
  • Data provider 3: dataD, dataE, dataG

So my test takes in a data provider. But I want it to chose different data provider for different test type depending on test group. For example if I am running group "smoke" then I want to use data provider 1, if I am running group "sanity" then I wanted to run data provider 1 and data provider 2, and If I am running group "regression" then I want it to run data provider 1, 2 and 3.

Is this possible? If so can you please provide the information or point me to documentation or something that could help.

Currently my work around is to have 3 different test for each of the group and then I can select which data provider to use. I can also combine data provider.

The problem with my work around is that all 3 test are exactly same the thing that is different is the group and the data provider.

thanks!

1

There are 1 answers

0
Jaroslav Cincera On BEST ANSWER

What about to use one data provider which returns different data - based on current test group:

@DataProvider(name = "myDataProvider")
public Object[][] testDataProvider(ITestContext context) {
    List<String> includedGroups = Arrays.asList(context.getIncludedGroups());

    if(includedGroups.contains("myGroup")) {
        return dataA;
    }
    else if (includedGroups.contains("myOtherGroup")) {
        return dataBC;
    }

    //...
}