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
CodePudding user response:
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}
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);
}
CodePudding user response:
There are few issues in the code.
- Your single test case expects url, username and password. So it should be a single array
{"https://google.com","username","mypassword"}
- 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.