如何显示TestNG的“dependsOnMethods”作为单独的节点测试结果列程度HTML报告(

2019-10-29 07:11发布

如何显示TestNG的“dependsOnMethods”作为测试结果列程度HTML报告单独的节点”

我运行TestNG的,JAVA,程度报告3.1.2,在Maven项目的Selenium测试。 我有一个测试 - TEST1其内部调用TEST2(使用TestNg- dependendsOnMethods)。后来看,当我检查的范围内报告,它显示的TEST1和TEST2分别为2次测试的结果,而1测试ieTEST1有2次测试,即测试1 &TEST2。 这是链接到当前的形势: https://imgur.com/ZnBNqzo

我期望的程度HTML报告显示─TEST1只(以测试列),当我点击TEST1,报告应显示在测试步骤结果列中的状态和TEST1和TEST2的截图(它是在右手边当一个点击相应的试验)。 这是链接到TOBE情况: https://imgur.com/NKMxoIB

// TEST1

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

// TEST2

   @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();
    }
}

Answer 1:

最后,通过实施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。



文章来源: How to display the TestNg “dependsOnMethods” as separate node in the test result column Extent HTML report