Testing with Playwright
Playwright is an open-source, end-to-end testing framework that automates web application testing across multiple browsers. This guide will help you set up your environment for creating authenticated tests with Clerk, assuming you have some familiarity with both Clerk and Playwright.
Install @clerk/testing
Clerk's testing package provides integration helpers for popular testing frameworks. Run the following command to install it:
Set your API keys
In your test runner, set your Publishable and Secret Keys as the CLERK_PUBLISHABLE_KEY
and CLERK_SECRET_KEY
environment variables, respectively.
To find your keys:
- In the Clerk Dashboard, navigate to the API keys page.
- In the Quick Copy section, copy your Clerk Publishable and Secret Keys.
Configure Playwright with Clerk
The clerkSetup()
function obtains a Testing Token when your test suite starts, making it available for all subsequent tests to use. This ensures that you don't have to manually generate a Testing Token for each test.
To configure Playwright with Clerk, call the clerkSetup()
function in your global setup file, as shown in the following example:
Use setupClerkTestingToken()
Now that Playwright is configured with Clerk, you can use the setupClerkTestingToken()
function to include the Testing Token in individual test cases. This function injects the Testing Token for the specific test, ensuring the test can bypass Clerk's bot detection mechanisms. See the following example:
Feedback
Last updated on