: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
fix(playwright): isolate funnels spec insights to stop cross-test state leak (#63019)
Sam Pennington22d200c30bed
diff --git a/playwright/e2e/product-analytics/insights/funnels.spec.ts b/playwright/e2e/product-analytics/insights/funnels.spec.tsindex 228ac9ff942a..3cbfec2b7e10 100644--- a/playwright/e2e/product-analytics/insights/funnels.spec.ts+++ b/playwright/e2e/product-analytics/insights/funnels.spec.ts@@ -77,7 +77,13 @@ test.describe('Funnel insights', () => {use_current_time: true,skip_onboarding: true,events: generateFunnelEvents(),- insights: [{ name: 'Seeded Funnel', query: FUNNEL_QUERY }],+ // Tests that save the insight get their own copy — saving a shared insight+ // leaks state (e.g. step order) into every test that loads it afterwards.+ insights: [+ { name: 'Seeded Funnel', query: FUNNEL_QUERY },+ { name: 'Step Order Funnel', query: FUNNEL_QUERY },+ { name: 'Lifecycle Funnel', query: FUNNEL_QUERY },+ ],dashboards: [{ name: 'Funnel Dashboard', insight_indexes: [0] }],})})@@ -86,17 +92,32 @@ test.describe('Funnel insights', () => {await playwrightSetup.login(page, workspace!)})- function seededInsightId(): InsightShortId {- return workspace!.created_insights![0].short_id as InsightShortId+ function seededInsightId(insightIndex: number = 0): InsightShortId {+ return workspace!.created_insights![insightIndex].short_id as InsightShortId}- async function goToSeededFunnel(page: InsightPage['page']): Promise<InsightPage> {+ async function goToSeededFunnel(page: InsightPage['page'], insightIndex: number = 0): Promise<InsightPage> {const insight = new InsightPage(page)- await insight.goToInsight(seededInsightId(), { edit: true })+ await insight.goToInsight(seededInsightId(insightIndex), { edit: true })await insight.funnels.waitForChart()return insight}+ // Setting the conversion window right after navigation or entering edit mode can race+ // the editor's hydration — the edit is occasionally swallowed or reverted by a late+ // insight load. The page model waits for the insight re-fetch, but a just-received+ // response can still apply milliseconds after the edit, so require the dirty state to+ // stick and re-apply if it was reverted.+ async function setConversionWindowUntilDirty(insight: InsightPage, value: string): Promise<void> {+ await expect(async () => {+ await insight.funnels.setConversionWindowInterval(value)+ await expect(insight.saveButton).not.toContainText('No changes', { timeout: 2000 })+ await insight.page.waitForTimeout(300)+ await expect(insight.saveButton).not.toContainText('No changes', { timeout: 500 })+ await expect(insight.saveButton).toBeEnabled({ timeout: 500 })+ }).toPass({ timeout: 30000 })+ }+test('Create funnel via UI and verify conversion math and tooltips', async ({ page }) => {const insight = new InsightPage(page)@@ -190,7 +211,7 @@ test.describe('Funnel insights', () => {})test('Configure step ordering and session aggregation gating', async ({ page }) => {- const insight = await goToSeededFunnel(page)+ const insight = await goToSeededFunnel(page, 1)await test.step('default step order is Sequential', async () => {await expect(insight.funnels.stepOrderFilter).toContainText('Sequential')@@ -217,10 +238,17 @@ test.describe('Funnel insights', () => {await test.step('switch back to Sequential', async () => {await insight.funnels.selectStepOrder('Sequential')await insight.funnels.waitForChart()+ // Without this check a silently failed switch gets saved below, and any+ // test reading this insight afterwards runs against the wrong step order.+ await expect(insight.funnels.stepOrderFilter).toContainText('Sequential')})await test.step('clicking dropped-off count opens persons modal with correct users', async () => {- await insight.save()+ // Repeat runs share the workspace, so the round-trip back to Sequential can+ // match the saved state exactly — only save when there is something to save.+ if (!(await insight.saveButton.innerText()).includes('No changes')) {+ await insight.save()+ }await insight.funnels.waitForChart()const step2 = insight.funnels.stepLegend(1)@@ -229,7 +257,8 @@ test.describe('Funnel insights', () => {const modal = page.getByTestId('persons-modal')await expect(modal).toBeVisible({ timeout: 10000 })- await expect(modal).toContainText('firefox-user-1')+ // The actors query can take well over the local 10s expect default under load+ await expect(modal).toContainText('firefox-user-1', { timeout: 30000 })await modal.getByRole('button', { name: 'close' }).click()await expect(modal).not.toBeVisible()@@ -342,11 +371,17 @@ test.describe('Funnel insights', () => {})test('Save, button states, edit, and cancel lifecycle', async ({ page }) => {- const insight = await goToSeededFunnel(page)+ const insight = await goToSeededFunnel(page, 2)const funnelName = randomString('funnel-lifecycle')+ // Repeat runs share the workspace, so derive window values from the currently+ // saved one — hardcoded values would be a no-op edit on the second run.+ const savedWindow = Number(await insight.funnels.getConversionWindowInterval())+ const windowA = String(savedWindow >= 300 ? 2 : savedWindow + 1)+ const windowB = String(savedWindow >= 300 ? 3 : savedWindow + 2)+await test.step('save button is enabled on unsaved changes', async () => {- await insight.funnels.setConversionWindowInterval('7')+ await setConversionWindowUntilDirty(insight, windowA)await insight.funnels.waitForChart()await expect(insight.saveButton).toBeEnabled()await expect(insight.saveButton).not.toContainText('No changes')@@ -365,7 +400,7 @@ test.describe('Funnel insights', () => {})await test.step('make a change — save enables, cancel button appears', async () => {- await insight.funnels.setConversionWindowInterval('3')+ await setConversionWindowUntilDirty(insight, windowB)await insight.funnels.waitForChart()await expect(insight.saveButton).toBeEnabled()@@ -379,7 +414,7 @@ test.describe('Funnel insights', () => {await insight.funnels.waitForChart()await insight.edit()- await expect(insight.funnels.conversionWindowInput).toHaveValue('7')+ await expect(insight.funnels.conversionWindowInput).toHaveValue(windowA)})})@@ -412,7 +447,7 @@ test.describe('Funnel insights', () => {await insight.edit()await expect(insight.saveButton).toContainText('No changes')- await insight.funnels.setConversionWindowInterval('3')+ await setConversionWindowUntilDirty(insight, '3')await expect(insight.saveButton).toBeEnabled()await expect(insight.saveButton).toContainText('Save')})diff --git a/playwright/page-models/insightPage.ts b/playwright/page-models/insightPage.tsindex 75b3eb4fa632..415c8b4a4cf1 100644--- a/playwright/page-models/insightPage.ts+++ b/playwright/page-models/insightPage.ts@@ -81,17 +81,19 @@ export class InsightPage {): Promise<InsightPage> {const base = options?.edit ? urls.insightEdit(shortId) : urls.insightView(shortId)- if (!options?.queryParams) {- await this.page.goto(base, { waitUntil: 'domcontentloaded' })- return this+ let url = base+ if (options?.queryParams) {+ const params = new URLSearchParams()+ for (const [k, v] of Object.entries(options.queryParams)) {+ params.set(k, typeof v === 'object' ? JSON.stringify(v) : String(v))+ }+ const sep = base.includes('?') ? '&' : '?'+ url = `${base}${sep}${params}`}- const params = new URLSearchParams()- for (const [k, v] of Object.entries(options.queryParams)) {- params.set(k, typeof v === 'object' ? JSON.stringify(v) : String(v))- }- const sep = base.includes('?') ? '&' : '?'- await this.page.goto(`${base}${sep}${params}`, { waitUntil: 'domcontentloaded' })+ const insightLoaded = this.waitForInsightLoad()+ await this.page.goto(url, { waitUntil: 'domcontentloaded' })+ await insightLoadedreturn this}@@ -109,6 +111,11 @@ export class InsightPage {{ timeout: 30000 })+ // Saving switches back to view mode, which re-fetches the insight. Drain that+ // fetch before returning — left in flight, its response can land after a later+ // edit and clobber it (see waitForInsightLoad).+ const insightReloaded = this.waitForInsightLoad()+await this.saveButton.click()const saveResponse = await saveRequestPromise@@ -147,10 +154,27 @@ export class InsightPage {if (new URL(this.page.url()).pathname === originalPathname) {await expect(this.editButton).toBeVisible()}++ await insightReloaded+ }++ // Both navigating to an insight and entering edit mode trigger a re-fetch of the+ // insight (GET ?short_id=...). If a test edits the query while that fetch is in+ // flight, the response clobbers the local edit and the page reverts to a clean+ // "No changes" state. Wait for the fetch so edits made afterwards stick.+ private waitForInsightLoad(): Promise<unknown> {+ return this.page.waitForResponse(+ (response) =>+ /\/api\/(?:projects|environments)\/\d+\/insights\/?\?(?=.*\bshort_id=)/.test(response.url()) &&+ response.request().method() === 'GET',+ { timeout: 30000 }+ )}async edit(): Promise<void> {+ const insightLoaded = this.waitForInsightLoad()await this.editButton.click()+ await insightLoaded}async discard(): Promise<void> {diff --git a/playwright/page-models/insights/funnelsInsight.ts b/playwright/page-models/insights/funnelsInsight.tsindex aff03bc92112..0af78d4cfae9 100644--- a/playwright/page-models/insights/funnelsInsight.ts+++ b/playwright/page-models/insights/funnelsInsight.ts@@ -117,6 +117,12 @@ export class FunnelsInsight {await input.press('Enter')}+ async getConversionWindowInterval(): Promise<string> {+ await this.expandFunnelSettings()+ await expect(this.conversionWindowInput).toHaveValue(/\d+/)+ return await this.conversionWindowInput.inputValue()+ }+async selectConversionWindowUnit(unit: string): Promise<void> {await this.expandFunnelSettings()await this.conversionWindowSection.getByTestId('funnel-conversion-window-unit').click()