Log custom text to Cucumber JVM or Extent Reports

4.8k Views Asked by At

Please guide me in logging custom text which are there inside a method into Cucumber JVM (Masterthought) or Extent Reports.

I am using Cucumber Junit BDD Framework and have the below dependencies in my POM file -

<!-- Cucumber JVM Report -->
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>5.1.0</version>
    </dependency>

    <!-- Extent Report -->
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.2.1</version>
    </dependency>

And my Runner file is as below -

@CucumberOptions(
    tags = {"@SANITY,@REGRESSION,@E2E"},
    features = "src/test/resources/cta-features/features/",
    plugin = {
            "json:target/cucumber-reports/cucumber.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:",
            "pretty"
    },
    glue = {
            "e2e.steps",
            "e2e.hooks"
    })

@RunWith(Cucumber.class)
public class TestRunner {

@BeforeClass
public static void init() throws Exception {
    
}

@AfterClass
public static void generateReport() throws Exception {
    File reportOutputDirectory = new File("target");
    List<String> jsonFiles = new ArrayList<>();
    jsonFiles.add("target/cucumber-reports/cucumber.json");


    String buildNumber = "1";
    String projectName = "Project";


    Configuration configuration = new Configuration(reportOutputDirectory, projectName);
    // optional configuration - check javadoc for details
    configuration.addPresentationModes(PresentationMode.RUN_WITH_JENKINS);
    // do not make scenario failed when step has status SKIPPED
    configuration.setNotFailingStatuses(Collections.singleton(Status.SKIPPED));
    configuration.setBuildNumber(buildNumber);
    // addidtional metadata presented on main page
    configuration.addClassifications("Platform", "Windows");
    configuration.addClassifications("Browser", "Chrome");
    configuration.addClassifications("Branch", "release/1.0");


    ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
    Reportable result = reportBuilder.generateReports();
    // and here validate 'result' to decide what to do if report has failed
}

I am able to successfully generate report in both master thought and Extent which will contain Feature level statements and Step Level statements (I have used scenario.write for this). But my client wants one more level deeper where he can get info as to which link or button was clicked etc which i am currently publishing to my console using Log4j Example :

Log.info("Random Button or Link was clicked and Operation is successful")

My clients wants this to be integrated into the report (In Either Masterthought or Extent). Is there a way to do this ?

1

There are 1 best solutions below

0
On

Extent cucumber adapter provides addtestlog to log additional steps .

Please check below example -

ExtentCucumberAdapter.addAddTestStepLog(BTN.getText());

As per your Pom.xml file you are using adapter 4 if you cannot find method try to switch into cucumber adapter 6 and other essential dependency of cucumber 6. That will surely help you :)