Testing / Playwright Interview questions
How do you take a screenshot in Playwright?
The most direct way is calling screenshot() on the page or on a specific locator:
await page.screenshot({ path: 'full.png', fullPage: true }); await page.getByRole('heading').screenshot({ path: 'heading.png' });
The fullPage: true option captures the entire scrollable page rather than just the visible viewport, which is useful for visual review of long pages.
For test debugging, it's usually better to let the config handle it automatically: setting screenshot: 'only-on-failure' in playwright.config.ts captures a screenshot the moment a test fails, without cluttering successful runs, and it's attached to the HTML report automatically.
More Related questions...