0
0
Selenium Javatesting~10 mins

Extent Reports setup in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sets up Extent Reports in a Selenium Java test. It verifies that the report file is created and logs test steps correctly.

Test Code - JUnit 5
Selenium Java
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;

public class ExtentReportSetupTest {
    private static ExtentReports extent;
    private static ExtentTest test;
    private static final String reportPath = System.getProperty("user.dir") + "/test-output/ExtentReport.html";

    @BeforeAll
    public static void setup() {
        ExtentSparkReporter spark = new ExtentSparkReporter(reportPath);
        extent = new ExtentReports();
        extent.attachReporter(spark);
        test = extent.createTest("Extent Report Setup Test");
        test.info("Extent Report initialized");
    }

    @Test
    public void sampleTest() {
        test.info("Starting sample test");
        assertTrue(true, "Sample assertion always true");
        test.pass("Sample test passed");
    }

    @Test
    public void reportFileExists() {
        extent.flush();
        File reportFile = new File(reportPath);
        assertTrue(reportFile.exists(), "Extent report file should exist after flush");
        test.info("Verified report file exists");
    }

    @AfterAll
    public static void tearDown() {
        extent.flush();
    }
}
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts - JUnit initializes test class and calls @BeforeAll setup methodExtentSparkReporter created with path 'test-output/ExtentReport.html'. ExtentReports instance attached to reporter.-PASS
2ExtentTest instance created and logs info 'Extent Report initialized'Test named 'Extent Report Setup Test' ready to log steps.-PASS
3JUnit runs sampleTest methodTest logs info 'Starting sample test'.assertTrue(true) verifies condition is truePASS
4Test logs pass status 'Sample test passed'Test step recorded in ExtentTest instance.-PASS
5JUnit runs reportFileExists methodChecks if report file exists at 'test-output/ExtentReport.html'assertTrue(reportFile.exists()) verifies report file presencePASS
6Test logs info 'Verified report file exists'Log added to ExtentTest instance.-PASS
7JUnit calls @AfterAll tearDown methodExtentReports flush() writes all logs to report file.-PASS
Failure Scenario
Failing Condition: Extent report file is not created or not found after flush
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the Extent Report?
AThat the browser opens correctly
BThat the report file is created and test steps are logged
CThat the web page loads without errors
DThat the test fails when assertion is false
Key Result
Always call ExtentReports.flush() after tests to ensure the report file is properly written and saved.