I have an excel which contains 4 columns with N rows. Let us say Col1, Col2, Col3, Col4 are the headers. Now I have a java class and there are 3 methods inside it.
public class test(){
@Test(Dataprovider="test")
public void mone(String firstval) //firstval will get all the values from Col1 { system.out.println(firstval)}
@Test(Dataprovider="test")
public void mtwo(String secondval, String thirdval, String fourthval) //secondval, thirdval, fourthval will get all the values from Col2, Col3, Col4 { system.out.println(secondval); system.out.println(thirdval); system.out.println(fourthval);}
@DataProvider(name="test")
public Object[][] getData() {
String sheetName = "headercomptests";
int rows = excel.getRowCount(sheetName);
int cols = excel.getColumnCount(sheetName);
Object[][] data = new Object[rows - 1][cols];
for (int rowNum = 2; rowNum <= rows; rowNum++) {
for (int colNum = 0; colNum < cols; colNum++) {
data[rowNum - 2][colNum] = excel.getCellData(sheetName, colNum, rowNum); }
} return data; } //end of dataprovider class
How to pass excel column values into different test methods of a class?
Added Edits:
All the columns are in the same worksheet, so if I take two data providers - each one will be starting from the first column. For me, the first method takes values from the 1st column, the second method should take values from Columns 2, 3, 4. So since the excel worksheet is one, data providers will always look from the first.
Added Edits - 10th July. I have tried as you have mentioned, the dataprovider returns the value but the testmethod says throws an error as "Dataprovider mismatch" as it has 5 cols in excel but only one agrument is passed.
mone
has only one argument and your dataprovider returns 2D object array with 5 values that's the reason exception is thrown. Please be clear what's your required output and post it here