End-to-End Testing
When it comes to writing end-to-end tests using the Stencil Playwright adapter, the best advice we can give is to leverage Playwright documentation. The adapter is set up in a way so that developers will use the same public APIs with as little Stencil nuances as possible.
Writing Tests
As far as writing the actual tests goes, the most important thing to be aware of for tests to run correctly is to import the test
function from
@stencil/playwright
, not directly from @playwright/test
:
// THIS IS CORRECT
import { test } from '@stencil/playwright';
// THIS IS NOT!!
// import { test } from '@playwright/test';
The adapter package extends Playwright's stock test
function to provide additional fixtures and handle nuances related to web component hydration. More
information is available in the API documentation.
Testing Patterns
page.goto()
The goto()
method allows tests to load a pre-defined HTML template. This pattern is great if a test file has many tests to execute that all use the same HTML code
or if additional script
or style
tags need to be included in the HTML. However, with this pattern, developers are responsible for defining the necessary script
tags pointing to the Stencil entry code (so all web components are correctly loaded and registered).
For the following snippets, we'll imagine this is the simplified file structure for a Stencil project:
stencil-project-root