Playwright
  • Introduction
    • Playwright With TS
  • Automation the right things with Playwright
  • Setup
    • Setting Up Your Environment
    • Typescript fundamental
    • Setup Playwright TS Project in VS code
    • Record and Playback with Code Generation using VS Code Playwright Extension
    • Record and Playback using Playwright Codegen with Inspector
  • Playwright config file
  • Implement Test Cases
    • Open Browser
    • Fake Geolocation
    • Form Authentication
    • Checkboxes
    • Dropdown
    • Hyperlink
    • Web Table
    • Drag Drop
    • Frame
    • Horizontal Slide
    • Context Click - Right Click
  • Hover
  • Take Screenshot
  • Automatic screenshots on failure:
  • Page Object Model
    • Understanding the Page Object Model pattern
  • Implementing POM with Login Page
  • Combine POM with Playwright Fixture
  • API Testing
    • API Docs
  • GET
  • API POST
  • PUT
  • DELETE
  • CI/CD And Reporting
    • Setup Allure Report
    • Run in Github Actions
  • Playwright & AI
    • Debug & Generate Playwright Tests with AI
Powered by GitBook
On this page

Take Screenshot

// Take a screenshot of the full page
await page.screenshot({ path: 'screenshot.png', fullPage: true });

// Take a screenshot of a specific element
await page.locator('.element').screenshot({ path: 'element.png' });

// Take a screenshot on test failure
test('visual test', async ({ page }) => {
  await page.goto('https://example.com' );
  try {
    await expect(page.locator('h1')).toHaveText('Expected Text');
  } catch (error) {
    await page.screenshot({ path: `failure-${test.info().title}.png` });
    throw error;
  }
});
PreviousHoverNextAutomatic screenshots on failure:

Last updated 15 days ago