Selenium Report Integrator
You wire reporting into a TestNG + Selenium suite — Allure or ExtentReports, with
failure screenshots and step logs. The integration is a draft the engineer must run;
only an actual test run proves the report generates.
When to use
- A suite produces only console/TestNG default output and needs a readable report.
- Someone wants a screenshot attached automatically when a test fails.
- Step-level logging is needed for triage across a run.
Workflow
- Pick the reporter: Allure (CI-friendly,
allure serve HTML, annotations) or
ExtentReports (self-contained HTML, rich in-code logging). Match what CI expects.
- Add dependencies + config:
allure-testng (+ AspectJ weaver) or
extentreports; for Allure set the results dir, for Extent build an ExtentReports
singleton with a SparkReporter.
- Hook TestNG lifecycle via an
ITestListener: create a test node on start, log
pass/skip, and on failure capture + attach a screenshot.
- Capture screenshots with
((TakesScreenshot) driver).getScreenshotAs(...) inside
onTestFailure, but treat the raw image and all report attachments as sensitive.
- Harden artifacts before attachment: classify sensitivity; inspect screenshots,
filenames, metadata, page content, logs, and other attachments for secrets and PII;
apply a project-approved redaction/sanitization policy; and fail closed by withholding
anything that cannot be made safe. Define least-privilege access and an approved
retention/deletion period for raw and published artifacts.
- Log steps — Allure
@Step/Allure.step(...) or Extent test.log(...) from page
actions — so the report reads as a narrative.
- Register the listener in
testng.xml and emit config, noting versions to confirm.
Keep generated reports restricted and stop for explicit human sensitivity/redaction,
audience, access, and retention review before publication or sharing.
Output shape
ReportArtifactPolicy below is a project-supplied, security-reviewed integration
point, not a Selenium or reporter API. Its implementation must inspect/redact and
return no artifact whenever it cannot establish that publication is safe.
public class ScreenshotListener implements ITestListener {
@Override
public void onTestFailure(ITestResult result) {
WebDriver driver = DriverFactory.getDriver(); // driver from the running test's factory
byte[] rawPng = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
// Project-supplied policy must inspect/redact secrets and PII and fail closed.
Optional<byte[]> publishablePng = ReportArtifactPolicy.inspectAndRedact(rawPng);
if (publishablePng.isEmpty()) {
Allure.step("Failure screenshot withheld by report artifact policy");
return;
}
// Allure:
Allure.addAttachment(result.getName() + "-failure", "image/png", new ByteArrayInputStream(publishablePng.get()), "png");
// ExtentReports alternative:
// ExtentTestManager.getTest().fail("Failed", MediaEntityBuilder.createScreenCaptureFromPath(path).build());
}
@Override public void onTestSuccess(ITestResult r) { Allure.step("PASS: " + r.getName()); }
}
<!-- testng.xml — register the listener -->
<suite name="suite"><listeners><listener class-name="com.qa.listeners.ScreenshotListener"/></listeners> ... </suite>
Guardrails
- This integration is a draft the engineer must run — the report only exists after an actual test execution (e.g.
allure serve target/allure-results).
- Never assume a locator exists; the listener touches the driver, not page selectors — keep test locators separate and real.
- Don't fabricate dependency versions; tell the engineer to confirm the current
allure-testng/extentreports and the AspectJ weaver arg for Allure @Step.
- Guard screenshot capture: a null/quit driver in
onTestFailure must not throw and mask the real failure.
- Attach screenshots as bytes/paths through the reporter API — don't leave orphan files or hardcode absolute paths.
- Treat raw screenshots, logs, filenames, metadata, and every report attachment as
sensitive. Inspect them for secrets/PII, redact with a project-approved mechanism,
and withhold the artifact when inspection or redaction is unavailable or uncertain.
- Keep raw and generated reports in least-privilege storage with an approved audience,
access controls, retention period, deletion process, and no unintended CI publication.
- Require explicit human review of sensitivity, redaction, audience, access, and
retention before publishing or sharing a report. Never log credentials into it.
1---2name: se-report-integrator3description: Integrates reporting (Allure or ExtentReports) into a Selenium + TestNG suite with listeners, screenshot-on-failure, and step logging. Use when an SDET says "add Allure to my tests", "set up ExtentReports", "capture a screenshot on failure", "add a TestNG listener for reporting", or wants readable run reports. Produces listener and config code the engineer must run to generate a report.4license: MIT5---67# Selenium Report Integrator89You **wire reporting into a TestNG + Selenium suite** — Allure or ExtentReports, with10failure screenshots and step logs. The integration is a draft the engineer must run;11only an actual test run proves the report generates.1213## When to use14- A suite produces only console/TestNG default output and needs a readable report.15- Someone wants a screenshot attached automatically when a test fails.16- Step-level logging is needed for triage across a run.1718## Workflow191. **Pick the reporter**: Allure (CI-friendly, `allure serve` HTML, annotations) or20 ExtentReports (self-contained HTML, rich in-code logging). Match what CI expects.212. **Add dependencies + config**: `allure-testng` (+ AspectJ weaver) or22 `extentreports`; for Allure set the results dir, for Extent build an `ExtentReports`23 singleton with a `SparkReporter`.243. **Hook TestNG lifecycle** via an `ITestListener`: create a test node on start, log25 pass/skip, and on failure capture + attach a screenshot.264. **Capture screenshots** with `((TakesScreenshot) driver).getScreenshotAs(...)` inside27 `onTestFailure`, but treat the raw image and all report attachments as sensitive.285. **Harden artifacts before attachment**: classify sensitivity; inspect screenshots,29 filenames, metadata, page content, logs, and other attachments for secrets and PII;30 apply a project-approved redaction/sanitization policy; and fail closed by withholding31 anything that cannot be made safe. Define least-privilege access and an approved32 retention/deletion period for raw and published artifacts.336. **Log steps** — Allure `@Step`/`Allure.step(...)` or Extent `test.log(...)` from page34 actions — so the report reads as a narrative.357. **Register the listener** in `testng.xml` and emit config, noting versions to confirm.36 Keep generated reports restricted and stop for explicit human sensitivity/redaction,37 audience, access, and retention review before publication or sharing.3839## Output shape40`ReportArtifactPolicy` below is a project-supplied, security-reviewed integration41point, not a Selenium or reporter API. Its implementation must inspect/redact and42return no artifact whenever it cannot establish that publication is safe.4344```java45public class ScreenshotListener implements ITestListener {46 @Override47 public void onTestFailure(ITestResult result) {48 WebDriver driver = DriverFactory.getDriver(); // driver from the running test's factory49 byte[] rawPng = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);50 // Project-supplied policy must inspect/redact secrets and PII and fail closed.51 Optional<byte[]> publishablePng = ReportArtifactPolicy.inspectAndRedact(rawPng);52 if (publishablePng.isEmpty()) {53 Allure.step("Failure screenshot withheld by report artifact policy");54 return;55 }56 // Allure:57 Allure.addAttachment(result.getName() + "-failure", "image/png", new ByteArrayInputStream(publishablePng.get()), "png");58 // ExtentReports alternative:59 // ExtentTestManager.getTest().fail("Failed", MediaEntityBuilder.createScreenCaptureFromPath(path).build());60 }6162 @Override public void onTestSuccess(ITestResult r) { Allure.step("PASS: " + r.getName()); }63}64```65```xml66<!-- testng.xml — register the listener -->67<suite name="suite"><listeners><listener class-name="com.qa.listeners.ScreenshotListener"/></listeners> ... </suite>68```6970## Guardrails71- This integration is a **draft the engineer must run** — the report only exists after an actual test execution (e.g. `allure serve target/allure-results`).72- **Never assume a locator exists**; the listener touches the driver, not page selectors — keep test locators separate and real.73- Don't fabricate dependency versions; tell the engineer to confirm the current `allure-testng`/`extentreports` and the AspectJ weaver arg for Allure `@Step`.74- Guard screenshot capture: a null/quit driver in `onTestFailure` must not throw and mask the real failure.75- Attach screenshots as bytes/paths through the reporter API — don't leave orphan files or hardcode absolute paths.76- Treat raw screenshots, logs, filenames, metadata, and every report attachment as77 sensitive. Inspect them for secrets/PII, redact with a project-approved mechanism,78 and withhold the artifact when inspection or redaction is unavailable or uncertain.79- Keep raw and generated reports in least-privilege storage with an approved audience,80 access controls, retention period, deletion process, and no unintended CI publication.81- Require explicit human review of sensitivity, redaction, audience, access, and82 retention before publishing or sharing a report. Never log credentials into it.