Testing with Playwright
Playwright is a well-established JavaScript testing framework. This guide aims to help you set up your environment for creating authenticated tests with Clerk. This guide will assume you're somewhat familiar with Clerk and Playwright.
Before diving in, you might want to start by visiting the Playwright starter for an example repo that tests a Clerk-powered application using Testing Tokens.
Install @clerk/testing
Clerk's testing package provides integration helpers for popular testing frameworks.
Set your API keys
Set your publishable and secret keys in your test runner, as the CLERK_PUBLISHABLE_KEY
and CLERK_SECRET_KEY
environment variables respectively.
Global setup
In your global setup file, call the clerkSetup
function:
clerkSetup
will obtain a Testing Token when your test suite starts, making it available for all subsequent tests to use.
Use setupClerkTestingToken
Then, in your tests use the setupClerkTestingToken
function to augment your requests with the token:
For more information, feedback or issues, visit the @clerk/testing
package.