Reputation: 93
For example:
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!
Upvotes: 2
Views: 2069
Reputation: 1036
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;
}
//...
}
Upvotes: 8