Created
June 21, 2023 08:15
-
-
Save stevenroh/b9c40a78c209aa690d18df5c741838a1 to your computer and use it in GitHub Desktop.
Playwright screenshot on failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { screenshotOnFailure } from './helper'; | |
test.afterEach(screenshotOnFailure); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { TestInfo } from '@playwright/test'; | |
export async function screenshotOnFailure({ page }: { page: Page }, testInfo: TestInfo) { | |
if (testInfo.status !== testInfo.expectedStatus) { | |
// Get a unique place for the screenshot. | |
const screenshotPath = testInfo.outputPath(`failure.png`); | |
// Add it to the report. | |
testInfo.attachments.push({ name: 'screenshot', path: screenshotPath, contentType: 'image/png' }); | |
// Take the screenshot itself. | |
await page.screenshot({ path: screenshotPath, timeout: 5000 }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment