1

I have a data file in selenium webdriver as below:

[Contact_Buyer]
Title = Madam
Contact_language = French

[Contact_Owner]
Title = sir
Contact_language = English

I want my test to run for each keyset Contact_Buyer and Contact_Owner. suppose my test as below:

public void setcontact() {
    crmdatafile = new ReadData(file.getAbsolutePath()); //Has complete file contents
    Section section= crmdatafile.data.get("Contact_Buyer"); //has all values under section for Contact_Buyer
}

How do I use dataprovider to pass these keysets to testcase such that my test is run twice for different data?

2

The documentation is a good start to understanding the data provider feature.

But the following code will run the test twice (once for the buyer and once for the owner):

@DataProvider
public Object[][] getContacts() {
    crmdatafile = new ReadData(file.getAbsolutePath()); //Has complete file contents
    Section buyerSection = crmdatafile.data.get("Contact_Buyer");
    Section ownerSection = crmdatafile.data.get("Contact_Owner");
    return new Object[][]{ { buyerSection }, { ownerSection } };
}

@Test(dataprovider = "getContacts")
public void test(Section section) {
    // TODO use section and make assertions
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.