E2E Testing Flows with Playwright
Welcome to the guide on testing Descope flows with Playwright.
Note
This guide covers creating test users manually for testing; however, you can also see our Dynamic Test Users Configuration guide if you would like the ability to create test users dynamically as part of the sign-up-or-in process.
Playwright Installation
Make sure you have Playwright already installed within your application. If not, you can do so here.
Descope Application Setup
To get started with Descope, an application needs to be setup within the Descope Console via the following steps:
- Visit the Descope Console and create a new project.
- Enter the desired name for your application.
- Get your
projectId
found inSettings/Project
, and create amanagementKey
, found inSettings/Company/Management Keys/+ Mangement Key
Global Setup and Teardown for Descope Authentication
Configuration
First, you'll need a general configuration file to setup Playwright testing. Create a playwright.config.ts
in the root directory.
Setup for Authentication
To have access to test user credentials within our tests we need to configure Playwright to use the Descope environment variables set in the .env
file.
Make sure the corresponding environment variables exist in your .env
file
Teardown after Testing
Create a e2e/auth.teardown.ts
script to clean up test users and reset the state:
Implementing Tests with Authenticated State
With the global setup and teardown scripts handling authentication, your tests can focus on the application's functionality:
Running Playwright tests
Simply execute the following command to run tests
Note
If you don't already have playwright installed, you'll need to install it using the following command: npx playwright install
. If you're on a linux/mac system, you might also need to run npx playwright install msedge
to run the Microsoft Edge tests locally, from the root user.
That's it! To see a full example of setting up e2e tests with Playwright and Descope, check out the Descope Playwright React Example.
Notes
WebAuthn Support
If you are looking to test with WebAuthn, you may need to set up a virtual authenticator. This can be done as follows: