Serenity BDD 5.2.2 Release Notes
February 2, 2026 ยท View on GitHub
Session Persistence, API Testing, Console Error Checking, and Failure Evidence Capture
This release adds powerful new capabilities to serenity-screenplay-playwright: session state persistence for faster tests, integrated API testing that shares browser authentication, console error checking to catch JavaScript issues, network request capture for debugging, and automatic failure evidence collection.
What's New
Session State Persistence
Save and restore browser session state (cookies, localStorage, sessionStorage) to speed up tests and share authenticated sessions across tests:
// Login once and save the session
alice.attemptsTo(
Navigate.to("https://myapp.com/login"),
Enter.theValue("user@example.com").into("#email"),
Enter.theValue("password").into("#password"),
Click.on(Button.withText("Login")),
SaveSessionState.toFile("authenticated-session")
);
// In other tests, restore the session and skip login
bob.attemptsTo(
RestoreSessionState.fromFile("authenticated-session"),
Navigate.to("https://myapp.com/dashboard")
);
// Bob is already logged in!
Session State API
| Interaction | Description |
|---|---|
SaveSessionState.toPath(path) | Save session to specific file path |
SaveSessionState.toFile(name) | Save to target/playwright/session-state/{name}.json |
RestoreSessionState.fromPath(path) | Restore session from specific file |
RestoreSessionState.fromFile(name) | Restore from default location |
Use cases:
- Skip login steps in tests (faster execution)
- Share authentication across test classes
- Create session fixtures for different user roles
- Test session expiration scenarios
API Testing Integration
Make API requests that share the browser's session context (cookies, authentication). This enables hybrid UI + API testing:
// Initialize browser context
alice.attemptsTo(Open.url("about:blank"));
// Make API requests
alice.attemptsTo(
APIRequest.post("https://api.example.com/users")
.withJsonBody(Map.of(
"name", "John Doe",
"email", "john@example.com"
))
.withHeader("Authorization", "Bearer token123")
);
// Query the response
int status = alice.asksFor(LastAPIResponse.statusCode());
Map<String, Object> json = alice.asksFor(LastAPIResponse.jsonBody());
API Request Methods
| Method | Description |
|---|---|
APIRequest.get(url) | GET request |
APIRequest.post(url) | POST request |
APIRequest.put(url) | PUT request |
APIRequest.patch(url) | PATCH request |
APIRequest.delete(url) | DELETE request |
APIRequest.head(url) | HEAD request |
Request Configuration
APIRequest.post(url)
.withJsonBody(object) // Set JSON body
.withBody(string) // Set string body
.withHeader(name, value) // Add header
.withQueryParam(name, value) // Add query parameter
.withContentType(type) // Set Content-Type
.withTimeout(ms) // Set timeout
.failOnStatusCode(true) // Fail on non-2xx
Response Questions
| Question | Return Type | Description |
|---|---|---|
LastAPIResponse.statusCode() | Integer | Response status code |
LastAPIResponse.ok() | Boolean | True if 2xx status |
LastAPIResponse.body() | String | Response body |
LastAPIResponse.jsonBody() | Map<String, Object> | Parsed JSON object |
LastAPIResponse.jsonBodyAsList() | List<Map<String, Object>> | Parsed JSON array |
LastAPIResponse.headers() | Map<String, String> | All response headers |
LastAPIResponse.header(name) | String | Specific header value |
LastAPIResponse.url() | String | Final URL after redirects |
API calls are recorded in Serenity reports with full request/response details, just like RestAssured.
Network Request Capture
Capture and analyze all network requests made during tests:
alice.attemptsTo(CaptureNetworkRequests.duringTest());
// Perform actions that trigger network requests
alice.attemptsTo(Navigate.to("https://myapp.com"));
// Query captured requests
List<CapturedRequest> all = alice.asksFor(NetworkRequests.all());
List<CapturedRequest> failed = alice.asksFor(NetworkRequests.failed());
List<CapturedRequest> apiCalls = alice.asksFor(NetworkRequests.toUrlContaining("/api/"));
int failedCount = alice.asksFor(NetworkRequests.failedCount());
Network Request Questions
| Question | Description |
|---|---|
NetworkRequests.all() | All captured requests |
NetworkRequests.count() | Total request count |
NetworkRequests.withMethod(method) | Filter by HTTP method |
NetworkRequests.toUrlContaining(text) | Filter by URL substring |
NetworkRequests.matching(pattern) | Filter by glob pattern |
NetworkRequests.failed() | Failed requests (4xx, 5xx, errors) |
NetworkRequests.failedCount() | Count of failed requests |
NetworkRequests.clientErrors() | 4xx status requests |
NetworkRequests.serverErrors() | 5xx status requests |
Automatic Failure Evidence Capture
When a test fails, Serenity Playwright now automatically captures and attaches diagnostic information to the report:
- Page Information: Current URL and page title
- Console Errors: All
console.error()andconsole.warn()messages - Failed Network Requests: Requests that returned 4xx/5xx or had network errors
Enable evidence capture:
@BeforeEach
void setup() {
alice.attemptsTo(
CaptureConsoleMessages.duringTest(),
CaptureNetworkRequests.duringTest()
);
}
Access evidence programmatically:
List<String> errors = PlaywrightFailureEvidence.getConsoleErrors(alice);
List<String> failed = PlaywrightFailureEvidence.getFailedRequests(alice);
Console Error Checking
Automatically fail tests when JavaScript errors occur with the new CheckConsole interaction:
alice.attemptsTo(
CaptureConsoleMessages.duringTest(),
// Perform user flow
Navigate.to("https://myapp.com/checkout"),
Enter.theValue("4111111111111111").into("#card"),
Click.on(Button.withText("Pay")),
// Fail if any JavaScript errors occurred
CheckConsole.forErrors()
);
CheckConsole Options
| Method | Description |
|---|---|
CheckConsole.forErrors() | Fail test if console errors found |
CheckConsole.forWarnings() | Fail test if console warnings found |
CheckConsole.forErrorsAndWarnings() | Fail test if errors OR warnings found |
CheckConsole.forErrors().andReportOnly() | Report to Serenity without failing |
The andReportOnly() mode is useful for documenting known issues or monitoring error trends without failing the build.
Console Message Reporting
Explicitly add console messages to your Serenity reports with ReportConsoleMessages:
alice.attemptsTo(
CaptureConsoleMessages.duringTest(),
// ... perform actions ...
// Add console errors and warnings to the report
ReportConsoleMessages.errorsAndWarnings()
);
ReportConsoleMessages Options
| Method | Description |
|---|---|
ReportConsoleMessages.all() | Report all console messages |
ReportConsoleMessages.errors() | Report only errors |
ReportConsoleMessages.warnings() | Report only warnings |
ReportConsoleMessages.errorsAndWarnings() | Report errors and warnings |
Example: Complete Hybrid Test
@Test
void shouldCreateUserViaApiAndVerifyInUi() {
// Setup
alice.attemptsTo(
CaptureNetworkRequests.duringTest(),
RestoreSessionState.fromFile("admin-session"),
Open.url("about:blank")
);
// Create user via API
alice.attemptsTo(
APIRequest.post("https://myapp.com/api/users")
.withJsonBody(Map.of("name", "New User", "role", "member"))
);
assertThat(alice.asksFor(LastAPIResponse.statusCode())).isEqualTo(201);
// Verify in UI
alice.attemptsTo(Navigate.to("https://myapp.com/admin/users"));
assertThat(alice.asksFor(Text.ofEach(".user-name")))
.contains("New User");
// Verify no failed requests
assertThat(alice.asksFor(NetworkRequests.failed())).isEmpty();
}
Maven Coordinates
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-playwright</artifactId>
<version>5.2.2</version>
<scope>test</scope>
</dependency>
Why This Matters
- Faster Tests: Session persistence eliminates redundant login steps
- Hybrid Testing: Combine UI and API testing with shared authentication
- Quality Assurance: Catch JavaScript errors automatically with
CheckConsole - Better Debugging: Network capture and failure evidence make troubleshooting easier
- Rich Reports: API calls and console messages appear in Serenity reports
- Production Parity: Test real authentication flows, then reuse sessions
Documentation
Full documentation is available at:
Full Changelog: https://github.com/serenity-bdd/serenity-core/compare/5.2.1...5.2.2