What is Serenity BDD?
Serenity BDD (formerly Thucydides) is an open-source reporting library that provides:- Living Documentation - Automatic generation of illustrated, narrative reports
- Screenplay Pattern Support - Built-in support for maintainable test design
- WebDriver Management - Automatic browser driver management via Selenium Manager
- Rich Reporting - Detailed test execution reports with screenshots and evidence
- Requirements Traceability - Links tests to business requirements
This project uses Serenity BDD version 4.0.46, which includes the latest Selenium Manager integration and parallel reporting capabilities.
Gradle Configuration
Plugin Setup
The Serenity Gradle plugin is configured at the top ofbuild.gradle:
test- Runs tests and captures Serenity dataaggregate- Generates HTML reports from test resultscheckOutcomes- Verifies test results and fails the build if tests failed
Dependencies
The framework includes four core Serenity dependencies:Dependency Breakdown
Dependency Breakdown
serenity-core
- Core Serenity BDD functionality
- Report generation engine
- Screenshot capture
- Test lifecycle management
- Cucumber integration
- Gherkin step reporting
- Scenario outcome tracking
- Feature file requirements mapping
- Screenplay pattern implementation
- Actor, Task, and Question abstractions
- Ability management
- Consequence validation
- WebDriver-based Interactions
- Browser abilities (BrowseTheWeb)
- UI element interactions
- Page object utilities
Serenity Configuration
Build-level Configuration
Inbuild.gradle, the Serenity block configures report generation:
- testRoot - Base package for test scanning
- requirementsBaseDir - Location of feature files for requirements tracing
- reports - Report formats to generate (HTML in this case)
- finalizedBy(aggregate) - Automatically generates reports after tests run
Runtime Configuration (serenity.conf)
Thesrc/test/resources/serenity.conf file uses HOCON format for runtime settings:
take.screenshots
FOR_FAILURES - Only captures screenshots when tests fail, reducing report sizeOther options:
FOR_EACH_ACTION, BEFORE_AND_AFTER_EACH_STEP, DISABLEDtest.root
org.btg.practual - Root package for test discoveryEnsures Serenity correctly scans and reports all test classes
logging
QUIET - Minimal console output during test executionOther options:
VERBOSE, NORMALconsole.colors
true - Enables colored console output for better readabilityUseful for distinguishing pass/fail in terminal output
WebDriver Management
Selenium Manager Integration
Serenity 4.0.46 includes automatic WebDriver management:autodownload = true enables Selenium Manager, which automatically downloads and manages the correct ChromeDriver version for your installed Chrome browser. No manual driver management required!
Chrome Options Explained
- remote-allow-origins=* - Allows remote connections (required for newer Chrome versions)
- start-maximized - Opens browser in full-screen mode
- incognito - Runs in private browsing mode (clean state)
- disable-infobars - Removes “Chrome is being controlled” banner
- disable-gpu - Prevents GPU-related crashes in headless mode
- disable-dev-shm-usage - Fixes shared memory issues in Docker/CI environments
- no-sandbox - Required for running in containerized environments
Environment Management
Serenity supports multiple test environments through theenvironments block:
Report Generation
Automatic Report Creation
Reports are generated automatically after test execution:test.finalizedBy(aggregate) configuration ensures reports are created even if some tests fail.
Report Location
Serenity reports are generated in:Open
target/site/serenity/index.html in your browser to view the interactive test report.Report Features
Test Results Overview
High-level summary of test execution:
- Total scenarios executed
- Pass/fail/pending counts
- Execution time
- Success rate
Requirements Traceability
Maps tests to business requirements:
- Feature file linkage
- Coverage metrics
- Scenario grouping
- Tag-based filtering
Detailed Step Execution
Step-by-step test execution details:
- Each Gherkin step
- Execution duration
- Screenshots (on failure)
- Stack traces
Visual Evidence
Screenshots and artifacts:
- Failure screenshots
- Browser state capture
- Console logs
- Network activity
Serenity Reporter Integration
The Cucumber runner uses Serenity’s parallel reporter:- SerenityReporterParallel - Thread-safe reporter for parallel execution
- pretty - Formatted console output
- html:target/cucumber-report.html - Additional Cucumber HTML report
The Serenity reporter runs alongside Cucumber’s built-in reporters, capturing additional context for enhanced reporting.
Screenshot Capture
Screenshots are automatically captured based on configuration:Screenshot Strategies
| Strategy | Description | Use Case |
|---|---|---|
FOR_FAILURES | Only on test failures | Production (reduces report size) |
FOR_EACH_ACTION | After every interaction | Debugging complex scenarios |
BEFORE_AND_AFTER_EACH_STEP | Before/after each step | Detailed step verification |
DISABLED | No screenshots | Performance testing |
Test Execution Options
Thetest task is configured with Serenity-specific properties:
- useJUnitPlatform() - Enables JUnit 5 test execution
- systemProperties - Passes all system properties to tests
- serenity.project.name - Sets the project name in reports
- showStandardStreams - Displays console output during tests
Best Practices
Use Environment-Specific Configs
Define QA, STG, and PROD environments in
serenity.conf to avoid hardcoding URLs in test codeOptimize Screenshot Capture
Use
FOR_FAILURES in CI/CD to reduce report size and execution timeTag Your Scenarios
Use Cucumber tags (
@smoke, @regression, @test) to control which scenarios runReview Reports Regularly
Check Serenity reports for flaky tests, slow scenarios, and failure patterns
Learn more about implementing tests using the Screenplay Pattern or explore the Project Structure.