Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take a screenshot of a full page with Playwright (visual comparison)?

I'm trying to capture a full page screenshot for visual regression with Playwright. Per their docs, it can be done like so:

import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
  await page.goto('https://playwright.dev');
  await expect(page).toHaveScreenshot();
});

This works great, the only problem is it will only take a screenshot of the viewport. Is it possible to capture a full page screenshot for visual comparison?

like image 514
Kode_12 Avatar asked Sep 05 '25 03:09

Kode_12


1 Answers

The answer is to include 'fullPage' optional property as part of the toHaveScreenshot() method:

import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
  await page.goto('https://playwright.dev');
  await expect(page).toHaveScreenshot({ fullPage: true });
});
like image 167
Kode_12 Avatar answered Sep 07 '25 21:09

Kode_12