数据提供程序不匹配错误



我正在为数据提供程序使用以下代码,但它不起作用。请帮助我如何解决数据提供程序不匹配问题。这里提到了所有方法读取XLS、测试、数据提供程序的完整细节。

@DataProvider
    public Object[][] getgbTestData(){
        Object data[][] = testutil.getTestData(sheetName);
        return data;
    }
    @Test(dataProvider="getgbTestData")
    public void addnewuser(String fname,String lname,String email,String pass,String conpass) throws IOException{
        newuser.newregistration1(fname, lname, email, pass, conpass);
        }
**method:**
public Personaldetails newregistration1(String fsname,String lsname,String email1,String pass1,String conpass1) throws IOException {
        Account.click();
        Registerlink.click();
        Firstname.sendKeys(fsname);
        Lastname.sendKeys(lsname);
        useremail.sendKeys(email1);
        password.sendKeys(pass1);
        confirmpassword.sendKeys(conpass1);
        submit.click();
        //return person;
        return new Personaldetails();
    }

使用以下方法从Excel读取数据

public static Object[][] getTestData(String sheetName) {
    FileInputStream file = null;
    try {
        file = new FileInputStream(TESTDATA_SHEET_PATH);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        book = WorkbookFactory.create(file);
    } catch (InvalidFormatException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    sheet = book.getSheet(sheetName);
    Object[][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];
    // System.out.println(sheet.getLastRowNum() + "--------" +
    // sheet.getRow(0).getLastCellNum());
    for (int i = 0; i < sheet.getLastRowNum(); i++) {
        for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++) {
            data[i][k] = sheet.getRow(i + 1).getCell(k).toString();
            // System.out.println(data[i][k]);
        }
    }
    return data;
}

看起来测试需要 5 个参数,但您的数据提供程序方法getTestData传递更少/更多的参数。

您传递了错误数量的参数。该方法addnewuser()需要 5 个参数,但只接收一个参数。您可以在错误消息的最后一行看到它

参数: [(java.lang.String(fname]

如果要传递不同数量的参数,可以使用String[]而不是单个参数。如果您每次期望 5 个参数,请检查datagetTestData()中保存的内容

最新更新