Testng - Is it possible to pass have parameters of a Dataprovider method?

廉价感情. 提交于 2019-12-11 18:29:47

问题


   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

来源:https://stackoverflow.com/questions/52753698/testng-is-it-possible-to-pass-have-parameters-of-a-dataprovider-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!