数据提供程序不允许返回字符串 2D 数组



我用TestNG创建了一个Selenium框架。在此框架中,@Dataprovider包含一组代码,这些代码从 Excel 读取数据并将此值作为 2D 数组返回给@Test。

@DataProvider(name="excelParam")
public static String[][] loginData()
{
return Util.Excel.get("/LearningSelenium/creds.xls");
}
@Test(dataProvider = "excelParam")
public void loginTest(String username, String password) {
driver.findElement(By.name("uid")).sendKeys(username);
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.name("btnLogin")).click();
}

'get' 方法返回 String[][]。但是我收到错误,因为"数据提供程序必须返回对象[][]"。如果我将其更改为 Object[][],那么我的测试用例失败并出现以下错误:

org.testng.internal.reflect.MethodMatcherException: 
[public void ParameterTestExcel.loginTest(java.lang.String,java.lang.String)] has no parameters defined but was found to be using a data provider (either explicitly specified or inherited from class level annotation).
Data provider mismatch
Test ignored.
===============================================
Default Suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
===============================================
**
@DataProvider(name ="Testlogin")
public Object[][]  getData()
{
// here you can give data
return data;
}
**
your code like " public static String[][] loginData()
{
return Util.Excel.get("/LearningSelenium/creds.xls");
}
your return type is string but that should be Object[][]

相关内容

  • 没有找到相关文章

最新更新