Testing with Cypress
Testing with Cypress requires the use of Testing Tokens to bypass various bot detection mechanisms that typically safeguard Clerk apps against malicious bots. Without Testing Tokens, you might encounter "Bot traffic detected" errors in your requests.
This guide will help you set up your environment for creating Clerk-authenticated tests with Cypress.
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 key 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 key.
- Paste your keys into your
.env.local
file.
Global setup
To set up Clerk with Cypress, call the clerkSetup()
function in your cypress.config.ts
file.
clerkSetup()
will retrieve a Testing Token once the test suite starts, making it available for all subsequent tests.
Use Clerk Testing Tokens
Now that Cypress is configured with Clerk, use the setupClerkTestingToken()
function in your tests to integrate the Testing Token. See the following example:
Feedback
Last updated on