How to Configure Allure Reports with the AllureManager Class in automationframeworkselenium
The AllureManager class in anhtester/automationframeworkselenium provides static utility methods to write environment metadata, capture screenshots, attach video recordings, and add custom text or HTML logs to Allure reports, all controlled via external property files.
The anhtester/automationframeworkselenium repository offers a robust TestNG-based automation framework with built-in Allure reporting capabilities. Learning how to configure Allure reports with the AllureManager class allows you to generate rich, diagnostic-heavy test reports without modifying test logic. The framework centralizes all reporting switches in FrameworkConstants, making it easy to toggle screenshots, videos, and environment details through simple configuration changes.
Understanding the Allure Reporting Architecture
The framework implements a three-layer architecture for Allure integration. Understanding these components helps you configure reports effectively without hunting through the codebase.
Core Components
-
AllureManager (
src/main/java/com/anhtester/reports/AllureManager.java): The primary utility class containing static helper methods for environment setup, screenshot capture, video attachment, and custom logging. -
AllureListener (
src/test/java/com/anhtester/listeners/AllureListener.java): A TestNG listener that hooks into the test lifecycle to automatically attach screenshots based on configuration flags for passed or failed tests. -
FrameworkConstants (
src/main/java/com/anhtester/constants/FrameworkConstants.java): The centralized configuration holder that readsSCREENSHOT_PASSED_TCS,SCREENSHOT_FAILED_TCS,VIDEO_RECORD, andEXPORT_VIDEO_PATHfrom property files.
Setting Up Environment Information
Allure reports can display a dedicated "Environment" section showing test execution context such as URLs, browser versions, and timeout values. The AllureManager class writes this data via the AllureEnvironmentWriter.
Writing the Environment Block
Call AllureManager.setAllureEnvironmentInformation() once per test suite to populate the environment widget with values from FrameworkConstants:
import com.anhtester.reports.AllureManager;
import org.testng.annotations.BeforeSuite;
public class BaseTest {
@BeforeSuite
public void suiteSetup() {
AllureManager.setAllureEnvironmentInformation();
}
}
This method aggregates framework configuration values and registers them as key-value pairs visible in the generated Allure report.
Managing Test Artifacts
The AllureManager class provides specific methods for different attachment types, each annotated with Allure's @Attachment annotation for automatic inclusion in reports.
Capturing Screenshots on Failure and Success
Three distinct methods handle visual documentation:
-
takeScreenshotToAttachOnAllureReport(): Captures the current browser state specifically for failed test cases. The framework typically calls this fromBaseTestvia@AfterMethodor automatically viaAllureListener. -
takeScreenshotStep(): Captures screenshots at arbitrary points within test logic, useful for documenting intermediate states in page object methods. -
Configuration Flags: Set
SCREENSHOT_PASSED_TCS=yesin your properties file to attach screenshots for every passed test viaAllureListener. SetSCREENSHOT_FAILED_TCS=yesto ensure failed tests always include visual evidence.
import com.anhtester.reports.AllureManager;
import io.qameta.allure.Allure;
public class LoginTest extends BaseTest {
public void verifyLogin() {
// Custom step screenshot inside business logic
Allure.addAttachment("Before Login",
AllureManager.takeScreenshotStep());
loginPage.performLogin();
}
@AfterMethod
public void tearDown(ITestResult result) {
if (!result.isSuccess()) {
Allure.addAttachment("Failure Evidence",
AllureManager.takeScreenshotToAttachOnAllureReport());
}
}
}
Attaching Video Recordings
For comprehensive debugging, the framework supports attaching screen recordings in AVI or MP4 formats:
addAttachmentVideoAVI(): Attaches the most recent AVI file from the export directory.addAttachmentVideoMP4(): Attaches the most recent MP4 file from the export directory.
Enable video attachment by setting VIDEO_RECORD=yes and defining EXPORT_VIDEO_PATH in your configuration. The AllureListener or your BaseTest class should invoke these methods after test execution completes.
@AfterMethod
public void attachVideo() {
// Attaches video only if files exist in EXPORT_VIDEO_PATH
AllureManager.addAttachmentVideoMP4();
}
Adding Custom Logs and HTML
Beyond visual artifacts, you can attach diagnostic data as text or formatted HTML:
// Plain text attachment for API responses or stack traces
AllureManager.saveTextLog("API Response: " + jsonResponse);
// HTML attachment for formatted tables or rich content
AllureManager.attachHtml("<h3>Order Details</h3><table>" + htmlContent + "</table>");
These methods are ideal for attaching request/response payloads, database query results, or structured debug information.
Capturing Browser and OS Metadata
Use addBrowserInformationOnAllureReport() to attach operating system and browser details as a plain-text file named "Browser Information":
Allure.addAttachment("Browser Information",
AllureManager.addBrowserInformationOnAllureReport());
This method leverages BrowserInfoUtils to fetch runtime environment details, helping you identify platform-specific test failures.
Configuring Allure Behavior via Properties
All reporting behavior is externalized to property files, allowing you to adjust output without code changes.
FrameworkConstants Configuration
The FrameworkConstants class reads the following keys from src/main/resources/config.properties (or equivalent):
| Constant | Values | Effect |
|---|---|---|
SCREENSHOT_PASSED_TCS |
yes / no |
When yes, AllureListener automatically attaches screenshots for passed tests. |
SCREENSHOT_FAILED_TCS |
yes / no |
When yes, automatically attaches screenshots for failed tests. |
VIDEO_RECORD |
yes / no |
Enables video attachment logic in AllureListener and BaseTest. |
EXPORT_VIDEO_PATH |
File path | Directory where screen recording utilities store AVI/MP4 files (e.g., ExportData/Videos/). |
Example config.properties:
SCREENSHOT_PASSED_TCS=no
SCREENSHOT_FAILED_TCS=yes
VIDEO_RECORD=yes
EXPORT_VIDEO_PATH=ExportData/Videos/
Changing these values and rerunning the suite immediately alters Allure report content without rebuilding the project.
Integrating AllureManager into Your Test Base
A typical implementation wires environment setup and artifact attachment into your base test class, while the AllureListener handles automatic screenshot injection.
Wiring Components in BaseTest
package com.anhtester.common;
import com.anhtester.reports.AllureManager;
import io.qameta.allure.Allure;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
@Listeners(com.anhtester.listeners.AllureListener.class)
public class BaseTest {
@BeforeSuite
public void initAllureEnvironment() {
// Write environment block once per execution
AllureManager.setAllureEnvironmentInformation();
}
@AfterMethod
public void attachTestArtifacts(ITestResult result) {
// Manual attachment for failures (if not using listener exclusively)
if (!result.isSuccess()) {
Allure.addAttachment("Screenshot on Failure",
AllureManager.takeScreenshotToAttachOnAllureReport());
}
// Attach video if recording is enabled
if (Boolean.parseBoolean(System.getProperty("video.record", "false"))) {
AllureManager.addAttachmentVideoMP4();
}
// Attach browser metadata
Allure.addAttachment("Execution Environment",
AllureManager.addBrowserInformationOnAllureReport());
}
}
The @Listeners annotation registers AllureListener, which intercepts test results and applies the SCREENSHOT_PASSED_TCS and SCREENSHOT_FAILED_TCS logic automatically.
Generating the Final Report
After test execution completes, Allure result files reside in target/allure-results by default. Generate the interactive HTML report using Maven:
mvn allure:serve
Alternatively, use the Allure CLI:
allure serve target/allure-results
The generated report displays your environment table, step-by-step screenshots, video attachments, and custom logs organized by test case.
Summary
- The
AllureManagerclass insrc/main/java/com/anhtester/reports/AllureManager.javaprovides static methods for environment setup, screenshots, videos, and custom attachments. - Configuration is centralized in
FrameworkConstantsand controlled viaconfig.propertieskeys likeSCREENSHOT_FAILED_TCSandVIDEO_RECORD. - Automatic attachment occurs through
AllureListener(src/test/java/com/anhtester/listeners/AllureListener.java), while manual attachment happens inBaseTestteardown methods. - Environment metadata is written once per suite via
setAllureEnvironmentInformation(). - Video and screenshot methods support both AVI and MP4 formats, with paths defined by
EXPORT_VIDEO_PATH.
Frequently Asked Questions
How do I enable screenshots for passed tests using AllureManager?
Set SCREENSHOT_PASSED_TCS=yes in your config.properties file. The AllureListener class automatically detects this flag and attaches a screenshot via AllureManager methods whenever a test passes. You do not need to modify your test code; the listener handles the attachment during the TestNG lifecycle.
Where does AllureManager look for video files to attach?
The AllureManager class searches the directory specified by the EXPORT_VIDEO_PATH property in config.properties. Methods like addAttachmentVideoMP4() and addAttachmentVideoAVI() look for the most recent video file in that path and attach it to the current test case in the Allure report.
Can I add custom HTML tables to Allure reports using AllureManager?
Yes. Use the AllureManager.attachHtml() static method to add formatted HTML content. Pass your HTML string directly to this method—for example, <table><tr><td>Data</td></tr></table>—and Allure renders it as an attachment in the report timeline. This is useful for displaying structured API responses or comparison tables.
How do I change the environment information displayed in Allure reports?
Modify the values in config.properties that are mapped in FrameworkConstants, then ensure your BaseTest class calls AllureManager.setAllureEnvironmentInformation() in a @BeforeSuite method. This writes the current configuration values (URL, browser, timeouts) to the Allure environment widget. Changes take effect immediately on the next test run without recompiling code.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →