传递数据我开始使用Eclipse和TestNG学习Selenium2(webdriver的)。我有一个关于DataProvider的问题。例如,我有一个登录页面,其中包含用户,密码和登录按钮。我在TestNG中写了一个测试。我已经在另一个类中使用了UI对象(具有单独的类)和实际测试的pageobject。的DataProvider TestNG中从Excel
这里glogin是一个类和登录在这里找到元素和发送键完成的功能与这被称为在另一个类中GTEST(这是主要的测试),其具有TestNG的注释。
我访问将于值主脚本类。
我有以下excel表
user pass
John Smith
Carson Black
Carla ck23
test test4
当我使用数据提供器,并从Excel工作表作为阵列获取数据,并用它在试验则显示以下错误:
org.testng.TestNGException:
The data provider is trying to pass 4 parameters but the method plus.gmail#glogin takes 2
at org.testng.internal.Invoker.injectParameters(Invoker.java:1337)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1225)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
任何帮助真的很感激。
这里是方法的代码与数据提供器和注释
@DataProvider(name="test")
public Object[][] createdata1()throws Exception
{
Object[][] retobj = getexcel();
return retobj;
}
private String[][] getexcel() throws Exception
{
// TODO Auto-generated method stub
String[][] tabarray = null;
try {
Workbook wb1 = Workbook.getWorkbook(new
File("F:/testdata.xls"));
Sheet sheet = wb1.getSheet("userlogin");
Cell tablestart = sheet.findCell("login");
int startrow = tablestart.getRow();
int startcol = tablestart.getColumn();
Cell tableend = sheet.findCell("login",startcol+1,startrow+1,
100, 64000, false);
int endrow = tableend.getRow();
int endcol = tableend.getColumn();
System.out.println("startRow="+startrow+", endRow="+endrow+",
" + "startCol="+startcol+", endCol="+endcol);
tabarray = new String[endrow - startrow + 1][endcol -
startcol + 1];
int ci = 0;
for(int i = startrow +1 ;i<endrow;i++,ci++)
{
int cj = 0;
for(int j = startcol + 1;j<endcol;j++,cj++)
{
tabarray[ci][cj] = sheet.getCell(j,
i).getContents();
System.out.println(tabarray[ci][cj]);
}
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tabarray;
}
test(Dataprovider = "test")
public void glogins(String user, String pass)
{
glogin log1 = new glogin(driver);
log1.login(user,pass);
}
当我执行的测试中,我从Excel接收到的数据作为
john
smith
carson
Black
carla
ck23
test
test4
作为输出
你能给与的DataProvider(这样一个阅读批注的方法的代码excel)?我猜这个问题肯定会在那里。 –
您应该检查是否tabarray [X]。长度为4对任何在您的Excel行。 –