Allure Playwright Java reference
These are the classes and methods you can use to integrate your Playwright Java tests with Allure.
AllurePlaywright
io.qameta.allure.playwright.AllurePlaywright
A utility class with static methods for registering Playwright objects, capturing browser artifacts, and managing the per-test Playwright state. All methods are thread-safe and safe to call when no Allure test is active.
register
AllurePlaywright.register(Page page)AllurePlaywright.register(BrowserContext context)
Register a Playwright Page or BrowserContext for automatic failure diagnostics. Registered objects are used as sources for screenshots, page source, and page log attachments when a test fails or is broken.
Registering a Page also registers its parent BrowserContext.
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 is performed on a page while a test is active. Explicit registration is only needed for objects created and used exclusively outside an active test (for example, in a @BeforeAll setup).
import io.qameta.allure.playwright.AllurePlaywright;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.Page;
Page page = browser.newContext().newPage();
AllurePlaywright.register(page);
BrowserContext context = browser.newContext();
AllurePlaywright.register(context);attachScreenshot
AllurePlaywright.attachScreenshot(String name, Page page)
Capture a screenshot of the given page and attach it to the current Allure test or step. This call does not produce an additional Allure step.
Pass null or an empty string as name to use the default attachment name Screenshot.
AllurePlaywright.attachScreenshot("Before submit", page);
AllurePlaywright.attachScreenshot(null, page); // attached as "Screenshot"attachPageSource
AllurePlaywright.attachPageSource(String name, Page page)
Capture the current HTML of the given page and attach it as a text/html attachment.
Pass null or an empty string as name to use the default attachment name Page source.
AllurePlaywright.attachPageSource("Page source", page);attachConsoleMessages
AllurePlaywright.attachConsoleMessages(String name, Page page)
Attach the console messages collected by the given page since it was created. Each message is formatted as [type] text (location). Empty output is not attached.
Pass null or an empty string as name to use the default attachment name Console messages.
AllurePlaywright.attachConsoleMessages("Browser console", page);attachPageErrors
AllurePlaywright.attachPageErrors(String name, Page page)
Attach the uncaught JavaScript errors collected by the given page since it was created. Each error is written on its own line as plain text. Empty output is not attached.
Pass null or an empty string as name to use the default attachment name Page errors.
AllurePlaywright.attachPageErrors("Page errors", page);attachTrace
AllurePlaywright.attachTrace(String name, Path traceZip)
Attach an existing Playwright trace archive (zip file) to the current Allure test or step.
Pass null or an empty string as name to use the default attachment name Playwright trace.
AllurePlaywright.attachTrace("Login trace", Path.of("trace.zip"));attachVideo
AllurePlaywright.attachVideo(String name, Path videoFile)
Attach an existing video file to the current Allure test or step. WebM files are attached with the video/webm media type; other extensions are attached as application/octet-stream.
Pass null or an empty string as name to use the default attachment name Playwright video.
AllurePlaywright.attachVideo("Test recording", Path.of("video.webm"));startTracing
AllurePlaywright.startTracing(BrowserContext context): TraceSessionAllurePlaywright.startTracing(String name, BrowserContext context): TraceSession
Start Playwright tracing on the given BrowserContext with screenshots and DOM snapshots enabled, and return a TraceSession that can stop and attach the trace.
The context is registered for failure diagnostics automatically.
Pass a name to control the attachment name. The default name is Playwright trace.
Use try-with-resources to guarantee that tracing is stopped and the archive is attached even if the test throws:
try (TraceSession trace = AllurePlaywright.startTracing("Checkout trace", context)) {
page.navigate("https://example.com");
page.click("#checkout");
}If the context is closed before TraceSession.close() is called, the trace is still attached automatically. If the test ends while the session is still open, the trace is attached before the test result is written.
beforeTest
AllurePlaywright.beforeTest()
Clear the Playwright registry before a test starts. Call this at the start of each test when no Allure framework integration is managing the lifecycle automatically.
Any open trace sessions present at this point are stopped without attaching.
afterTest
AllurePlaywright.afterTest()
Attach pending console messages, page errors, and open trace sessions for registered pages and contexts, then clear the Playwright registry. Call this at the end of each test when no Allure framework integration is managing the lifecycle automatically.
Videos are attached when page.close(), context.close(), or browser.close() is called, not by this method.
afterTestFailure
AllurePlaywright.afterTestFailure()AllurePlaywright.afterTestFailure(Throwable throwable)
Attach failure diagnostics — screenshots, page source, and open trace sessions — for all registered pages. This is called once per test; duplicate calls within the same test are ignored.
Call this from your failure handler or @AfterEach equivalent when no Allure framework integration is managing the lifecycle automatically. The Throwable overload accepts the causing exception for debug logging.
// In an @AfterEach or equivalent
try {
testBody.run();
} catch (Throwable t) {
AllurePlaywright.afterTestFailure(t);
throw t;
} finally {
AllurePlaywright.afterTest();
}TraceSession
io.qameta.allure.playwright.TraceSession
Represents an active Playwright trace session started by AllurePlaywright.startTracing(). Implements AutoCloseable.
attach
TraceSession.attach()
Stop the trace and attach the generated archive to the current Allure test or step. Equivalent to close().
close
TraceSession.close()
Stop the trace and attach the generated archive to the current Allure test or step. Use try-with-resources to call this automatically:
try (TraceSession trace = AllurePlaywright.startTracing(context)) {
// browser actions
}