Testng - Is it possible to pass have parameters of

2019-08-28 22:49发布

问题:

   DataProvider(name = "sizerDefaults")
   public Object[][] getSizerDefaults() {

   } 

    @Test(dataProvider = "sizerDefaults")
    public void sizerDefaults(String... args) {

    }

Above is my DataProvider and the methods which uses a DataProvider.

Requirement is, it possible to have parameters to a DataProvider? That is, I want to use the same DataProvider for several methods, where a String value changes every time for each method, which I should be able to pass in the @Test methods wherever I am using my @DataProvider

I expect something like

   DataProvider(name = "sizerDefaults")
   public Object[][] getSizerDefaults(String a) {

   // Will be using 'String a' somewhere  here

   } 

    // Here I should be able to pass different String values In @Test methods wherever I use this dataProvider = "sizerDefaults"
    @Test(dataProvider = "sizerDefaults")
    public void sizerDefaults(String... args) {

    }

The main question is how & where i will fetch the data from DataProvider as a array like (String .. args) or (String[] args). Because i have to do something literally with the first element that is args[0]

At the same time pass my String for each @Test that uses the dataProvider