Getting started with Allure Playwright Java
Generate beautiful HTML reports using Allure Report and your Playwright Java tests.
Setting up
Allure Playwright Java works alongside your test framework — set up JUnit 5 or TestNG first, then add the steps below.
To integrate Allure Playwright into your project, you need to:
- Add Allure Playwright dependencies.
- Set up the AspectJ weaving agent.
- Specify a location for Allure results storage.
Add Allure dependencies
<!-- Define the version of Allure you want to use via the allure.version property -->
<properties>
<allure.version>VERSION</allure.version>
<aspectj.version>1.9.25.1</aspectj.version>
</properties>
<!-- Add allure-bom to dependency management to ensure correct versions of all the dependencies are used -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-bom</artifactId>
<version>${allure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Add necessary Allure dependencies to dependencies section -->
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-playwright</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>val allureVersion = "VERSION"
val aspectjVersion = "1.9.25.1"
val aspectjAgent: Configuration by configurations.creating
dependencies {
testImplementation(platform("io.qameta.allure:allure-bom:$allureVersion"))
testImplementation("io.qameta.allure:allure-playwright")
testRuntimeOnly("org.aspectj:aspectjrt:$aspectjVersion")
aspectjAgent("org.aspectj:aspectjweaver:$aspectjVersion")
}def allureVersion = "VERSION"
def aspectjVersion = "1.9.25.1"
configurations {
aspectjAgent
}
dependencies {
testImplementation platform("io.qameta.allure:allure-bom:$allureVersion")
testImplementation "io.qameta.allure:allure-playwright"
testRuntimeOnly "org.aspectj:aspectjrt:$aspectjVersion"
aspectjAgent "org.aspectj:aspectjweaver:$aspectjVersion"
}Set up the AspectJ agent
Allure Playwright uses AspectJ to intercept Playwright API calls at runtime and record them as Allure steps. The AspectJ weaver must be attached to the JVM when tests run.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>tasks.test {
doFirst {
jvmArgs("-javaagent:${configurations["aspectjAgent"].singleFile}")
}
}test {
doFirst {
jvmArgs "-javaagent:${configurations.aspectjAgent.singleFile}"
}
}Specify Allure results location
Allure saves test results in the project's root directory by default. It is recommended to store results in the build output directory instead.
Create an allure.properties file in src/test/resources:
allure.results.directory=target/allure-resultsallure.results.directory=build/allure-resultsallure.results.directory=build/allure-resultsGenerate a report
After running your tests, convert the results into an HTML report using one of these commands:
allure generateprocesses the test results and saves an HTML report into theallure-reportdirectory. To view the report, use theallure opencommand.allure servecreates the same report asallure generate, then automatically opens the main page of the report in a web browser.
Browser actions as steps
With the AspectJ agent active, Allure Playwright automatically intercepts calls to the Playwright Java API and records them as steps in the test report. No additional code is required.
The following Playwright types are intercepted:
Page,Frame,Locator,ElementHandle— browser interaction methods- Playwright assertion classes —
assertThat(...)assertions
Step names are generated from the method name and its arguments. For example:
page.click("button"); // → "Click button"
page.navigate("https://example.com"); // → "Navigate to https://example.com"
page.hover(".menu-item"); // → "Hover .menu-item"
page.fill("#search", "query"); // → "Fill #search with <redacted>"
page.type("#comment", "text"); // → "Type <redacted> into #comment"
page.screenshot(); // → "Take screenshot" step, with a "Screenshot" attachment inside itValues passed to fill(), type(), and press() are replaced with <redacted> in step names by default to avoid exposing passwords and other sensitive data. See configuration to change this behavior.
Playwright action steps are nested under any enclosing Allure steps you define:
Allure.step("Checkout flow", () -> {
page.click("button"); // appears as a sub-step of "Checkout flow"
});By default, only recognized browser interaction methods (click, fill, navigate, hover, check, type, dragTo, waitForSelector, and more) and Playwright assertions are recorded as steps. To record every public Playwright API method call, set allure.playwright.steps.mode=all in allure.properties.
Capturing browser artifacts
Allure Playwright captures browser artifacts automatically and also provides helpers for manual capture.
On test failure
When a test fails or is broken, Allure Playwright automatically captures a screenshot and the current page source for each registered page, and attaches them to the test result.
This requires pages or contexts to be registered, either explicitly or automatically (see Registering pages and contexts).
On close
When a Page, BrowserContext, or Browser is closed while a test is active, Allure Playwright automatically collects:
- Console messages — browser console output accumulated since the page was created (controlled by
allure.playwright.close.page-logs). - Page errors — uncaught JavaScript exceptions (controlled by
allure.playwright.close.page-logs). - Video — if the context was created with video recording enabled (controlled by
allure.playwright.close.video). - Trace — if tracing was started with
AllurePlaywright.startTracing()(controlled byallure.playwright.close.trace). See Trace capture for the full set of triggers; closing an individualPagedoes not trigger trace attachment.
Console messages and page errors are also captured when the test ends for any registered pages whose context was not explicitly closed during the test.
See configuration for details on each setting.
Manual capture
You can capture and attach any of these artifacts at any point during a test using the static helpers on AllurePlaywright:
import io.qameta.allure.playwright.AllurePlaywright;
// Attach a screenshot of the current page state
AllurePlaywright.attachScreenshot("Before submit", page);
// Attach the current page HTML
AllurePlaywright.attachPageSource("Page source", page);
// Attach console messages collected by the page
AllurePlaywright.attachConsoleMessages("Browser console", page);
// Attach uncaught JavaScript errors
AllurePlaywright.attachPageErrors("Page errors", page);
// Attach an existing trace archive
AllurePlaywright.attachTrace("Playwright trace", Path.of("trace.zip"));
// Attach an existing video file
AllurePlaywright.attachVideo("Test recording", Path.of("video.webm"));All helpers are safe to call when no Allure test is active — they do nothing in that case.
Registering pages and contexts
Allure Playwright tracks registered pages and contexts and uses them to capture screenshots, page source, console messages, and page errors when a test fails.
When AspectJ weaving is active, pages and contexts are registered automatically in two ways: when created via browser.newPage(), browser.newContext(), or context.newPage(); and when any intercepted Playwright action (such as click or fill) is performed on a page while a test is active. Auto-registration only applies while a test is active; objects created and used exclusively before the test starts, such as in a @BeforeAll setup, must be registered explicitly.
For pages or contexts created outside of Playwright's standard factory methods, or outside an active test, register them explicitly:
AllurePlaywright.register(page);
AllurePlaywright.register(context);Registering a Page also registers its parent BrowserContext.
Trace capture
Playwright traces record browser activity as a rich archive that can be opened in the Playwright Trace Viewer. Allure Playwright can start a trace and attach the resulting archive automatically.
Use AllurePlaywright.startTracing() to begin tracing a browser context. The returned TraceSession stops tracing and attaches the archive when closed:
import io.qameta.allure.playwright.AllurePlaywright;
import io.qameta.allure.playwright.TraceSession;
BrowserContext context = browser.newContext();
try (TraceSession trace = AllurePlaywright.startTracing(context)) {
// run browser actions
}
// trace archive is now attached to the test resultTracing is also stopped and attached automatically when:
- The
BrowserContextorBrowseris closed while a test is active (controlled byallure.playwright.close.trace). - The test fails while a trace is still open (always, regardless of
allure.playwright.close.trace). - The test ends while a trace is still open (controlled by
allure.playwright.close.trace).
To assign a custom name to the trace attachment, use the overload that accepts a name:
TraceSession trace = AllurePlaywright.startTracing("Login flow trace", context);Framework lifecycle integration
When allure-playwright is on the classpath alongside any Allure framework integration, lifecycle integration is configured automatically — no additional setup is needed.
For test frameworks without an Allure integration, call the following methods in your test setup and teardown. beforeTest() must run before the test body, and afterTest() must run after it — typically in a @BeforeEach/@AfterEach pair. Detecting failure requires intercepting the test body exception before it propagates:
import io.qameta.allure.playwright.AllurePlaywright;
// Before the test body runs (@BeforeEach or equivalent)
AllurePlaywright.beforeTest();
// Wrap the test body execution to detect failure:
try {
// test body
} catch (Throwable t) {
AllurePlaywright.afterTestFailure(t);
throw t;
} finally {
AllurePlaywright.afterTest();
}Environment information
For the main page of the report, you can collect various information about the environment in which the tests were executed.
To provide environment information, put a file named environment.properties into the allure-results directory after running the tests. See the example in Environment file.
os.name=Linux
java.version=17.0.10
browser=chromium
playwright.version=1.60.0