So to start off, I am building out an automation library built on top of Selenium and Java. I'm building out a way to parameterize data that is being passed into test methods. I am using TestNG.
Right now I have two sample Test methods that take in different Data Models as a parameter. For example, testOne takes in TestModelA, and testTwo takes in TestModelB. However, both of these use the SAME dataProvider. These TestModel classes read from a JSON file and returns the data in getter methods.
Example:
@Test(dataProvider = "JsonDataProvider")
public void testDataProviderOne(TestModelA testData) {
System.out.println(testData.getTestDataAA());
System.out.println(testData.getTestDataAB());
}
@Test(dataProvider = "JsonDataProvider")
public void testDataProviderTwo(TestModelB testData) {
System.out.println(testData.getTestDataBA());
System.out.println(testData.getTestDataBB());
}
What I need help with is building out this DataProvider method...
Right now it will work with one of them if I return the specified Class.
Example:
@DataProvider(name = "JsonDataProvider")
protected static Object[][] getJsonDataModel() {
return new Object[][]{ { new TestModelA() } };
}
I need the DataProvider to return whichever Object is being passed into the test method as a parameter that is using this data provider.
What is the best way to accomplish this.
If you want to check out my project on GitHub, you can at: https://github.com/Dominic-Pace/AutoCoreCommons