Bird
Raised Fist0
Selenium Javatesting~15 mins

Extent Reports setup in Selenium Java - Deep Dive

Choose your learning style10 modes available
Overview - Extent Reports setup
What is it?
Extent Reports is a tool that helps testers create clear and attractive reports for automated tests. It collects test results and shows them in a web page with colors and details. Setting it up means adding it to your Selenium Java project so you can see which tests passed or failed easily.
Why it matters
Without Extent Reports, test results are often just plain text or hard-to-read logs. This makes it difficult to understand what happened during testing, especially for teams or managers. Extent Reports solves this by giving a visual summary that saves time and reduces confusion.
Where it fits
Before setting up Extent Reports, you should know basic Selenium WebDriver and Java programming. After setup, you can learn how to customize reports, add screenshots, and integrate with test frameworks like TestNG or JUnit.
Mental Model
Core Idea
Extent Reports transforms raw test results into easy-to-understand, colorful web reports that show test status and details.
Think of it like...
It's like turning a messy notebook of test notes into a neat, colorful presentation slide deck that everyone can quickly understand.
┌───────────────────────────────┐
│       Test Execution           │
│  (Selenium Java Tests Run)    │
└──────────────┬────────────────┘
               │
               ▼
┌───────────────────────────────┐
│      Extent Reports Setup      │
│  (Initialize, Configure, Log) │
└──────────────┬────────────────┘
               │
               ▼
┌───────────────────────────────┐
│      HTML Report Generated     │
│  (Pass/Fail, Details, Colors)  │
└───────────────────────────────┘
Build-Up - 7 Steps
1
FoundationAdd Extent Reports dependency
🤔
Concept: Learn how to include Extent Reports library in your Selenium Java project.
To use Extent Reports, first add its dependency to your project. If you use Maven, add this to your pom.xml: com.aventstack extentreports 5.0.9 This downloads the Extent Reports library so you can use it in your code.
Result
Your project now has Extent Reports available to import and use.
Knowing how to add dependencies is the first step to using any external tool in your project.
2
FoundationInitialize Extent Reports objects
🤔
Concept: Create the main Extent Reports objects needed to start logging test results.
In your test code, create these objects: ExtentReports extent = new ExtentReports(); ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("extentReport.html"); extent.attachReporter(htmlReporter); The ExtentHtmlReporter sets the output file. The ExtentReports object manages the report.
Result
You have a report object ready to log test steps and results.
Initialization sets the foundation for capturing and saving test information.
3
IntermediateCreate and log test cases
🤔Before reading on: do you think you log test steps before or after running the test? Commit to your answer.
Concept: Learn how to create test entries and log pass/fail status during test execution.
Inside your test method, create a test entry: ExtentTest test = extent.createTest("Test Case Name"); Then log steps: test.pass("Step passed message"); test.fail("Step failed message"); Use these to mark what happened during the test.
Result
Test steps and results are recorded in the report object.
Logging test steps as they happen helps build a detailed and useful report.
4
IntermediateFlush and generate report file
🤔Before reading on: do you think the report file updates automatically or needs a manual save? Commit to your answer.
Concept: Understand how to save the collected test data into the final report file.
After all tests finish, call: extent.flush(); This writes all logged information to the HTML file you specified earlier. Without this, the report file stays empty.
Result
An HTML report file is created or updated with test results.
Knowing when to flush prevents missing or incomplete reports.
5
IntermediateIntegrate Extent Reports with TestNG
🤔Before reading on: do you think Extent Reports setup goes inside each test or in test lifecycle methods? Commit to your answer.
Concept: Learn to set up Extent Reports in TestNG's lifecycle methods for better management.
Use TestNG annotations: @BeforeSuite public void setup() { // initialize ExtentReports } @AfterSuite public void tearDown() { extent.flush(); } @BeforeMethod public void startTest(Method method) { test = extent.createTest(method.getName()); } This organizes report creation and flushing properly.
Result
Reports are created and saved automatically with TestNG tests.
Using test framework hooks ensures reports are consistent and complete.
6
AdvancedAdd screenshots to reports
🤔Before reading on: do you think screenshots are added before or after test failure? Commit to your answer.
Concept: Learn how to capture and attach screenshots to Extent Reports on test failure.
On test failure, capture screenshot: File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); String path = "screenshots/" + System.currentTimeMillis() + ".png"; FileUtils.copyFile(src, new File(path)); Attach to report: test.fail("Test failed", MediaEntityBuilder.createScreenCaptureFromPath(path).build()); This shows exactly what went wrong visually.
Result
Reports include screenshots for failed tests, improving debugging.
Visual evidence in reports speeds up problem solving and communication.
7
ExpertCustomize report look and behavior
🤔Before reading on: do you think Extent Reports styling is fixed or customizable? Commit to your answer.
Concept: Explore advanced configuration options to change report theme, title, and system info.
Use htmlReporter.config(): htmlReporter.config().setDocumentTitle("My Test Report"); htmlReporter.config().setReportName("Regression Tests"); htmlReporter.config().setTheme(Theme.DARK); Add system info: extent.setSystemInfo("OS", "Windows 10"); extent.setSystemInfo("Tester", "Alice"); These make reports clearer and branded.
Result
Reports look professional and provide useful context.
Customizing reports improves readability and stakeholder trust.
Under the Hood
Extent Reports works by creating objects in memory that collect test information as tests run. It stores test names, statuses, logs, and attachments. When you call flush(), it converts this data into an HTML file with embedded CSS and JavaScript for interactivity. The report file is static but visually rich, showing colors and expandable details.
Why designed this way?
It was designed to separate test execution from reporting, so tests run fast without waiting for file writes. The flush step batches all data into one file for performance and simplicity. Using HTML allows easy sharing and viewing without special software.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ Test Execution│──────▶│ ExtentReports │──────▶│ HTML Report   │
│ (Selenium)    │       │ (In-memory)   │       │ (File Output) │
└───────────────┘       └───────────────┘       └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does Extent Reports automatically save the report file after each test? Commit yes or no.
Common Belief:Extent Reports saves the report file automatically after every test step.
Tap to reveal reality
Reality:Extent Reports only writes the report file when you call extent.flush(), usually at the end of all tests.
Why it matters:If you forget to call flush(), the report file will be empty or incomplete, causing confusion and wasted debugging time.
Quick: Can you add screenshots to Extent Reports without saving image files? Commit yes or no.
Common Belief:You can embed screenshots directly without saving image files on disk.
Tap to reveal reality
Reality:Extent Reports requires screenshots to be saved as files first, then referenced in the report.
Why it matters:Trying to embed unsaved screenshots causes errors or missing images in reports, reducing their usefulness.
Quick: Does Extent Reports replace your test framework like TestNG or JUnit? Commit yes or no.
Common Belief:Extent Reports is a test framework that runs tests and reports results.
Tap to reveal reality
Reality:Extent Reports only creates reports; it does not run or manage tests. You still need TestNG, JUnit, or similar.
Why it matters:Confusing these leads to improper test setup and missing test execution control.
Quick: Is it safe to share Extent Reports HTML files publicly without risk? Commit yes or no.
Common Belief:Extent Reports HTML files contain only test results and no sensitive data.
Tap to reveal reality
Reality:Reports may include system info, logs, or screenshots that contain sensitive information.
Why it matters:Sharing reports without review can expose confidential data, causing security risks.
Expert Zone
1
Extent Reports supports parallel test execution but requires thread-safe handling of ExtentTest objects to avoid data mix-ups.
2
You can extend Extent Reports with custom reporters or listeners to integrate with CI/CD pipelines and dashboards.
3
The report's HTML and CSS can be customized deeply by modifying the reporter's config or using custom CSS files.
When NOT to use
Extent Reports is not ideal for very large test suites with thousands of tests due to report size and performance. In such cases, lightweight logging or specialized test management tools are better.
Production Patterns
In real projects, Extent Reports is integrated with TestNG listeners to automatically log test start, success, failure, and skip events. Screenshots are captured on failure and attached. Reports are archived per build and linked in CI tools like Jenkins.
Connections
TestNG Listeners
Builds-on
Understanding TestNG listeners helps automate Extent Reports logging without manual calls in each test.
Continuous Integration (CI)
Used together
Integrating Extent Reports with CI tools like Jenkins provides quick feedback on test results after each code change.
Data Visualization
Shares principles
Extent Reports applies data visualization principles by turning raw test data into clear, interactive visual summaries.
Common Pitfalls
#1Forgetting to call extent.flush() after tests finish.
Wrong approach:public void tearDown() { // no flush call here }
Correct approach:public void tearDown() { extent.flush(); }
Root cause:Misunderstanding that flush() is required to write the report file.
#2Creating ExtentReports and ExtentTest objects inside each test without sharing.
Wrong approach:ExtentReports extent = new ExtentReports(); ExtentTest test = extent.createTest("Test1"); // repeated in every test method
Correct approach:Initialize ExtentReports once in @BeforeSuite and create ExtentTest in @BeforeMethod or test method.
Root cause:Not managing object lifecycle leads to multiple reports or lost data.
#3Not saving screenshots to disk before attaching to report.
Wrong approach:test.fail("Failed", MediaEntityBuilder.createScreenCaptureFromPath("temp.png").build()); // but temp.png does not exist
Correct approach:Save screenshot file first, then attach: File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("temp.png")); test.fail("Failed", MediaEntityBuilder.createScreenCaptureFromPath("temp.png").build());
Root cause:Assuming Extent Reports can embed images directly from memory.
Key Takeaways
Extent Reports turns raw test results into clear, colorful HTML reports that improve understanding and communication.
You must add Extent Reports as a dependency and initialize it properly before logging tests.
Logging test steps and calling flush() at the end are essential to generate complete reports.
Integrating Extent Reports with test frameworks like TestNG automates report creation and management.
Adding screenshots and customizing reports makes debugging easier and reports more professional.

Practice

(1/5)
1. What is the primary purpose of using ExtentHtmlReporter in Selenium Java testing?
easy
A. To execute Selenium WebDriver tests
B. To locate web elements on a page
C. To generate an HTML report for test execution results
D. To manage browser windows during tests

Solution

  1. Step 1: Understand the role of ExtentHtmlReporter

    ExtentHtmlReporter is used to create a visual HTML report that shows test results clearly.
  2. Step 2: Differentiate from other components

    It does not run tests or interact with browsers; it only formats and outputs reports.
  3. Final Answer:

    To generate an HTML report for test execution results -> Option C
  4. Quick Check:

    ExtentHtmlReporter = HTML report generator [OK]
Hint: ExtentHtmlReporter creates HTML reports, not test execution [OK]
Common Mistakes:
  • Confusing ExtentHtmlReporter with WebDriver
  • Thinking it runs tests
  • Assuming it manages browser actions
2. Which of the following is the correct way to initialize ExtentReports with ExtentHtmlReporter in Java?
easy
A. ExtentReports extent = new ExtentReports(); extent.createReporter("report.html");
B. ExtentHtmlReporter reporter = new ExtentHtmlReporter("report.html"); ExtentReports extent = new ExtentReports(); extent.attachReporter(reporter);
C. ExtentHtmlReporter reporter = new ExtentHtmlReporter(); extent.attachReporter(reporter);
D. ExtentReports extent = new ExtentReports("report.html"); ExtentHtmlReporter reporter = new ExtentHtmlReporter();

Solution

  1. Step 1: Create ExtentHtmlReporter with file path

    You must instantiate ExtentHtmlReporter with the report file name or path.
  2. Step 2: Attach reporter to ExtentReports instance

    Create ExtentReports object and attach the reporter using attachReporter method.
  3. Final Answer:

    ExtentHtmlReporter reporter = new ExtentHtmlReporter("report.html"); ExtentReports extent = new ExtentReports(); extent.attachReporter(reporter); -> Option B
  4. Quick Check:

    Initialize reporter with path, then attach to ExtentReports [OK]
Hint: Create reporter with path, then attach to ExtentReports [OK]
Common Mistakes:
  • Not passing file path to ExtentHtmlReporter constructor
  • Calling attachReporter before creating ExtentReports
  • Using non-existent methods like createReporter
3. Given the following code snippet, what will be the output in the Extent Report after execution?
ExtentHtmlReporter reporter = new ExtentHtmlReporter("testReport.html");
ExtentReports extent = new ExtentReports();
extent.attachReporter(reporter);
ExtentTest test = extent.createTest("LoginTest");
test.pass("Login successful");
extent.flush();
medium
A. The report will show a test named 'LoginTest' marked as failed.
B. The report will be empty because flush() is called before creating the test.
C. The code will throw a runtime exception due to missing test initialization.
D. The report will show a test named 'LoginTest' marked as passed with message 'Login successful'.

Solution

  1. Step 1: Analyze test creation and logging

    The test 'LoginTest' is created and logged as passed with message 'Login successful'.
  2. Step 2: Understand flush() role

    Calling extent.flush() writes the report to the file including all logged tests.
  3. Final Answer:

    The report will show a test named 'LoginTest' marked as passed with message 'Login successful'. -> Option D
  4. Quick Check:

    createTest + pass + flush = Passed test in report [OK]
Hint: Create test, log pass, then flush to save report [OK]
Common Mistakes:
  • Thinking flush() clears tests
  • Assuming test is failed without fail() call
  • Believing report is empty without flush()
4. Identify the error in the following Extent Reports setup code:
ExtentHtmlReporter reporter = new ExtentHtmlReporter();
ExtentReports extent = new ExtentReports();
extent.attachReporter(reporter);
ExtentTest test = extent.createTest("SearchTest");
test.pass("Search executed");
extent.flush();
medium
A. ExtentHtmlReporter must be initialized with a file path in its constructor.
B. ExtentReports cannot attach more than one reporter.
C. createTest() method requires two parameters.
D. flush() should be called before creating tests.

Solution

  1. Step 1: Check ExtentHtmlReporter initialization

    ExtentHtmlReporter requires a file path string in its constructor to specify report output location.
  2. Step 2: Verify other method usages

    attachReporter, createTest, and flush are used correctly; no multiple reporter restriction or parameter issues.
  3. Final Answer:

    ExtentHtmlReporter must be initialized with a file path in its constructor. -> Option A
  4. Quick Check:

    Reporter needs file path on creation [OK]
Hint: Always give file path when creating ExtentHtmlReporter [OK]
Common Mistakes:
  • Omitting file path in ExtentHtmlReporter constructor
  • Misunderstanding createTest parameters
  • Calling flush too early
5. You want to create an Extent Report that logs multiple tests and marks one as failed with a custom error message. Which code snippet correctly sets up the report and logs these results?
hard
A. ExtentHtmlReporter reporter = new ExtentHtmlReporter("multiTestReport.html"); ExtentReports extent = new ExtentReports(); extent.attachReporter(reporter); ExtentTest test1 = extent.createTest("Test1"); test1.pass("Test1 passed"); ExtentTest test2 = extent.createTest("Test2"); test2.fail("Test2 failed due to timeout"); extent.flush();
B. ExtentReports extent = new ExtentReports("multiTestReport.html"); ExtentHtmlReporter reporter = new ExtentHtmlReporter(); extent.createTest("Test1").pass("Test1 passed"); extent.createTest("Test2").fail("Test2 failed due to timeout"); extent.flush();
C. ExtentHtmlReporter reporter = new ExtentHtmlReporter(); ExtentReports extent = new ExtentReports(); extent.attachReporter(reporter); extent.createTest("Test1").pass("Test1 passed"); extent.createTest("Test2").fail("Test2 failed due to timeout"); extent.flush();
D. ExtentHtmlReporter reporter = new ExtentHtmlReporter(); ExtentReports extent = new ExtentReports(); extent.attachReporter(reporter); ExtentTest test1 = extent.createTest("Test1"); test1.fail("Test1 failed"); ExtentTest test2 = extent.createTest("Test2"); test2.pass("Test2 passed"); extent.flush();

Solution

  1. Step 1: Initialize ExtentHtmlReporter with file path

    Instantiate ExtentHtmlReporter with the path to the report file, create an ExtentReports instance, and attach the reporter.
  2. Step 2: Create multiple tests and log statuses

    Create ExtentTest instances with createTest(), log one with pass("message") and one with fail("custom error message"), then flush().
  3. Final Answer:

    ExtentHtmlReporter reporter = new ExtentHtmlReporter("multiTestReport.html"); ExtentReports extent = new ExtentReports(); extent.attachReporter(reporter); ExtentTest test1 = extent.createTest("Test1"); test1.pass("Test1 passed"); ExtentTest test2 = extent.createTest("Test2"); test2.fail("Test2 failed due to timeout"); extent.flush(); -> Option A
  4. Quick Check:

    Reporter with path + attach + pass/fail + flush [OK]
Hint: Attach reporter with path, create tests, log pass/fail, then flush [OK]
Common Mistakes:
  • Not passing file path to ExtentHtmlReporter
  • Swapping pass and fail calls
  • Calling flush before logging tests
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard