Setup Cypress
Learn how to set up Cypress for testing applications using Kinde authentication. This guide covers installation, configuration, and basic setup for end-to-end testing.
What you need
Link to this sectionInstallation for new projects
Link to this section-
Install Cypress with the following command:
Terminal window npm install cypress --save-dev -
Run the following command. The Cypress configuration wizard opens:
Terminal window npx cypress open- Select E2E Testing and select Continue.
- Select Start E2E Testing in Chrome. This will open the Cypress Test Runner.
- Select Create new spec. In the pop-up that opens, select Create spec
- Select Okay, run the spec
This will create a basic test file in the
cypress/e2efolder. -
Close the Cypress Test Runner.
Configuration
Link to this sectionEnvironment variables
Link to this section-
Create or update the Cypress env file:
Terminal window touch cypress.env.json -
Add the following to the
cypress.env.jsonfile using values from your test user and application:{"TEST_APP_URL": "https://your-app-url.com","TEST_USER_EMAIL": "your-test-email","TEST_USER_PASSWORD": "your-test-password","KINDE_ISSUER_URL": "https://your_kinde_domain.kinde.com","KINDE_CLIENT_ID": "your-kinde-client-id","KINDE_CLIENT_SECRET": "your-kinde-client-secret"}Kinde Client Secret is required for confidential clients (backend applications). Public clients (SPAs, mobile apps) do not use a client secret. -
Create a
.gitignorefile and add the environment file to it:Terminal window touch .gitignoreecho "cypress.env.json" >> .gitignore
Cypress configuration
Link to this sectionUpdate your cypress.config.js file with the following basic configuration:
const { defineConfig } = require("cypress");
module.exports = defineConfig({ e2e: { baseUrl: 'http://localhost:3000', setupNodeEvents(on, config) { // implement node event listeners here }, },});Project structure
Link to this sectionAfter setup, your project should have the following structure:
your-project/├── cypress.config.js├── cypress.env.json # Environment variables (gitignored)├── cypress/│ ├── e2e/│ │ └── spec.cy.js # Example test file│ ├── fixtures/ # Test data│ └── support/│ ├── commands.js # Custom commands│ └── e2e.js # Support file└── package.jsonBasic test example
Link to this sectionCreate your first test file to verify the setup:
describe('Authentication', () => { it('can visit the application', () => { cy.visit(Cypress.env('TEST_APP_URL')) cy.url().should('include', new URL(Cypress.env('TEST_APP_URL')).hostname) })})Running tests
Link to this sectionInteractive mode (recommended for development)
Link to this sectionOpen Cypress in interactive mode:
npx cypress openThis opens the Cypress Test Runner where you can:
- Select a browser
- See tests run in real-time
- Debug tests interactively
Headless mode (for CI/CD)
Link to this sectionRun tests in headless mode:
npx cypress runTroubleshooting
Link to this sectionCypress not found
Link to this sectionIf you get a “command not found” error, make sure Cypress is installed locally:
npm install cypress --save-devEnvironment variables not loading
Link to this sectionMake sure cypress.env.json exists and contains valid JSON. You can also use environment variables directly:
CYPRESS_TEST_APP_URL=https://your-app.com npx cypress openCross-origin errors
Link to this sectionWhen testing with Kinde, you’ll need to use cy.origin() for cross-origin requests.
For additional troubleshooting or configuration guidance, refer to the official Cypress documentation.
Next steps
Link to this sectionNow that Cypress is set up, you can proceed with:
- Test Authentication Flows - Learn how to test sign-up, sign-in, and sign-out flows
- Test Passwordless Flows - Test passwordless authentication with email OTP
- Test Auth Features - Test authenticated features using session state
- Test Backend APIs - Test backend APIs with refresh tokens