Skip to content

Commit 4f88ad3

Browse files
committed
playwright: attach helpful screenshots on errors
Whenever an operation fails, it is nice to see what the current browser windows looked like. It really helps to diagnose failures better. The actual code is inspired by the comments at https://stackoverflow.com/questions/78020451/how-to-take-screenshot-on-failure Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 3b26ef6 commit 4f88ad3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/git-scm.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ const url = process.env.PLAYWRIGHT_TEST_URL
55
: 'https://git-scm.com/'
66
const isRailsApp = url === 'https://git-scm.com/'
77

8+
// Whenever a test fails, attach a screenshot to diagnose failures better
9+
test.afterEach(async ({ page }, testInfo) => {
10+
if (testInfo.status !== testInfo.expectedStatus) {
11+
const screenshotPath =
12+
testInfo.outputPath(`${testInfo.line}-${testInfo.column}-failure.png`)
13+
testInfo.attachments.push({
14+
name: 'screenshot',
15+
path: screenshotPath,
16+
contentType: 'image/png'
17+
})
18+
await page.screenshot({
19+
path: screenshotPath,
20+
timeout: 15000
21+
})
22+
}
23+
})
24+
825
async function pretendPlatform(page, browserName, userAgent, platform) {
926
if (browserName !== 'chromium') {
1027
await page.context().addInitScript({

0 commit comments

Comments
 (0)