0

I'm in the process of learning keyword driven framework with TestNG and ReportNG integration. My requirements are

  1. Triggering the automation using TestNG
  2. Read the keywords and values from the excel sheet (one sheet has keywords and actions. The other sheet has xpath for each object)
  3. Drive the automation using keyword driven approach
  4. 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 :

enter image description here

Excel Sheet2:

This can be moved to properties file but as of now I'm reading from excel file

enter image description here

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?

  1. 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?

  2. 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.

4

2 回答 2

0

我认为问题在于用于存储测试步骤的数组。您使用的是二维数组,因此测试用例和测试步骤之间没有关联。

我会改用 Map 并将其转换为数据提供者的二维数组。

例子:

Map<String, String> map = new HashMap<String, String>();
map.put("TS1", "step1");
map.put("TS2", "step2");
object[0][1] = map;
于 2019-06-10T01:14:35.463 回答
-1

首先,您需要了解什么是您在实现中使用的数据提供者... http://toolsqa.com/selenium-webdriver/testng-data-provider-excel/ > 这个网站可以帮助您...

数据提供者发送参数以执行您的测试……每一行将是执行每个测试的参数……换句话说……

第一行将是您第一次测试的参数...第二个原始将是您第二次测试的参数...等等...

我认为您错误地使用了 dataprovider... dataprovider 用于为测试提供数据...例如用户名或密码...

对于元素的位置,还有其他做法,如在自己的测试代码中......在其他功能或PAGEOBJECTS中......

所以,简短的回答是......请检查什么是数据提供者......

此致

于 2016-09-12T08:18:08.533 回答