Setup Playwright
Learn how to set up Playwright 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 Playwright with the following command:
Terminal window npm init playwright@latestPick the following options:
- Do you want to use TypeScript or JavaScript?: TypeScript
- Where to put your end-to-end tests?: tests
- Add a GitHub Actions workflow?: true
- Install Playwright browsers?: true
This will create the basic Playwright folder structure and configuration files.
-
Install dotenv for environment variable management:
Terminal window npm install dotenv --save-dev
Configuration
Link to this sectionEnvironment variables
Link to this section-
Create a new
.envfile:Terminal window touch .env -
Add the following to the
.envfile using values from your test user and Kinde application:TEST_APP_URL=https://your-app-url.comTEST_USER_EMAIL=your-test-emailTEST_USER_PASSWORD=your-test-passwordKINDE_ISSUER_URL=https://your-subdomain.kinde.comKINDE_CLIENT_ID=your-kinde-client-idKINDE_CLIENT_SECRET=your-kinde-client-secretKinde Client Secret is required for confidential clients (backend applications). Public clients (SPAs, mobile apps) do not use a client secret. -
Add the
.envfile to your.gitignorefile:Terminal window echo ".env" >> .gitignore
Playwright configuration
Link to this sectionUpdate your playwright.config.ts file with the following basic configuration:
import { defineConfig, devices } from '@playwright/test';import * as dotenv from 'dotenv';import path from 'path';
dotenv.config({ path: path.resolve(__dirname, '.env') });
export default defineConfig({ testDir: './tests', fullyParallel: true, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, reporter: 'html',
use: { baseURL: process.env.TEST_APP_URL, trace: 'on-first-retry', },
projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'] }, }, ],});Project structure
Link to this sectionAfter setup, your project should have the following structure:
your-project/├── playwright.config.ts├── .env # Environment variables (gitignored)├── .gitignore├── tests/│ └── example.spec.ts # Example test file└── package.jsonBasic test example
Link to this sectionCreate your first test file to verify the setup:
import { test, expect } from '@playwright/test';
test('can visit the application', async ({ page }) => { await page.goto(process.env.TEST_APP_URL!); await expect(page).toHaveURL(new RegExp(new URL(process.env.TEST_APP_URL!).hostname));});Running tests
Link to this sectionInteractive mode (recommended for development)
Link to this sectionOpen Playwright in interactive mode:
npx playwright test --uiThis opens the Playwright Test UI 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 playwright testTroubleshooting
Link to this sectionPlaywright not found
Link to this sectionIf you get a “command not found” error, make sure Playwright is installed:
npm init playwright@latestBrowsers not installed
Link to this sectionInstall Playwright browsers:
npx playwright installEnvironment variables not loading
Link to this sectionMake sure .env exists and contains valid environment variables. You can also use environment variables directly:
TEST_APP_URL=https://your-app.com npx playwright testCross-origin errors
Link to this sectionWhen testing with Kinde, you’ll need to handle redirects properly. See the Test authentication flows guide for examples.
For additional troubleshooting or configuration guidance, refer to the official Playwright documentation.
Next steps
Link to this sectionNow that Playwright 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 authenticated features - Test authenticated features using saved session state
- Test backend APIs - Test backend APIs with refresh tokens