Using both @DataProvider and @Parameters

I would like to know if there is a way to use both @DataProvider

and Paramaters

to pass parameters.

I tried two options, but both failed:

@Parameters("Brand")
@Test(dataProvider="dpCGA", groups={"CGA"})
public void createAccount(String brand) {
    setBrand(brand);
}

      

In the above example, the data provider is overwritten with a variable.

@Parameters("Brand")
@Test(dataProvider="dpCGA", groups={"CGA"})
public void createAccount(String brand, String email) {
    setBrand(brand);
    createAccount(email);
}

      

The test drive didn't even start.

I am using TestNG to run my test cases and want to grab a brand parameter from an XML file.

Also, I have an Excel file that I am using to store my email and I want to get these values ​​using @DataProvider

.

Can both of these tags be used together? If not, is there any other way to grab the brand parameter from the XML file?

Thank you in advance

+3


source to share


3 answers


@DataProvider is one way to pass parameters to a method. You cannot use both methods for the same method.

Looking at your question, you can simply add the brand to the DataProvider method, for example

  @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);
}

      

+2


source


You cannot use @DataProvider and @Parameters at the same time. Pass all parameters via @DataProvider.



0


source


As already noted, DataProvider

it is not possible to get results together with the set parameters. This answer confirms this by stepping through the code:

While it DataProvider

can get the context using ITestContext

, it only makes the parameters available in the set (XML) not set using system properties.

0


source







All Articles