I'd like to know whether there is a way to use both @DataProvider
and Paramaters
to pass parameters.
I've tried two options, but both of these failed:
@Parameters("Brand")
@Test(dataProvider="dpCGA", groups={"CGA"})
public void createAccount(String brand) {
setBrand(brand);
}
brand variable is being overwritten by the data provider in the above example.
@Parameters("Brand")
@Test(dataProvider="dpCGA", groups={"CGA"})
public void createAccount(String brand, String email) {
setBrand(brand);
createAccount(email);
}
Test case didn't even run.
I'm using TestNG to run my test cases, and want to grab the brand parameter from the XML file.
Also, I've got an Excel file which I use to keep emails, and want to grab those values using @DataProvider
.
Is it possible to use both of these tags together? If not, is there an other way to grab the brand parameter from the XML file?
Thanks in advance
@DataProvider is one of the ways to pass parameters to a method. You cannot use both for same method.
Looking at your question, you can simply add the brand to the DataProvider method something like,
@DataProvider(name="dpCGA")
public Object[][] data() {
return new Object[][] {
{"brand", "email1"},
{"brand", "email2"}
};
}
and pass it to the method,
@Test(dataProvider="dpCGA", groups={"CGA"})
public void createAccount(String brand, String email) {
setBrand(brand);
createAccount(email);
}