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?

juherr
  • 285
  • 1
  • 7

1 Answers1

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
}
juherr
  • 285
  • 1
  • 7