Skip to content

Commit 4278bbb

Browse files
committed
Add screenshots after each test in the Allure reports
1 parent eb711ab commit 4278bbb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/test/java/com/serenitydojo/playwright/toolshop/contact/ContactFormTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void recordTrace(TestInfo testInfo, BrowserContext context) {
6060
@Story("Submitting a request")
6161
@DisplayName("Customers can use the contact form to contact us")
6262
@Test
63-
void completeForm() throws URISyntaxException {
63+
void completeForm(Page page) throws URISyntaxException {
6464
contactForm.setFirstName("Sarah-Jane");
6565
contactForm.setLastName("Smith");
6666
contactForm.setEmail("[email protected]");
@@ -70,6 +70,7 @@ void completeForm() throws URISyntaxException {
7070
Path fileToUpload = Paths.get(ClassLoader.getSystemResource("data/sample-data.txt").toURI());
7171
contactForm.setAttachment(fileToUpload);
7272

73+
recordScreenshot(page, "Submit form");
7374
contactForm.submitForm();
7475

7576
Assertions.assertThat(contactForm.getAlertMessage())

src/test/java/com/serenitydojo/playwright/toolshop/fixtures/RecordsAllureScreenshots.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
public interface RecordsAllureScreenshots {
1010
@AfterEach
1111
default void tearDown(Page page) {
12-
Allure.addAttachment("End of Test Screenshot", new ByteArrayInputStream(page.screenshot()));
12+
recordScreenshot(page,"End of Test Screenshot");
13+
}
14+
15+
default void recordScreenshot(Page page, String screenshotName) {
16+
Allure.addAttachment(screenshotName, new ByteArrayInputStream(page.screenshot()));
1317
}
1418
}

0 commit comments

Comments
 (0)