I tried searching for relevant information for this question but wasn't able to find. Here is the question: There are 2 sheets in same excel. I want to print the data from both sheets using TestNG DataProvider only once in the same class.
Sheet1:
UserName Password
administrator1 password1
administrator2 password2
Sheet2:
FirstName LastName
abc def
pqr xyz
String path=<filePath>;
String sheetName;
@Test (dataProvider="loginInfo")
public void loginVerification(String username, String password) throws InterruptedException
{
sheetName="Sheet1";
System.out.println("Username:"+username+" "+"Password:"+password);
System.out.println("************");
}
@Test (dataProvider="loginInfo")
public void userNames(String firstName, String lastName)
{
sheetName="sheet2";
System.out.println("FirstName:"+firstName+" LastName:"+lastName);
System.out.println("*******");
}
@DataProvider(name="loginInfo")
public Object[][] userFormData() throws BiffException, IOException
{
Object[][] data = testData(path, sheetName);
return data;
}
public Object[][] testData(String path, String sheetName) throws BiffException, IOException
{
<code to read excel data>
}
}
return inputData;
}
When I run the code, it just skips execution with Null Pointer exception. If I declare sheetName at the beginning as I did for filePath, only data from 1st sheet is picked. Any help on how to proceed here is appreciated.!