如何在测试结果列 Extent HTML 报告中将 TestNg "dependsOnMethods" 作为单独的节点显示

How to display the TestNg "dependsOnMethods" as separate node in the test result column Extent HTML report

如何在测试结果列范围 HTML 报告中将 TestNg "dependsOnMethods" 作为单独的节点显示

我正在 运行宁 TestNg,java,范围报告 3.1.2,Maven 项目中的硒测试。我有一个内部调用 TEST2 的测试-TEST1(使用 TestNg-dependendsOnMethods)。在 运行 之后,当我检查范围报告时,它分别将 TEST1 和 TEST2 的结果显示为 2 个测试而不是 1 个测试,即 TEST1 与2 个子测试,即 TEST1 和 TEST2。这是link到目前的情况:https://imgur.com/ZnBNqzo

我希望 Extent HTML 报告仅显示 TEST1(在 TESTS 列中),当我单击 TEST1 时,报告应在测试步骤结果中显示 TEST1 和 TEST2 的状态和屏幕截图列(单击相应测试时它位于右侧)。这是 ToBe 的 link 情况:https://imgur.com/NKMxoIB

//测试1

@Test(dependsOnMethods = { "TEST2" })
    public void TEST1 () throws InterruptedException { 
    // selenium test java code
    }

//测试2

   @Test()
   public void TEST2 () throws InterruptedException { 
    // selenium test java code
    }

//范围报告

    public void onTestSuccess(ITestResult tr) {
    logger = extent.createTest(tr.getName());
    logger.log(Status.PASS, MarkupHelper.createLabel(tr.getName(), 
      ExtentColor.GREEN)); 
    System.out.println("TEST PASSED- Screenshot taken");

    try {
        captureScreen(tr.getName());            
        } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String screenshotPath = ".//"+tr.getName()+".png";      

    try {
        logger.pass("Screenshot is below:" + 
      logger.addScreenCaptureFromPath(screenshotPath));
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

最后,通过实现 ITestListener 解决了我的问题。

public static ArrayList<String> methodList = new ArrayList<String>();

@Override
public void onTestStart(ITestResult result) {   

      if ((chkAndAddArray(finalInstance))) {
        return;
    }   

    if (finalmethodname.equalsIgnoreCase(finalInstance.toString())) {
        parentTest= extent.createTest(finalmethodname);
    } else {
        parentTest= extent.createTest(finalInstance);
            }
        }

  boolean chkAndAddArray(String instance) {

    if (methodList.contains(instance)) {
        System.out.println(instance + " value is already present");
        return true;
    } else
        methodList.add(instance);
    System.out.println(instance + " value is not present & now, added");
    return false;
}





public void onTestSuccess(ITestResult tr) {

System.out.println("onTestSuccess");

    childTest = parentTest.createNode(tr.getName());
    childTest.log(Status.PASS, MarkupHelper.createLabel(tr.getName(),  
   xtentColor.GREEN));
        e1.printStackTrace();
    }       
childTest.pass("Screenshot is below:", 
        MediaEntityBuilder.createScreenCaptureFromPath(screenshotPath).build());
    } catch (IOException e1) {

        e1.printStackTrace();
        }
            }

** 对 onTestFailure、onTestSkipped 做了同样的事情。