Include screenshots in report test steps with playwright

Viewed 43

Friends, does anyone have the code that allows me to include the screenshots in the line I want and make this print be attached to the standard playwright report?

I'm using playwright with javascriptenter image description here npx plawright show-report

1 Answers

You can use page.screenshot() to capture the screenshot and use attach() to attach the captured screenshto the report like this:

  const screenshot = await page.screenshot();
  await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });
Related