0

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.

foursyth
  • 527
  • 1
  • 3
  • 10
viki
  • 165
  • 2
  • 11

1 Answers1

3

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();
    }
}
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
  • Thanks Ishita, it worked, do you know how we can get Assertion failure message and stack trace (preferably expand collapse control against each step/test) as we get in ReportNG ? and also if you have any code to add screenshot for the failed tests pls ? – viki Aug 11 '18 at 06:12
  • Glad to help you. Please Accept the answer by clicking on the hollow tick mark beside my answer. – Ishita Shah Aug 11 '18 at 06:21
  • Yes everything is possible. Please generate separate questions for same, Also do some googling you will find something for your trial code and also you can found on Stack overflow. And you can raise question if you get failure. – Ishita Shah Aug 11 '18 at 06:22
  • yeah, definitely I will accept the answer, just one part is left regarding stack trace or assertion error message to display on report. I googled about screenshot to be added in report, but somehow nothing worked yet, I will try that on my own, just let me know about error message display – viki Aug 11 '18 at 06:24
  • Update your question with this details, And I will add solution in my answer. – Ishita Shah Aug 11 '18 at 06:30
  • Question is already there, if you read the following line - "and also not getting failed stack trace against failed results" – viki Aug 11 '18 at 06:33
  • A good way to add failure is just test.fail(result.getThrowable()); by passing the exception directly as it will be displayed in the correct format also – Karthik Aug 11 '18 at 16:37