如何显示TestNg"dependsOnMethods"?作为测试结果列中的单独节点范围HTML报告 [英] How to display the TestNg "dependsOnMethods" as separate node in the test result column Extent HTML report

查看:202
本文介绍了如何显示TestNg"dependsOnMethods"?作为测试结果列中的单独节点范围HTML报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I am running the TestNg,java, extent reports 3.1.2, selenium tests in Maven project. I have a test- TEST1 which calls TEST2 internally(using TestNg- dependendsOnMethods).After the run, when I check the Extent Report, it shows the results of TEST1 & TEST2 separately as 2 tests rather 1 test i.e.TEST1 with 2 child tests i.e. TEST1 & TEST2. This is the link to the current situation : https://imgur.com/ZnBNqzo

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

I expect the Extent HTML report to show- TEST1 only(in the TESTS column) and when I click on the TEST1, report should show the status & screenshot of TEST1 and TEST2 in the Test steps results column (it is in the right hand side when one clicks on the respective Test). This is the link to the ToBe situation : 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();
    }
}

推荐答案

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

Finally, solved my problem by implementing 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相同.

**did the same for onTestFailure, onTestSkipped.

这篇关于如何显示TestNg"dependsOnMethods"?作为测试结果列中的单独节点范围HTML报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆