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

我只是一个虾纸丫 提交于 2019-12-13 04:25:40

问题


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

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

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
    }

//Extent Reporting

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

回答1:


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

**did the same for onTestFailure, onTestSkipped.



来源:https://stackoverflow.com/questions/57510722/how-to-display-the-testng-dependsonmethods-as-separate-node-in-the-test-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!