How to pass parameter to data provider in testng from csv file

一笑奈何 提交于 2019-12-08 11:15:32
luboskrnac

You should read entire file in data provider and return iterator of test cases. Here is some pseudocode for data provider. Notice that I used List<String []> to store test cases instead of Object[][]. This allows you do define test cases dynamically.

    @DataProvider(name = "test")
    public Iterator<Object []> provider( ) throws InterruptedException
    {
        List<Object []> testCases = new ArrayList<>();
        String[] data= null;

        //this loop is pseudo code
        br = new BufferedReader(new FileReader(csvFile));
        while ((line = br.readLine()) != null) {
            // use comma as separator
            data= line.split(cvsSplitBy);
            testCases.add(data);
        }

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