如何从excel工作表中提供的测试数据打印日志,以显示在数据块报告中我正在使用testng和maven的混合框架

6mzjoqzu  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(227)

在keyword.java类中,我包含以下内容:

public void logs(String data) throws Throwable
{

    extent = new ExtentReports();
    test = extent.createTest("SomeName");
    htmlReporter = new ExtentHtmlReporter("Test.html");//Constructor takes a path
    extent.attachReporter(htmlReporter);
    test.info( data);

在executeleadtest.java中,我有以下代码:

@Test
    public void salesBooking() throws Throwable {
    System.out.println("Start Sales Booking function...........");

    key.logs(data);

    SalesBooking exetest = new SalesBooking();

    String filePath = "..//FarmERPAutomation//src//test//java//datafile//FarmERPTestCase - 
    Sales Booking.xlsx";
    String sheetName = "Sales Booking";

    exetest.readExcelfile(filePath, sheetName);

    System.out.println("End Sales Booking function.............");

}

public void readExcelfile(String filePath, String sheetName) throws Throwable {

    ArrayList a = new ArrayList();
    File src = new File(filePath);
    FileInputStream file = new FileInputStream(src);
    XSSFWorkbook b = new XSSFWorkbook(file);
    Sheet s = b.getSheet(sheetName);

    Iterator itr = s.iterator();

    while (itr.hasNext()) {
        Row rowitr = (Row) itr.next();
        Iterator cellitr = rowitr.cellIterator();

        while (cellitr.hasNext()) {
            Cell celldata = (Cell) cellitr.next();

            switch (celldata.getCellType()) {
            case Cell.CELL_TYPE_STRING:
                a.add(celldata.getStringCellValue());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                a.add(celldata.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                a.add(celldata.getBooleanCellValue());
                break;

            }// switch

        } // while
    } // while

    SalesBooking exetest = new SalesBooking();
    exetest.forloop(a);

    file.close();

}

public void forloop(ArrayList a) throws Throwable {
    Keywords key = new Keywords();
    SalesBooking exetest = new SalesBooking();

    for (int i = 0; i < a.size(); i++) {

        // openbrowser
        if (a.get(i).equals("openbrowser")) {
            String keyword = (String) a.get(i);
            String data = (String) a.get(i + 1);
            String objectname = (String) a.get(i + 2);
            String runmode = (String) a.get(i + 3);

            System.out.println(keyword);
            System.out.println(data);
            System.out.println(objectname);
            System.out.println(runmode);

            if (runmode.equals("yes")) {
                key.openbrowser();
            }
        }
        if (a.get(i).equals("logs")) {
            String keyword = (String) a.get(i);
            String data = (String) a.get(i + 1);
            String objectname = (String) a.get(i + 2);
            String runmode = (String) a.get(i + 3);

            System.out.println(keyword);
            System.out.println(data);
            System.out.println(objectname);
            System.out.println(runmode);

            if (runmode.equals("yes")) {
                key.logs(data);
            }
        }

尽管在excel工作表中获取了logs关键字,但为什么sales booking没有从关键字调用logs()方法并生成包含日志的范围报告?
如果这是一个错误的过程,请就如何在数据块报告中打印excel工作表中的日志提出建议。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题