extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
224 stars 127 forks source link

ExtentSparkReport with TestNGCucumberRunner how to get test steps logged in test view with screenshots at step level #323

Open ghost opened 3 years ago

ghost commented 3 years ago

Current implementation: image

Desired version: image

below is my TestNGRunner class: @CucumberOptions(features = "src/main/resources/features", glue = {"stepDefinitions"}, //tags = {"~@Ignore"}, //plugin = {"com.cucumber.listener.ExtentCucumberFormatter:"}, plugin = {"pretty","json:target/cucumber-reports/CucumberTestReport.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"},monochrome = true)

public class TestRunner extends BaseTest{ static LoginPage loginPage = new LoginPage(); private TestNGCucumberRunner testNGCucumberRunner; public static RemoteWebDriver connection; public ExtentTest test;

@BeforeClass(alwaysRun = true)
public void setUpClass(){
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}

// @SuppressWarnings("unused") @Test(groups = "cucumber", description = "Runs Cucumber Scenarios", dataProvider = "scenarios") public void runScenario(PickleWrapper pickleWrapper, FeatureWrapper featureWrapper) throws IOException {

// ExtentTest test = extent.createTest(pickleWrapper.getPickle().getName()); test = extent.createTest(pickleWrapper.getPickle().getName()); test.assignCategory(pickleWrapper.getPickle().getName()); test.createNode("Given", "This is node step"); test.log(test.getStatus(), "Execution Result"); testNGCucumberRunner.runScenario(pickleWrapper.getPickle());

    File srcFile = ((TakesScreenshot) DriverUtils.getDriver()).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(srcFile, new File("./test-output/screenshots/screen.png"));
    String screenshotPath = System.getProperty("user.dir")+"/test-output/screenshots/screen.png";
    test.addScreenCaptureFromPath(screenshotPath);

    extent.flush();
}

@DataProvider
public Object[][] scenarios() {
    if (testNGCucumberRunner == null) {
        return new Object[0][0];
    }
    return testNGCucumberRunner.provideScenarios();
}

@AfterClass(alwaysRun = true)
public void tearDownClass() {
    if (testNGCucumberRunner == null) {
        return;
    }
    testNGCucumberRunner.finish();
}

}

Below is BaseTest class:

@BeforeTest(description = "LYFT login") public static void setUp(String uaturl, String uatusername, String uatpassword, String devurl, String devusername, String devpassword) throws IOException { //report for attachment extent = new ExtentReports(); String reportPath = System.getProperty("user.dir")+"/target/Report/HTMLExecutionReport2.html"; ExtentSparkReporter reporter = new ExtentSparkReporter(reportPath); // reporter.config().setReportName("Avent Report"); // reporter.config().setDocumentTitle("Execution Report"); String reportConfigPath = System.getProperty("user.dir")+"/src/test/resources/extent-config.xml"; reporter.loadXMLConfig(reportConfigPath); extent.attachReporter(reporter);

    // part of the method is not mentioned here which is not relevant for report
}
ghost commented 3 years ago

Just to mention, this is not an issue but rather a question to get some help.

ghost commented 3 years ago

tagging anshoo and grasshopper to notify about the question. @anshooarora and @grasshopper7