Search code examples
selenium-webdrivertestng-dataproviderextentreportsselenium-extent-reportreportng

Customization of Extent Reports using TestNG (Java)


Need help to display parameters (against each test) in extent report. Parameters like the values picked from @dataprovider (URL, other details to fill the form) in Testng framework and also not getting failed stack trace against failed results

Reportng provides beautiful report with all required details without any customization, but can't get those details in extentreports.


Solution

  • It is possible in ExtentReport with Customized format:

    Sample Example:

    As according to your data provider is getting details, you can add it in Extent Report:

    @Test(dataProvider = "getTestData", )
    public void createAccount(String caseNo, String targetGroupName, String expectedResult) 
    {
    
        extentTest= extentReport.createTest("Test"); 
    
        String testResult = "Case No: " + caseNo + " &nbsp; <br /> &nbsp; Group Name: " + targetGroupName;
        extentTest.info(MarkupHelper.createLabel(testResult, ExtentColor.BLUE));
        System.out.println(testResult);
    }
    

    And this is how its looks like:

    So like wise you can add customized String as according to preference.

    Add Failure Details or Error Stack Trace in Reports:

    To add Test Failure description in Report, After every test method, Annotation @AfterMethod is call on which ITestResult through the result of test, if test got fail it can retrieve error stack information.

    @AfterMethod
    public void testStatus(ITestResult result) throws Exception {
    
        if (result.getStatus() == ITestResult.FAILURE) {
    
            testResult = "Test Fail :" + result.getName();
            extentTest.fail(MarkupHelper.createLabel(testResult, failColor));
            System.out.println(testResult);
    
            testResult = "Details of Fail Testcase:" + result.getThrowable();
            extentTest.info(testResult);
    
            extentReport.flush();
        }
    }