Skip to content

Commit 621d24c

Browse files
authored
Add Allure reporting for Playwright Java (via #1269)
1 parent d1da0de commit 621d24c

16 files changed

Lines changed: 2269 additions & 1 deletion

File tree

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,69 @@ SelenideLogger.addListener("AllureSelenide", new AllureSelenide().enableLogs(Log
7777
https://github.com/SeleniumHQ/selenium/wiki/Logging
7878
```
7979

80-
80+
## Playwright Java
81+
82+
AspectJ-based integration for Playwright Java that reports browser actions as Allure steps and attaches
83+
Playwright screenshots automatically:
84+
85+
```xml
86+
<dependency>
87+
<groupId>io.qameta.allure</groupId>
88+
<artifactId>allure-playwright</artifactId>
89+
<version>$LATEST_VERSION</version>
90+
</dependency>
91+
```
92+
93+
Enable the AspectJ weaver for automatic action steps:
94+
```
95+
-javaagent:/path/to/aspectjweaver.jar
96+
```
97+
98+
Usage example with Playwright Java JUnit fixtures:
99+
```java
100+
@UsePlaywright
101+
class UiTest {
102+
103+
@Test
104+
void shouldOpenPage(Page page) {
105+
page.navigate("https://playwright.dev");
106+
page.screenshot();
107+
}
108+
}
109+
```
110+
111+
The module registers an Allure test lifecycle listener automatically, so per-test cleanup, failure diagnostics,
112+
and final trace/log flush work with any test framework that reports through Allure. Playwright pages and
113+
contexts are tracked by the AspectJ integration when they are created or used. Use
114+
`AllurePlaywright.register(...)` only for pages or contexts the aspect cannot observe.
115+
116+
Frameworks or custom runners that do not use the Allure lifecycle can call the reporting hooks directly:
117+
```java
118+
AllurePlaywright.beforeTest();
119+
try {
120+
testBody();
121+
} catch (Throwable e) {
122+
AllurePlaywright.afterTestFailure(e);
123+
throw e;
124+
} finally {
125+
AllurePlaywright.afterTest();
126+
}
127+
```
128+
129+
The following defaults can be overridden in `allure.properties`:
130+
```
131+
allure.playwright.steps.enabled=true
132+
allure.playwright.steps.mode=actions
133+
allure.playwright.parameters=redacted
134+
allure.playwright.screenshots.attach=true
135+
allure.playwright.failure.screenshot=true
136+
allure.playwright.failure.page-source=true
137+
allure.playwright.close.trace=true
138+
allure.playwright.close.video=true
139+
allure.playwright.close.page-logs=true
140+
```
141+
142+
81143
## Rest Assured
82144

83145
Filter for rest-assured http client, that generates attachment for allure.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.model;
17+
18+
/**
19+
* Common attachment media types and file extensions.
20+
*/
21+
public final class AttachmentType {
22+
23+
public static final AttachmentType PNG = new AttachmentType("image/png", "png");
24+
public static final AttachmentType JPEG = new AttachmentType("image/jpeg", "jpg");
25+
public static final AttachmentType TEXT = new AttachmentType("text/plain", "txt");
26+
public static final AttachmentType HTML = new AttachmentType("text/html", "html");
27+
public static final AttachmentType ZIP = new AttachmentType("application/zip", "zip");
28+
public static final AttachmentType WEBM = new AttachmentType("video/webm", "webm");
29+
public static final AttachmentType OCTET_STREAM = new AttachmentType("application/octet-stream", "");
30+
31+
private final String mediaType;
32+
private final String extension;
33+
34+
private AttachmentType(final String mediaType, final String extension) {
35+
this.mediaType = mediaType;
36+
this.extension = extension;
37+
}
38+
39+
public String getMediaType() {
40+
return mediaType;
41+
}
42+
43+
public String getExtension() {
44+
return extension;
45+
}
46+
}

allure-playwright/build.gradle.kts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
description = "Allure Playwright Integration"
2+
3+
val agent: Configuration by configurations.creating
4+
5+
val playwrightVersion = "1.59.0"
6+
7+
dependencies {
8+
agent("org.aspectj:aspectjweaver")
9+
api(project(":allure-java-commons"))
10+
compileOnly("com.microsoft.playwright:playwright:$playwrightVersion")
11+
compileOnly("org.aspectj:aspectjrt")
12+
testAnnotationProcessor(project(":allure-descriptions-javadoc"))
13+
testImplementation("com.microsoft.playwright:playwright:$playwrightVersion")
14+
testImplementation("org.assertj:assertj-core")
15+
testImplementation("org.junit.jupiter:junit-jupiter-api")
16+
testImplementation("org.slf4j:slf4j-simple")
17+
testImplementation(project(":allure-assertj"))
18+
testImplementation(project(":allure-java-commons-test"))
19+
testImplementation(project(":allure-junit-platform"))
20+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
21+
}
22+
23+
tasks.jar {
24+
manifest {
25+
attributes(mapOf(
26+
"Automatic-Module-Name" to "io.qameta.allure.playwright"
27+
))
28+
}
29+
}
30+
31+
tasks.test {
32+
useJUnitPlatform()
33+
doFirst {
34+
jvmArgs("-javaagent:${agent.singleFile}")
35+
}
36+
}

0 commit comments

Comments
 (0)