Reputation: 2697
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
Upvotes: 0
Views: 3927
Reputation: 2922
I am able to reproduce the issue. The below error...
Data provider mismatch
Method: mytest([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, ype=java.lang.reflect.Method,
declaredAnnotations=[]}, Parameter{index=4, type=org.testng.ITestContext, declaredAnnotations=[]}])
Arguments:
[([Ljava.lang.Object;) [https://google.com],
([Ljava.lang.Object;) [username],
([Ljava.lang.Object;) [mypassword]]
...is saying "The method requires {String, String, String}
input but you are passing {Object, Object, Object}
Working code:
@Test(priority = 1, alwaysRun = true, dataProvider = "SigninLink")
public void mytest(Object url, Object username, Object password, Method method, ITestContext ctx)
throws InterruptedException, IOException {
System.out.println(Array.get(url, 0) + "-" + Array.get(username, 0) + "-" + Array.get(password, 0));
}
Output:
https://google.com-username-mypassword
Instead of that simply you can pass the data like below.
@DataProvider(name = "SigninLink")
public Object[][] getData() {
return new Object[][] { { "https://google.com", "username", "mypassword" } };
}
@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);
}
Upvotes: 0
Reputation: 4935
There are few issues in the code.
{"https://google.com","username","mypassword"}
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.
Upvotes: 1