Udemy Playwright: Web Automation Testing From Zero to Hero: Difference between revisions

Jump to navigation Jump to search
m
Line 2,032: Line 2,032:


=== Visual Testing ===
=== Visual Testing ===
This is so cool! Simply call <code>await expect(locator).toHaveScreenshot(...)</code> on an element. The first run through creates screenshot(s) inside a subfolder from <code>tests</code> folder. Second run compares current actual with previously expected. If there's any significant differences they are saved to subfolders in the <code>test-results</code> folder, and the html reporter has a very nice way to see and compare snapshots.
You can control settings in the code
<nowiki>
    await expect(locator).toHaveScreenshot({maxDiffPixels:150, maxDiffPixelRatio: 0.01})</nowiki>
as well as in file <code>playwright.config.ts</code>
<nowiki>
export default defineConfig<TestOptions>({
  expect: {
    ...
    toMatchSnapshot: { maxDiffPixels: 50 },
  },
  ...</nowiki>
If you need to update a lot of snapshots use
<nowiki>
npx playwright test --update-snapshots</nowiki>
=== Playwright with Docker Container ===
=== Playwright with Docker Container ===
=== Github Actions and Argos CI ===
=== Github Actions and Argos CI ===

Navigation menu