I have been looking for a way to use multiple DataProviders in my test method. My scenario is as follows:
lets say we have a DataProvider class:
@Test
public class ExampleDataProvider {
/**
* Returns the list of shape codes.
*
* @return the collection shape codes.
*/
@DataProvider(name = "ShapeCodes")
public static Object[][] getShapeCodes() {
return new Object[][] { new Object[] { Shape.Square },
new Object[] { Shape.Triangle }
};
}
/**
* Returns the list of color codes.
*
* @return the collection of color codes.
*/
@DataProvider(name = "ColorCodes")
public static Object[][] geColorCodes() {
return new Object[][] { new Object[] { Color.Green },
new Object[] { Color.Red }
};
}
}
Now in my Test method I want to run for all combinations of scenarios:
- Green-Square
- Red-Square
- Green-Triangle
- Red-triangle
How should I achieve this in my code, given that I cant specify multiple DataProviders with @Test
annotation
@Test(dataProvider = "ShapeCodes", dataProviderClass = ExampleDataProvider.class)
public void test(String ShapeCode, String ColorCode) throws IOException {
.............
/* tests for color shape combination */
.............
}
EDIT : I found a similar problem and a @ workaround but I am still wondering if there are better ways to handle this.