javaseleniumselenium-webdrivertestngtestng-dataprovider

Testng data provider Getting error "Data provider mismatch"


Here I am assigning data

public static Object[][][] SiteUrlForSignin = {
    {{"https://google.com"},{"username"},{"mypassword"}}
};

Here is my test class

public class SignInTest{

    @DataProvider(name = "SigninLink")
    public Object[][] getData() {
        Object[][][] data = SiteConfig.SiteUrlForSignin;
        return data;
    }    

    @Test(priority = 1, alwaysRun = true, dataProvider = "SigninLink")
    public void mytest(String url,String username,String password,Method method,ITestContext ctx) throws InterruptedException, IOException {

        System.out.println(url+"-"+username+"-"+password);
    }
}

Getting following error

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

I am not sure where I missed


Solution

  • There are few issues in the code.

    1. Your single test case expects url, username and password. So it should be a single array {"https://google.com","username","mypassword"}
    2. Also data provider expected 2-d array, but your SiteUrlForSignin is a 3-d array. Convert it as:
    public static Object[][] SiteUrlForSignin = {{"https://google.com","username","mypassword"}};
    

    Note: According to the documentation, you cannot inject Method into a method annotated with @Test. It is applicable only to @BeforeMethod, @AfterMethod and @DataProvider, But it is possible now :-)

    Not sure if it is a bug or if the documentation is not updated.