---
title: Playwright Java
description: Learn how to integrate Allure with Playwright Java tests to capture browser actions as steps, screenshots, traces, and other artifacts in your HTML report.
---

# Getting started with Allure Playwright Java

[![Allure Playwright Java latest version](https://img.shields.io/maven-central/v/io.qameta.allure/allure-playwright?style=flat "allure-playwright")](https://mvnrepository.com/artifact/io.qameta.allure/allure-playwright)

Generate beautiful HTML reports using [Allure Report](https://allurereport.org/) and your [Playwright Java](https://playwright.dev/java/) tests.

## Setting up

Allure Playwright Java works alongside your test framework — set up [JUnit 5](/docs/junit5/) or [TestNG](/docs/testng/) first, then add the steps below.

To integrate Allure Playwright into your project, you need to:

1. Add Allure Playwright dependencies.
2. Set up the AspectJ weaving agent.
3. Specify a location for Allure results storage.

### Add Allure dependencies

**Maven:**
```xml
<!-- 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>
```

**Gradle (Kotlin):**
```kts
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")
}
```

**Gradle (Groovy):**
```groovy
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.

**Maven:**
```xml
<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>
```

**Gradle (Kotlin):**
```kts
tasks.test {
    doFirst {
        jvmArgs("-javaagent:${configurations["aspectjAgent"].singleFile}")
    }
}
```

**Gradle (Groovy):**
```groovy
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`:

**Maven:**
```properties
allure.results.directory=target/allure-results
```

**Gradle (Kotlin):**
```properties
allure.results.directory=build/allure-results
```

**Gradle (Groovy):**
```properties
allure.results.directory=build/allure-results
```

### Generate a report

After running your tests, convert the results into an HTML report using one of these commands:

- `allure generate` processes the test results and saves an HTML report into the `allure-report` directory. To view the report, use the `allure open` command.

- `allure serve` creates the same report as `allure 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:

```java
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 it
```

Values 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](/docs/playwright-java-configuration/#allureplaywrightparameters) to change this behavior.

Playwright action steps are nested under any enclosing Allure steps you define:

```java
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](#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()`](/docs/playwright-java-reference/#starttracing) (controlled by `allure.playwright.close.trace`). See [Trace capture](#trace-capture) for the full set of triggers; closing an individual `Page` does 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](/docs/playwright-java-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`:

```java
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:

```java
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](https://playwright.dev/java/docs/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:

```java
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 result
```

Tracing is also stopped and attached automatically when:

- The `BrowserContext` or `Browser` is closed while a test is active (controlled by `allure.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:

```java
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:

```java
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](/docs/how-it-works-environment-file/).

```properties
os.name=Linux
java.version=17.0.10
browser=chromium
playwright.version=1.60.0
```
