playwrightplaywright-test

Include screenshots in report test steps with playwright


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


Solution

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

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