Parameterizing both data and object names using testNG and Data Providers
-
14-06-2021 - |
Question
I am trying to create a hybrid framework where I will be passing the object names and the corresponding values from an excel sheet. Here is what I want to do
FieldName Type Value1 Value2 Value3
FName Edit John Smith Carla
LName Edit Fellow Carson Black
Submit Link Click Click Click
- Field Name: Contains the Xpath or ID's for identifying the objects
- Type: Contains the type, like text box or list box etc, so that I can use a IF loop to handle each TYPE of object accordingly.
- Value 1..3..: The different values I want to run the test (objects) agianst.
How can I go about doing this using Data Providers, because Ideally the first 2 columns need to be constant while I use different data values. Also, the dataproviders seem to be reading the array row wise. Sorry if this is a elementary question, I am new to testNG and had heard excellent things about and wanted to check it out.
No correct solution
OTHER TIPS
Data providers return whatever data works for you, so you just need to think about how you can turn this spreadsheet into objects that your test method will accept. For example, if you want your test to take one parameter per column:
@Test(dataProvider = "dp")
public void f(String fieldName, String type, String value1, String value2, String value3) {
// test
}
@DataProvider
public Object[][] dp() {
// read the spreadsheet
return new Object[][] {
new Object[] { fieldName, type, value1, value2, value3 }, // row 1
new Object[] { fieldName, type, value1, value2, value3 }, // row 2
}
}