👉🏽 | Want the quickest start to testing? Try this!
Make sure that you don't have anything running already on port 3000
(default dev server port for Docusaurus) first before you follow the script below.
# Change to website directory
$ cd bash
# Make sure you have Node.js v18+ and install dependencies
$ npm install
# Run the Playwright test
$ npm run tests
# View the Playwright generated HTML test report
$ npm run report
Serving HTML report at http://localhost:9323. Press Ctrl+C to quit.
🎭 And you're done!!!
What the Playwright command just did for you:
- Built the website for dev preview
- Start the dev server for Docusaurus (on port 3000)
- Launch the test runner to test against the dev server preview
- Print the summary of test results to console
- Generate an HTML report with more details on tests
- Launch the browser to preview the last-generated report.
👉🏽 | Want to view the test results? Check the reports
Before we look under the hood, let's take a quick look at what the report looks like and correlate it to what you will see in the basic test specification used at this time.
The landing page of the report gives you the summary:
- The number of tests run altogether (12) - with #passed, failed or skipped
- The numner of browsers tested on (3 color tags) - giving 4 tests per browser.
- The execution time for each test (likely different per browser, test case)
Clicking on any test row takes you to these details:
- Time taken in setup ("Before") and teardown ("After") - by fixture!
- Time taken to execute test step - with code details for step
👉🏽 | Want to view more detailed traces? Try this option!
The Playwright test runner is configured to capture deeper traces only on-first-retry
. This is because running traces adds non-trivial costs, even though it provides more fine grained trace data for debug.
But what if you want to debug this on the fly? Override it using CLI options:
# Run the tests with trace on
$ npx playwright test --trace on
# Launch browser to show this report
$ npx run report
What does this do to the generated reports? Now the details view gets a "Traces" section with richer visualizations. Also note how the time taken for tests is now significantly higher (see before/after steps). The data (zipfile) also adds storage requirements - both of which can add up quickly if run across all test cases and specifications, on a regular cadence (CI/CD).
Clicking on the trace gets you to a rich interactive viewer that shows you details on the time taken for each test step, along with a waterfall diagram (showing snapshots of the page at each interval of load time) - and tabs to explore the source, network conditions, call state and more.
For convenience, a copy of this has been cached in this repo under the website assets. If you run the dev server (e.g., with npm run start
) and visit the /playwright-trace endpoint] you should be able to explore this exact report interactively.
👉🏽 | Want to understand Playwright setup and configuration?
First, let's install Playwright. There are two options available:
- Use the commandline (CLI)
- Use the VS Code extension.
The guidelines are self-explanatory. The CLI option is faster for initial setup but we recommend installng the VS Code Extension for a better developer experience end-to-end. Once installed, you can use npx playwright --help
to get details on usage commands and options.
Next, let's understand the core files and structure of the project from the Playwright perspective. Note that this reflects our current structure, and not the initial scaffold from Playwright.
website/
.env # Local .env file used for config
.env.example # Example .env file to copy & customize
playwright.config.ts # Main Config File
playwright-report/ # Temporary: artifacts from reporter
test-results/ # Temporary: artificats from test runner
tests/ # Configured: as 'testDir' in config file
01-basic.spec.ts # Specification: actual tests spec
Of these, only the playwright.config.ts
and tests/*.spec.ts
files are mandatory at start. The "Temporary" folders are generated during the test run. And the .env
files are used only if you want to override defaults.
To understand how these work, check out the Developer Guide under the "/testing" path. While we will describe Playwright there in the context of the Contoso Real Estate app test suite, you can easily apply those insights to the test suite here.
👉🏽 | Want to understand the structure of a test specification?
🚧 TODO: Explain what test spec
format is, why locators matter, what fixtures are, and why we may need to configure or observe timeouts.
👉🏽 | Want to understand test configuration settings & overrides?
🚧 TODO: Explain what we are configuring, why we have .env
, why we activated webserver
and why we have timeouts in both test and webserver levels.
👉🏽 | Want a more interactive testing workflow? This is magical!
🚧 TODO: Explain what npm run test-ui
does in project
We can use this section to capture any gotchas or best practices for this test suite, as we learn more. Help us out by filing bugs, or using issues to start a discussion for new features, or request clarity around existing ones.
Want to file a bug, contribute code or content, or improve the documentation and training resources? Excellent!
- Read up on our guidelines for contributing.
- Check out open issues that could use help.
- File a new issue to start a related discussion.