End to End testing suite template using:
- Playwright https://playwright.dev/
- TypeScript https://www.typescriptlang.org/
- Jest https://jestjs.io/
We have created a sample Clerk app which showcases the existing example, so feel free to play around!
- Install the dependencies using
npm install
oryarn install
- Rename
.env.example
to.env
- Check out the test by running the
test
or thetest:debug
command - Have fun building something!
|- config # Configuration file/s
|- external # External system interactions e.g. Database
|- fixtures # Predefined fixture sets & their factory functions e.g. createSignupAttributes
|- pages # Sets of pages for our applications
|- tests # Here is the magic 🧙♂️
To start building something with the suite template:
- Read this brief document.
- Read the Pages README.
- Dig in the documentation of the tools as you see fit.
For the suite template we chose to follow the PageObjects pattern in order to encapsulate each pages internal structure and responsibilities inside its own highly cohesive class file.
That means that for each page we would define a new Page object for our needs. We should not confuse the Page objects we create with actual pages in the application. We can think of Pages as a lightweight concept of a view, which is the set of cohesive elements living under a known browser location.
For more on how we structure views internally see the pages README.
Playwright provides all the goodies of a selector engine, so as to make it really easy to target elements on the document. As a general guideline for querying inside our tests/Page objects:
- Prefer user-facing and rarely changing attributes like
roles
, inputtypes
etc. - Use
data-test-id
responsibly. - There is no one-size-fits-all.
Also you can take a look at Playwright's take on selection best practices.
Our test suit is configured to run using Jest as a testing framework and jest-playwright acting as the glue between Jest and Playwright.
jest-playwright has more than a couple of ways to configure the suite so please refer to the documentation.
In some cases, we might need to run a test with specific suite configurations e.g. only for a specific browser . For those cases we can use the it.jestPlaywrightConfig
wrapper which allows specific jest-playwright
options to be passed directly into the test.
Playwright provides a couple of great debugging capabilities at all levels. The ones that you will probably find most useful are:
- Setting the
PWDEBUG=1
environment variable before running the tests to attache the Playwright inspector. - Setting the
DEBUG=pw:api
environment variable to get the Playwright API logs in the console.
For more options take a look at https://playwright.dev/docs/debug