Skip to content
  • Testing
  • Playwright

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.

  • A test user and optionally a running test application.
  • Node.js version 20 or higher.

Installation for new projects

Link to this section
  1. Install Playwright with the following command:

    Terminal window
    npm init playwright@latest

    Pick 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.

  2. Install dotenv for environment variable management:

    Terminal window
    npm install dotenv --save-dev

Environment variables

Link to this section
  1. Create a new .env file:

    Terminal window
    touch .env
  2. Add the following to the .env file using values from your test user and Kinde 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-subdomain.kinde.com
    KINDE_CLIENT_ID=your-kinde-client-id
    KINDE_CLIENT_SECRET=your-kinde-client-secret
  3. Add the .env file to your .gitignore file:

    Terminal window
    echo ".env" >> .gitignore

Playwright configuration

Link to this section

Update your playwright.config.ts file with the following basic configuration:

playwright.config.ts
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 section

After 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.json

Basic test example

Link to this section

Create your first test file to verify the setup:

tests/auth.spec.ts
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));
});
Link to this section

Open Playwright in interactive mode:

Terminal window
npx playwright test --ui

This 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 section

Run tests in headless mode:

Terminal window
npx playwright test

Troubleshooting

Link to this section

Playwright not found

Link to this section

If you get a “command not found” error, make sure Playwright is installed:

Terminal window
npm init playwright@latest

Browsers not installed

Link to this section

Install Playwright browsers:

Terminal window
npx playwright install

Environment variables not loading

Link to this section

Make sure .env exists and contains valid environment variables. You can also use environment variables directly:

Terminal window
TEST_APP_URL=https://your-app.com npx playwright test

Cross-origin errors

Link to this section

When 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.

Now that Playwright is set up, you can proceed with: