Integrating Allure Reports with Selenium
Allure Reports is a powerful, flexible reporting framework that provides detailed, interactive test reports. When integrated with Selenium, Allure helps visualize test execution results, steps, attachments, and failures—making debugging and reporting much easier.
1. Why Use Allure with Selenium?
Allure enhances Selenium test reporting by providing:
Clean and interactive HTML reports
Detailed test steps and execution history
Screenshots and logs for failed tests
Easy integration with CI/CD pipelines
Support for multiple test frameworks
2. Supported Test Frameworks
Allure works with Selenium tests written using:
JUnit
TestNG
PyTest
Behave
Cucumber
In this guide, examples use Java + Selenium + TestNG, but the concepts are similar for other stacks.
3. Prerequisites
Before starting, ensure you have:
Selenium set up
A test framework (e.g., TestNG or JUnit)
Java 8+ (or Python for PyTest users)
Maven or Gradle
Node.js installed (for Allure CLI)
4. Installing Allure Command-Line Tool
Using npm
npm install -g allure-commandline
Verify installation:
allure --version
5. Adding Allure Dependencies (Maven)
Add the following dependencies to your pom.xml:
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.24.0</version>
</dependency>
</dependencies>
Configure the Allure Maven plugin:
<build>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.11.2</version>
</plugin>
</plugins>
</build>
6. Configuring TestNG Listener
Add the Allure listener to your testng.xml:
<listeners>
<listener class-name="io.qameta.allure.testng.AllureTestNg"/>
</listeners>
Or annotate your test class:
@Listeners({AllureTestNg.class})
7. Writing Selenium Tests with Allure Annotations
Basic Test Example
@Epic("Login Feature")
@Feature("User Authentication")
@Story("Valid Login")
@Severity(SeverityLevel.CRITICAL)
@Test
public void validLoginTest() {
driver.get("https://example.com/login");
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("login")).click();
}
Common Allure Annotations
@Epic
@Feature
@Story
@Severity
@Description
@Step
8. Adding Steps to Tests
Use @Step for readable execution logs.
@Step("Enter username: {username}")
public void enterUsername(String username) {
driver.findElement(By.id("username")).sendKeys(username);
}
9. Attaching Screenshots and Logs
Screenshot Attachment on Failure
@Attachment(value = "Screenshot", type = "image/png")
public byte[] takeScreenshot() {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
Call this method in a test listener or @AfterMethod.
10. Running Tests and Generating Reports
Run Tests
mvn clean test
Allure results will be generated in:
target/allure-results
Generate and View Report
allure serve target/allure-results
This opens an interactive report in your browser.
11. Allure Report Features
Allure reports include:
Test execution timeline
Passed/failed/skipped test statistics
Test categorization (epics, features)
Stack traces and logs
Attachments (screenshots, videos)
12. CI/CD Integration
Allure integrates easily with:
Jenkins
GitHub Actions
GitLab CI
Azure DevOps
Typical CI flow:
Run Selenium tests
Generate Allure results
Publish Allure report as build artifact
13. Best Practices
Use @Step annotations for clarity
Attach screenshots only on failures
Categorize tests using features and stories
Clean old reports before new runs
Keep reports lightweight for CI pipelines
14. Common Issues & Troubleshooting
Missing results folder → Check listeners
Empty report → Verify test execution
Screenshots not attached → Ensure attachment methods are called
Version mismatch → Align Allure dependencies
Final Thoughts
Integrating Allure Reports with Selenium greatly improves test visibility, debugging efficiency, and reporting quality. It transforms raw test results into meaningful insights that benefit QA teams, developers, and stakeholders alike.
Learn Selenium with JAVA Training in Hyderabad
Read More
Maven Project Setup for Selenium Testing
Adding Custom Reports in Your Framework
How to Use POM with PageFactory
Visit Our Quality Thought Institute in Hyderabad
Subscribe by Email
Follow Updates Articles from This Blog via Email
No Comments