:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(playwright): support product-owned e2e tests (#60190)
Julian Bez2f6ab54e03a0
diff --git a/.github/scripts/verify-playwright-new-tests-and-snapshots.sh b/.github/scripts/verify-playwright-new-tests-and-snapshots.shindex 1a5a5edf8921..a111af139c4d 100755--- a/.github/scripts/verify-playwright-new-tests-and-snapshots.sh+++ b/.github/scripts/verify-playwright-new-tests-and-snapshots.sh@@ -29,8 +29,16 @@ echo "Detecting changed Playwright test files since $BASE_SHA..."RESULTS_FILE="playwright/flake-verification-results.json"rm -f "$RESULTS_FILE"-# All spec files touched by the PR (added or modified).-changed_test_files=$(git diff --name-only "$BASE_SHA..HEAD" -- 'playwright/**/*.spec.ts')+# All spec files touched by the PR (added or modified). Playwright tests live in two+# places: cross-cutting tests under playwright/e2e/, and product-owned tests under+# products/*/frontend/e2e/. Both are picked up by playwright.config.ts.+#+# --diff-filter=AM excludes renames: a `git mv` (with at most a trivial import-path+# update) doesn't change test logic, so re-running it 10x for flake verification is+# noise. If a file is moved AND substantively edited in the same PR, the verifier+# won't catch it — but that's a rare pattern, and the alternative (re-verifying every+# moved test) blocks routine reorganizations.+changed_test_files=$(git diff --name-only --diff-filter=AM "$BASE_SHA..HEAD" -- 'playwright/**/*.spec.ts' 'products/*/frontend/e2e/**/*.spec.ts')if [ -z "$changed_test_files" ]; thenecho "No changed Playwright test files found — skipping flake verification"@@ -43,8 +51,14 @@ while IFS= read -r test_file; docontinuefi- # Strip the playwright/ prefix — Playwright runs relative to its project root.- tests_to_run+=("${test_file#playwright/}")+ # Convert repo-relative paths to playwright-cwd-relative paths. The CI step runs+ # `pnpm --filter=@posthog/playwright exec playwright test`, which sets cwd to+ # playwright/, so files outside that directory need a `../` prefix.+ if [[ "$test_file" == playwright/* ]]; then+ tests_to_run+=("${test_file#playwright/}")+ else+ tests_to_run+=("../${test_file}")+ fidone <<< "$changed_test_files"if [ ${#tests_to_run[@]} -eq 0 ]; thendiff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.ymlindex d1a419cbc372..e8df2e09469f 100644--- a/.github/workflows/ci-e2e-playwright.yml+++ b/.github/workflows/ci-e2e-playwright.yml@@ -116,6 +116,7 @@ jobs:shouldRun:# Any change that could affect E2E behavior triggers a run.- playwright/**+ - 'products/*/frontend/e2e/**'- .github/workflows/ci-e2e-playwright.yml- 'ee/**'- 'posthog/!(temporal/**)/**'diff --git a/frontend/jest.config.ts b/frontend/jest.config.tsindex 353399d76206..24b3d3705bcd 100644--- a/frontend/jest.config.ts+++ b/frontend/jest.config.ts@@ -250,7 +250,7 @@ const config: Config = {// ],// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped- testPathIgnorePatterns: ['/node_modules/', '/services/mcp/', '/products/visual_review/cli/'],+ testPathIgnorePatterns: ['/node_modules/', '/services/mcp/', '/products/[^/]+/frontend/e2e/', '/products/visual_review/cli/'],// The regexp pattern or array of patterns that Jest uses to detect test files// testRegex: [],diff --git a/package.json b/package.jsonindex 8aff9f25cdfe..1ce26ac6e20e 100644--- a/package.json+++ b/package.json@@ -63,6 +63,7 @@"devDependencies": {"@parcel/packager-ts": "catalog:","@parcel/transformer-typescript-types": "catalog:",+ "@playwright/test": "catalog:","@types/uuid": "^11.0.0","@typescript/native-preview": "7.0.0-dev.20260421.2","markdownlint-cli2": "^0.18.1",diff --git a/playwright/README.md b/playwright/README.mdindex 4f9da9d9caf5..b585965ac1f6 100644--- a/playwright/README.md+++ b/playwright/README.md@@ -1,5 +1,22 @@# End-to-End Testing+## Where tests live++Playwright tests are discovered from two locations (configured in `playwright.config.ts`):++- `playwright/e2e/**/*.spec.ts` — cross-cutting and platform-level tests (auth, signup, shared dashboards, etc.) and any tests that don't have an obvious single-product owner.+- `products/<product>/frontend/e2e/**/*.spec.ts` — tests owned by a specific product, co-located with that product's code.++Shared fixtures, page models, and helpers live under `playwright/utils/`, `playwright/page-models/`, and `playwright/mocks/`. Import them from anywhere via TypeScript path aliases:++```ts+import { expect, test } from '@playwright-utils/playwright-test-base'+import { randomString } from '@playwright-utils'+import { InsightPage } from '@playwright-pages/insightPage'+```++When you add a new test for a feature owned by a specific product, prefer co-locating it under `products/<product>/frontend/e2e/` rather than adding it to `playwright/e2e/`.+## Running testsSpin up a full local E2E environment (backend, frontend, docker services, Playwright UI):diff --git a/playwright/package.json b/playwright/package.jsonindex 3ade36e27edf..4b639e2ba675 100644--- a/playwright/package.json+++ b/playwright/package.json@@ -5,7 +5,7 @@"test": "pnpm build:products && playwright test"},"dependencies": {- "@playwright/test": "1.60.0",+ "@playwright/test": "catalog:","@posthog/frontend": "workspace:*"},"peerDependencies": {}diff --git a/playwright/playwright.config.ts b/playwright/playwright.config.tsindex dc30aad796e6..b171e0408c48 100644--- a/playwright/playwright.config.ts+++ b/playwright/playwright.config.ts@@ -10,7 +10,13 @@ import { defineConfig, devices } from '@playwright/test'* See https://playwright.dev/docs/test-configuration.*/export default defineConfig({- testDir: '.',+ // testDir is the repo root so we can discover tests in two locations:+ // - playwright/e2e/** — cross-cutting and platform-level tests+ // - products/*/frontend/e2e/** — product-owned tests, co-located with the product+ // testMatch keeps discovery scoped to those two roots so we don't accidentally+ // pick up unrelated *.spec.ts files (e.g. Jest unit tests under products/).+ testDir: '..',+ testMatch: ['playwright/e2e/**/*.spec.ts', 'products/*/frontend/e2e/**/*.spec.ts'],/*Maximum time one test can run for.Shorter timeout in local dev since it's annoying to wait 90 seconds for a test to run.diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 84c5bc91bd46..533bf5ef9ff7 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -15,6 +15,9 @@ catalogs:'@parcel/transformer-typescript-types':specifier: 2.16.4version: 2.16.4+ '@playwright/test':+ specifier: 1.60.0+ version: 1.60.0'@posthog/react':specifier: ^1.9.0version: 1.9.0@@ -155,6 +158,9 @@ importers:'@parcel/transformer-typescript-types':specifier: 'catalog:'version: 2.16.4(@parcel/[email protected])([email protected])+ '@playwright/test':+ specifier: 'catalog:'+ version: 1.60.0'@types/uuid':specifier: ^11.0.0version: 11.0.0@@ -2141,7 +2147,7 @@ importers:playwright:dependencies:'@playwright/test':- specifier: 1.60.0+ specifier: 'catalog:'version: 1.60.0'@posthog/frontend':specifier: workspace:*@@ -22760,11 +22766,6 @@ packages:resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==}engines: {node: '>= 6'}- resolution: {integrity: sha512-ml/JPOj9fOQK8RNnWojA67GbZ0ApXAUlN2UQclwv2eVgTgn7O9gg9o7paZWKMp4g0H3nTLtS9LVzhkpOFIKzog==}- engines: {node: '>= 14.6'}- hasBin: true-resolution: {integrity: sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==}engines: {node: '>= 14.6'}@@ -40738,7 +40739,7 @@ snapshots:micromatch: 4.0.8pidtree: 0.6.0string-argv: 0.3.2- yaml: 2.8.4+ yaml: 2.9.0transitivePeerDependencies:- supports-color@@ -47366,8 +47367,6 @@ snapshots:- [email protected]: {}-diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 65cf090023bb..cf527ee2767f 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -46,6 +46,7 @@ catalog:jest: ^29.7.0'@types/jest': ^29.5.12'@types/node': ^22.13.14+ '@playwright/test': 1.60.0# Storybook'@storybook/addon-actions': ^8.6.14'@storybook/react': ^8.6.14diff --git a/products/README.md b/products/README.mdindex f7425dbb4d64..fea1a43ce790 100644--- a/products/README.md+++ b/products/README.md@@ -93,7 +93,8 @@ This avoids circular imports and keeps migrations/app labels stable.- Each `frontend/` directory contains the frontend app for the product.- It lives under the same package as the backend.- Backend and frontend tooling can be independent (`requirements.txt` vs. `package.json`) but remain in the same Turborepo package.-- Tests for frontend code live inside `frontend/tests/`.+- Jest unit tests for frontend code live inside `frontend/tests/` (or alongside the file as `*.test.ts` / `*.spec.ts`).+- Playwright end-to-end tests for a product live inside `frontend/e2e/` as `*.spec.ts` — these are discovered by `playwright.config.ts` and run by the E2E CI workflow. Import shared fixtures via the `@playwright-utils/*` and `@playwright-pages/*` aliases. See `playwright/README.md` for details.## Shared codediff --git a/playwright/e2e/surveys/crud.spec.ts b/products/surveys/frontend/e2e/crud.spec.tssimilarity index 98%rename from playwright/e2e/surveys/crud.spec.tsrename to products/surveys/frontend/e2e/crud.spec.tsindex f81b14550616..754526e54da4 100644--- a/playwright/e2e/surveys/crud.spec.ts+++ b/products/surveys/frontend/e2e/crud.spec.ts@@ -1,8 +1,7 @@+import { randomString } from '@playwright-utils'+import { expect, test } from '@playwright-utils/playwright-test-base'import { Page } from '@playwright/test'-import { randomString } from '../../utils'-import { expect, test } from '../../utils/playwright-test-base'-async function deleteSurvey(page: Page, name: string): Promise<void> {// Only archived surveys (or drafts) expose the "Delete permanently" action.await page.locator('[data-attr=open-context-panel-button]').first().click()diff --git a/playwright/e2e/surveys/quickcreate.spec.ts b/products/surveys/frontend/e2e/quickcreate.spec.tssimilarity index 98%rename from playwright/e2e/surveys/quickcreate.spec.tsrename to products/surveys/frontend/e2e/quickcreate.spec.tsindex a6e5882fdf43..a0114ef5430d 100644--- a/playwright/e2e/surveys/quickcreate.spec.ts+++ b/products/surveys/frontend/e2e/quickcreate.spec.ts@@ -1,10 +1,9 @@+import { randomString } from '@playwright-utils'+import { PlaywrightWorkspaceSetupResult, expect, test } from '@playwright-utils/workspace-test-base'import { Page } from '@playwright/test'import { urls } from 'scenes/urls'-import { randomString } from '../../utils'-import { PlaywrightWorkspaceSetupResult, expect, test } from '../../utils/workspace-test-base'-const saveFeatureFlag = async (page: Page): Promise<void> => {const saveButton = page.locator('[data-attr="save-feature-flag"]').first()await expect(saveButton).toBeEnabled()diff --git a/playwright/e2e/surveys/settings.spec.ts b/products/surveys/frontend/e2e/settings.spec.tssimilarity index 96%rename from playwright/e2e/surveys/settings.spec.tsrename to products/surveys/frontend/e2e/settings.spec.tsindex dae3b94a059f..495b40023ac2 100644--- a/playwright/e2e/surveys/settings.spec.ts+++ b/products/surveys/frontend/e2e/settings.spec.ts@@ -1,7 +1,6 @@+import { expect, test } from '@playwright-utils/playwright-test-base'import { Page } from '@playwright/test'-import { expect, test } from '../../utils/playwright-test-base'-test.describe('Survey Settings', () => {test.beforeEach(async ({ page }) => {await page.goToMenuItem('surveys')diff --git a/tsconfig.json b/tsconfig.jsonindex a5ca2e71f189..6d2a1eca7807 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -11,6 +11,10 @@"~/*": ["./frontend/src/*"],"public/*": ["./frontend/public/*"],"products/*": ["./products/*"],+ "@playwright-utils": ["./playwright/utils/index"],+ "@playwright-utils/*": ["./playwright/utils/*"],+ "@playwright-pages/*": ["./playwright/page-models/*"],+ "@playwright-mocks/*": ["./playwright/mocks/*"],"@common/*": ["./common/*"],"@posthog/mcp-ui": ["./services/mcp/src/ui-apps/lib/index.ts"],"@posthog/mcp-ui/*": ["./services/mcp/src/ui-apps/lib/*"],