DATAPROVIDER实施面临的问题

时间:2019-02-13 09:16:36

标签: selenium appium

当我尝试在Excel工作表中实现DATAPROVIDER并想在appium中执行程序但遇到问题时,我面临以下问题。

以----:

出现错误
Data provider mismatch
Method: test([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=4, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=5, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=6, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=7, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=8, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=9, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=10, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=11, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=12, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=13, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=14, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=15, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=16, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=17, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=18, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=19, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=20, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=21, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=22, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=23, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.String) LeadStatus]
    at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)
    at org.testng.internal.Parameters.injectParameters(Parameters.java:796)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:982)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================

请帮助我。

enter code here

2 个答案:

答案 0 :(得分:0)

如果要传递所有参数,则对数据提供者使用以下代码:

@DataProvider(name = "ProcurementLead") 
public Object[][] Procurement() throws IOException { 
return new Object[][] {
// first set of values
{"LeadStatus","CustomerName","MobileNO","EmailID","CustomerAddress","pincode","City", "ManufacturedYear", "ManufacturedMonth", "Colour", "KMs", "Owner", "LeadSource", "Make", "ModelAndVariant", "CustomerExpct", "BuyingQuote","RegdYear","RegdMonth","RegdNo", "Insurance", "RefSource", "ExecInfo", "StockVinNo"},

// second set of values
{"LeadStatus","CustomerName","MobileNO","EmailID","CustomerAddress","pincode","City", "ManufacturedYear", "ManufacturedMonth", "Colour", "KMs", "Owner", "LeadSource", "Make", "ModelAndVariant", "CustomerExpct", "BuyingQuote","RegdYear","RegdMonth","RegdNo", "Insurance", "RefSource", "ExecInfo", "StockVinNo"}

}
}

如果要添加更多数据集,可以添加它。

还观察到您使用了显式等待以及Thread.sleep()。 不建议使用Thread.sleep()。 相反,您可以使用“隐式等待”。

下一次在发布问题之前,请阅读stackoverflow问题发布准则。这样您的问题就易于阅读。

答案 1 :(得分:0)

当您从外部文件中获取的数据与测试中提到的数据类型不匹配时,就会发生数据提供者不匹配的情况。

为了解决此问题,您可以使用以下方法:

通过以下方法使用数据提供程序:     @Test(dataProvider =“ login”,dataProviderClass = DataGenerators.class)     public void tc_001_login_functionality(String uname,String pass,String ExpectedString)引发异常

现在只需注释此方法中的每个代码,并仅打印要获取的值,如下所示:

System.out.println( uname + pass +  expectedText);

现在运行该方法,您将能够找出哪个参数与您的外部文件不同。