【问题标题】:Type mismatch: cannot convert from DataProvider to Annotation类型不匹配:无法从 DataProvider 转换为 Annotation
【发布时间】:2017-12-31 10:54:39
【问题描述】:

我收到一个错误

'类型不匹配: 无法从 DataProvider 转换为 @DataProvider 的 Annotation 错误(@line 19)

任何帮助将不胜感激

package parameterization;

import org.testng.annotations.Test;

import org.testng.annotations.DataProvider;

public class DataProvider 
{
    //This test method declares that its data should be supplied by the Data Provider
        // "getdata" is the function name which is passing the data
           // Number of columns should match the number of input parameters
        @Test(dataProvider="getData")
        public void setData(String username, String password)
        {
            System.out.println("you have provided username as::"+username);
            System.out.println("you have provided password as::"+password);
        }

        @DataProvider(name="getData")
        public Object[][] getData()
        {
        //Rows - Number of times your test has to be repeated.
        //Columns - Number of parameters in test data.
        Object[][] data = new Object[3][2];

        // 1st row
        data[0][0] ="sampleuser1";
        data[0][1] = "abcdef";

        // 2nd row
        data[1][0] ="testuser2";
        data[1][1] = "zxcvb";

        // 3rd row
        data[2][0] ="guestuser3";
        data[2][1] = "pass123";

        return data;
        }   
}

谢谢。

【问题讨论】:

  • 奇怪的是,相同的代码对我来说效果很好。你用的是什么testng版本。
  • @MadisKangro 检查您的班级名称。它应该是“DataProvider”。

标签: java selenium testng dataprovider


【解决方案1】:

您的班级名称是DataProvider,它隐藏了您的导入import org.testng.annotations.DataProvider

与你认为稍后使用的错误一致,但实际上使用的是前者。

解决方案:重命名您的类或在注释中使用 FQN (@org.testng.annotations.DataProvider(name="getData"))。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 2016-03-13
    • 2014-02-12
    • 2014-04-16
    • 1970-01-01
    • 2015-11-18
    • 2014-04-07
    • 2011-12-27
    相关资源
    最近更新 更多