Data provider mismatch in Selenium with TestNG

前端 未结 2 394
半阙折子戏
半阙折子戏 2021-01-25 05:48

I am writing the below code in selenium and below error is showing, please let me know where is the issue.

import org.testng.annotations.DataProvider; import org.testng.

2条回答
  •  孤独总比滥情好
    2021-01-25 06:29

    The only problem I see is this, You are reading from excel so may be all the values are coming in String, unless you are converting that to Integer. However, in your test you expect third argument age to be Integer

    Changing type to String should resolve the issue

    @Test(dataProvider = "newdata")
    public void testData(String username, String password, String age) {
            System.out.println(username + " - " + password + " - " + age);
    }
    

    The following code would raise the same error.

    @DataProvider(name = "newdata")
    public static Object[][] getData() {
        return new Object[][]{
                {"20"},
                {"30"}
        };
    }
    
    @Test(dataProvider = "newdata")
    public void testData(Integer age) {
    
        System.out.println(age);
    
    }
    

提交回复
热议问题