Skip to content

Latest commit

 

History

History
43 lines (25 loc) · 2.53 KB

playwright_cheatsheet.md

File metadata and controls

43 lines (25 loc) · 2.53 KB

Debugging Playwright tests

VS Code Extension (simplest)

The Playwright Test for VSCode extension is the easiest way to run individual tests or test suites. It covers the vast majority of standard debugging use cases and supports debugging directly in VS Code.

You can run or debug tests from the side bar:

Note: the application will start automatically if it's not already running. This could take some time and doesn't provide a lot of output.

Screenshot showing VSCode Playwright extension

Or directly from the spec files (right-click for more options e.g. debug):

Screenshot showing extension in the file

Notice the useful options in the test side bar above:

  • Show browser for running tests in headed mode
  • Reveal test output for viewing test logs

Note: the extension can become unstable if there are compilation errors in the code.

Playwright CLI

Standard usage:

  • From root: pnpm exec playwright test -c ./test/e2e/playwright.config.ts [other options]
  • Or simply: pnpm run test-e2e [-- other options]

Tips:

  • test-e2e-report opens the latest HTML report with results, traces & screenshots (valuable for debugging after the fact)
  • await page.pause() acts as a breakpoint in --headed and --debug mode
  • Playwright's debugging inspector provides a toolkit for debugging Playwright locators. It is available in --debug mode or by using await page.pause() in --headed mode
  • Test for flakiness by running tests multiple times --repeat-each <N> and only running specific tests with test.only(...) or test.skip(...)

For a full list of options see the official docs.

Gotchas

  • For performance reasons, we persist user sessions in storageState.json files, so that we can reuse them across tests and test executions. These are automatically removed when starting the server and automatically created if they do not exist. If the sessions become invalid they can lead to peculiar test failures. Remove them with make clean-test.