I'm in the process of learning keyword driven framework with TestNG and ReportNG integration. My requirements are
- Triggering the automation using TestNG
- Read the keywords and values from the excel sheet (one sheet has keywords and actions. The other sheet has xpath for each object)
- Drive the automation using keyword driven approach
- Generate report using ReportNG
TestNG File:
<suite name="Test Results" parallel="false" thread-count="3">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>
<test name="Automation Test">
<classes>
<class name="TestSuite1">
</class>
</classes>
</test>
Excel Sheet1 :
Excel Sheet2:
This can be moved to properties file but as of now I'm reading from excel file
TestSuite file:
@Test(dataProvider="hybridData")
public void testLandingScreen(String testcaseName,String testStep,String keyword,String execute,String objectName, String value) throws Exception {
excelUtils.processXls(testcaseName, testStep, keyword, execute, objectName, value);
}
}
@DataProvider(name="hybridData")
public Object[][] getDataFromDataprovider() throws IOException {
Object[][] object = null;
ReadExcelFile file = new ReadExcelFile();
//Read keyword sheet
Sheet sheet = file.readExcel(BaseData.XLS_PATH,"TestData.xlsx" , "TSData");
//Find number of rows in excel file
int rowCount = sheet.getLastRowNum()-sheet.getFirstRowNum();
object = new Object[rowCount][6];
for (int i = 0; i < rowCount; i++) {
//Loop over all the rows
Row row = sheet.getRow(i+1);
//Create a loop to print cell values in a row
for (int j = 0; j < row.getLastCellNum(); j++) {
//Print excel data in console
object[i][j] = row.getCell(j).toString();
//object[i][j] = row.getCell(j);
}
}
return object;
}
Can anyone help me in clarifying the below questions?
When I run this test integrated with ReportNG, each excel row is considered as single test case and the report is showing the total number of row as test case count.
Any suggestion on how to read the excel sheet based on TC name and generate ReportNG report based on that?
If the answer for the above question is yes, then how can I call single @Test method to generate more than one test case?
Any help on this is highly appreciated. Thanks.