extent-framework / extentreports-testng-adapter

TestNG Adapter for Extent Framework
http://extentreports.com/docs/versions/4/java/testng.html
Apache License 2.0
50 stars 14 forks source link

Request for a way to extend the adapter #13

Closed QAthulhu closed 4 years ago

QAthulhu commented 4 years ago

It would be nice to be able to extend the testNG adapter to add screenshot on failure and logging of test steps. Out of the box it looks great, but only shows a Pass and Fail for each method.

anshooarora commented 4 years ago

@QAthulhu You should be able to use your custom @AfterMethod to get access to the test and attach screenshots to it. Example:

@AfterMethod
public synchronized void afterMethod(ITestResult result) throws IOException {
    switch (result.getStatus()) {
    case ITestResult.FAILURE:
        ExtentTestManager.getTest(result).fail("ITestResult.FAILURE, event afterMethod",
                MediaEntityBuilder.createScreenCaptureFromPath(getImagePath()).build());
        break;
    case ITestResult.SKIP:
        ExtentTestManager.getTest(result).skip("ITestResult.SKIP, event afterMethod");
        break;
    default:
        break;
    }
}
QAthulhu commented 4 years ago

But won't I have to copy-paste this code into every @AfterMethod I use? Is there a way to set it somewhere else?

anshooarora commented 4 years ago

Absolutely not, only in your base/parent class.