Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

setup playwright for e2e

ThieryMichel663c11d8cc26
diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml
new file mode 100644
index 00000000..3eb13143
--- /dev/null
+++ b/.github/workflows/playwright.yml
@@ -0,0 +1,27 @@
+name: Playwright Tests
+on:
+ push:
+ branches: [ main, master ]
+ pull_request:
+ branches: [ main, master ]
+jobs:
+ test:
+ timeout-minutes: 60
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: lts/*
+ - name: Install dependencies
+ run: npm ci
+ - name: Install Playwright Browsers
+ run: npx playwright install --with-deps
+ - name: Run Playwright tests
+ run: npx playwright test
+ - uses: actions/upload-artifact@v4
+ if: ${{ !cancelled() }}
+ with:
+ name: playwright-report
+ path: playwright-report/
+ retention-days: 30
diff --git a/.gitignore b/.gitignore
index 993d30b1..218571ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,3 +39,11 @@ public/r/
!supabase/functions/.env
.claude/settings.local.json
+
+# Playwright
+node_modules/
+/test-results/
+/playwright-report/
+/blob-report/
+/playwright/.cache/
+/playwright/.auth/
diff --git a/e2e/example.spec.ts b/e2e/example.spec.ts
new file mode 100644
index 00000000..54a906a4
--- /dev/null
+++ b/e2e/example.spec.ts
@@ -0,0 +1,18 @@
+import { test, expect } from '@playwright/test';
+
+test('has title', async ({ page }) => {
+ await page.goto('https://playwright.dev/');
+
+ // Expect a title "to contain" a substring.
+ await expect(page).toHaveTitle(/Playwright/);
+});
+
+test('get started link', async ({ page }) => {
+ await page.goto('https://playwright.dev/');
+
+ // Click the get started link.
+ await page.getByRole('link', { name: 'Get started' }).click();
+
+ // Expects page to have a heading with the name of Installation.
+ await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
+});
diff --git a/makefile b/makefile
index 1eba0efb..cffb5216 100644
--- a/makefile
+++ b/makefile
@@ -60,6 +60,12 @@ test-functions:
test-integration:
npm run test:integration
+test-e2e:
+ npx playwright test --ui
+
+test-e2e-ci:
+ CI=1 npx playwright test
+
lint:
npm run lint
npm run prettier
diff --git a/package-lock.json b/package-lock.json
index e31dcdca..94b8f794 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -80,6 +80,7 @@
"devDependencies": {
"@eslint/js": "^9.22.0",
"@inquirer/prompts": "^8.2.0",
+ "@playwright/test": "^1.58.2",
"@storybook/react-vite": "^9.1.19",
"@types/dompurify": "^3.0.5",
"@types/faker": "^5.5.9",
@@ -101,7 +102,7 @@
"glob": "^11.1.0",
"globals": "^16.3.0",
"husky": "^9.1.7",
- "playwright": "^1.55.0",
+ "playwright": "^1.58.2",
"prettier": "^3.6.2",
"shadcn": "^3.5.0",
"storybook": "^9.1.19",
@@ -5382,6 +5383,22 @@
"node": ">=14"
}
},
+ "node_modules/@playwright/test": {
+ "version": "1.58.2",
+ "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.2.tgz",
+ "integrity": "sha512-akea+6bHYBBfA9uQqSYmlJXn61cTa+jbO87xVLCWbTqbWadRVmhxlXATaOjOgcBaWU4ePo0wB41KMFv3o35IXA==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright": "1.58.2"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
"node_modules/@polka/url": {
"version": "1.0.0-next.29",
"resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz",
diff --git a/package.json b/package.json
index 08edbb6a..3eee5e60 100644
--- a/package.json
+++ b/package.json
@@ -97,6 +97,7 @@
"devDependencies": {
"@eslint/js": "^9.22.0",
"@inquirer/prompts": "^8.2.0",
+ "@playwright/test": "^1.58.2",
"@storybook/react-vite": "^9.1.19",
"@types/dompurify": "^3.0.5",
"@types/faker": "^5.5.9",
@@ -118,7 +119,7 @@
"glob": "^11.1.0",
"globals": "^16.3.0",
"husky": "^9.1.7",
- "playwright": "^1.55.0",
+ "playwright": "^1.58.2",
"prettier": "^3.6.2",
"shadcn": "^3.5.0",
"storybook": "^9.1.19",
diff --git a/playwright.config.ts b/playwright.config.ts
new file mode 100644
index 00000000..dfe72abf
--- /dev/null
+++ b/playwright.config.ts
@@ -0,0 +1,79 @@
+import { defineConfig, devices } from '@playwright/test';
+
+/**
+ * Read environment variables from file.
+ * https://github.com/motdotla/dotenv
+ */
+// import dotenv from 'dotenv';
+// import path from 'path';
+// dotenv.config({ path: path.resolve(__dirname, '.env') });
+
+/**
+ * See https://playwright.dev/docs/test-configuration.
+ */
+export default defineConfig({
+ testDir: './e2e',
+ /* Run tests in files in parallel */
+ fullyParallel: true,
+ /* Fail the build on CI if you accidentally left test.only in the source code. */
+ forbidOnly: !!process.env.CI,
+ /* Retry on CI only */
+ retries: process.env.CI ? 2 : 0,
+ /* Opt out of parallel tests on CI. */
+ workers: process.env.CI ? 1 : undefined,
+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
+ reporter: 'html',
+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
+ use: {
+ /* Base URL to use in actions like `await page.goto('')`. */
+ // baseURL: 'http://localhost:3000',
+
+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
+ trace: 'on-first-retry',
+ },
+
+ /* Configure projects for major browsers */
+ projects: [
+ {
+ name: 'chromium',
+ use: { ...devices['Desktop Chrome'] },
+ },
+
+ {
+ name: 'firefox',
+ use: { ...devices['Desktop Firefox'] },
+ },
+
+ {
+ name: 'webkit',
+ use: { ...devices['Desktop Safari'] },
+ },
+
+ /* Test against mobile viewports. */
+ // {
+ // name: 'Mobile Chrome',
+ // use: { ...devices['Pixel 5'] },
+ // },
+ // {
+ // name: 'Mobile Safari',
+ // use: { ...devices['iPhone 12'] },
+ // },
+
+ /* Test against branded browsers. */
+ // {
+ // name: 'Microsoft Edge',
+ // use: { ...devices['Desktop Edge'], channel: 'msedge' },
+ // },
+ // {
+ // name: 'Google Chrome',
+ // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
+ // },
+ ],
+
+ /* Run your local dev server before starting the tests */
+ // webServer: {
+ // command: 'npm run start',
+ // url: 'http://localhost:3000',
+ // reuseExistingServer: !process.env.CI,
+ // },
+});