Common Mistakes & Anti-Patterns
This section documents real mistakes repeatedly seen in production automation frameworks. Avoiding these is as important as knowing the correct implementation.
1οΈβ£ Creating Reports Inside Test Classes ββ
Why People Do Thisβ
- Simplicity
- Copy-paste from tutorials
Why It Failsβ
- Breaks parallel execution
- Causes duplicate reports
- Violates separation of concerns
β Correct: Initialize reports in listeners / framework layer
2οΈβ£ Using Static ExtentTest Variables ββ
public static ExtentTest test;
Why It Failsβ
- Shared across threads
- Log mixing
- Wrong screenshots
β Correct: Use ThreadLocal<ExtentTest>
3οΈβ£ Flushing Reports Multiple Times ββ
Common Misuseβ
- Flushing after every test
- Flushing inside
@AfterMethod
Impactβ
- Corrupted HTML
- Missing logs
β Correct: Flush once in suite completion
4οΈβ£ Logging Everything ββ
Examples:
- Every Selenium call
- Every framework method
Impactβ
- Huge unreadable reports
- Business users stop reading
β Correct: Log intent, not implementation
5οΈβ£ Screenshot Abuse ββ
What Goes Wrongβ
- Screenshot on every step
- Overwriting screenshot files
Impactβ
- Slow execution
- Incorrect attachments
β Correct: Screenshot on failure + critical steps only
6οΈβ£ Hardcoded Paths ββ
Examplesβ
C:/Users/...- Local desktop paths
Impactβ
- CI failures
- Non-portable framework
β Correct: Relative paths + workspace-aware locations
7οΈβ£ Ignoring Thread Cleanup ββ
What Happensβ
- Memory leaks
- Unstable reports in long runs
β Correct:
extentTest.remove();
8οΈβ£ Over-Customization ββ
Examplesβ
- Heavy CSS/JS
- UI hacks
Impactβ
- Fragile reports
- Upgrade pain
β Correct: Minimal, meaningful customization
9οΈβ£ Mixing Reporting With Assertions ββ
Bad Practiceβ
test.fail("Assertion failed");
Assert.fail();
Impactβ
- Duplicate failures
- Confusing reports
β Correct: Assertions fail tests, listeners report them
π Self-Audit Checklistβ
Before committing your framework, confirm:
β One report per execution β ThreadLocal usage present β Listeners control lifecycle β CI reports always published β No test-level report code
π§ Final Takeawayβ
Most Extent Reports problems are design problems, not library problems.
Avoiding these anti-patterns guarantees stable, trustworthy reports.