QAMonk
QAMonk

Reputation: 11

Getting DataProvider Mismatch error although the parameters and return types all looking to be correct

I am getting the below DataProvide Mismatch error while executing this testng test. There are few solutions available here to this type of issues, but this one seems everything is correct but still unable to get rid of the error. How can I solve this?

Log:

org.testng.internal.reflect.MethodMatcherException: [public void com.shipper.qa.test.LoginTest.LoginPageTest(java.lang.String,java.lang.String) throws java.lang.InterruptedException,java.io.IOException] 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 Method: LoginPageTest([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}])

My Test Class

public class LoginTest extends TestBase{

LoginPage loginpage;

public LoginTest() throws IOException{
super();
}

@BeforeMethod
public void setup() throws IOException {
initialisation();
loginpage = new LoginPage();
}

@DataProvider(name = "loginTestData")
public static Object getLoginData() throws InvalidFormatException {
Object data [][] = ExcelUtils.getExcelData("login");
return data;
}

@Test(dataProvider = "loginTestData")
public void LoginPageTest(String userName, String passWord) throws InterruptedException, IOException {
loginpage.login(userName, passWord);
Thread.sleep(5);
String title = driver.getTitle();
System.out.println("Title is:" +title);
}

Excel Reader Class

public class ExcelUtils {
    
public static String TESTDATA_SHEET_PATH = "Data/MasterDataSheet.xlsx"; 
static Workbook wb;
static org.apache.poi.ss.usermodel.Sheet sheet;

public static Object [][] getExcelData(String worksheet) throws InvalidFormatException{


FileInputStream file = null;
try{

file = new FileInputStream(TESTDATA_SHEET_PATH);
}catch(FileNotFoundException e) {
e.printStackTrace();
}

try {
wb = WorkbookFactory.create(file);
}catch(IOException e) {
e.printStackTrace();
}

sheet = wb.getSheet(worksheet);

Object [][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];

for(int i=0; i<sheet.getLastRowNum(); i++) {

for(int k=0; k<sheet.getRow(0).getLastCellNum(); k++) {

data[i][k] = sheet.getRow(i+1).getCell(k);
//data[i][k] = sheet.getRow(i+1).getCell(k).toString();


}

} return data;

}

Upvotes: 0

Views: 762

Answers (1)

QAMonk
QAMonk

Reputation: 11

Thanks folks, I got the issue here and fixed it!!

Basically I missed to add [][] in Object return type here in DataProvider class.

@DataProvider(name = "loginTestData")
public static Object getLoginData() throws InvalidFormatException {
Object data [][] = ExcelUtils.getExcelData("login");
return data;
}

Upvotes: 1

Related Questions