Here’s the code sample from our tutorial on how to take screenshots in Playwright

 

const { test } = require('@playwright/test');
test.describe('Screenshot', () => {
test.beforeEach(async ({ page }) => {
await page.goto('https://kitchen.applitools.com/ingredients/file-picker');
});
test('should take a screenshot', async ({ page }) => {
await page.screenshot({ path: './screenshots/screenshot.png' });
});
test('should take a screenshot after trying to upload a picture', async ({ page }) => {
await page.setInputFiles('#photo-upload', './fixtures/images/french-toast.jpg');
await page.screenshot({ path: './screenshots/screenshot-with-image.png' });
});
});
view raw screenshot.spec.js delivered with ❤ by emgithub

View on GitHub
Colby Fayock
Developer Advocate

Ready for the next generation of testing?

Get started today Schedule a demo