: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(insights): deflake SQL variable dashboard playwright test (#66993)
Thiago Salvatore7a3200657880
diff --git a/playwright/e2e/product-analytics/dashboards.spec.ts b/playwright/e2e/product-analytics/dashboards.spec.tsindex ec2e87b7bdb7..170aa543e118 100644--- a/playwright/e2e/product-analytics/dashboards.spec.ts+++ b/playwright/e2e/product-analytics/dashboards.spec.ts@@ -170,8 +170,21 @@ test.describe('Dashboards', () => {await expect(dialog).toBeVisible()await dialog.getByRole('textbox', { name: 'Name' }).fill('Test Number')await dialog.getByRole('spinbutton').fill('5')++ // Saving the variable kicks off a reload of the insightVariables list, and the+ // editor can only substitute {variables.test_number} once that list has loaded.+ // Running the query before the reload returns sends the placeholder unresolved,+ // the backend errors with "Global variable not found: variables", and+ // "Save as insight" never enables. Wait for the reload before using the variable.+ const variablesReloaded = page.waitForResponse(+ (response) =>+ response.url().includes('/insight_variables') &&+ response.request().method() === 'GET' &&+ response.ok()+ )await dialog.getByRole('button', { name: 'Save' }).click()await expect(dialog).not.toBeVisible()+ await variablesReloaded})await test.step('write query, run, and save as insight', async () => {@@ -184,10 +197,18 @@ test.describe('Dashboards', () => {await page.keyboard.insertText('SELECT {variables.test_number}')await page.keyboard.press('Escape')- await page.getByRole('button', { name: 'Run' }).click()- await expect(page.locator('[data-attr=sql-editor-output-pane-empty-state]')).not.toBeVisible()- await expect(page.getByRole('button', { name: 'Save as insight' })).toBeEnabled({ timeout: 30000 })- await page.getByRole('button', { name: 'Save as insight' }).click()+ // The editor attaches the variable to the query through a short debounce, so a+ // fast first Run can execute before {variables.test_number} is substituted —+ // the query then errors with "Global variable not found: variables" and leaves+ // "Save as insight" disabled. Re-run until the variable resolves and the query+ // succeeds (a successful run is the only thing that enables "Save as insight").+ const saveAsInsight = page.getByRole('button', { name: 'Save as insight' })+ await expect(async () => {+ await page.getByRole('button', { name: 'Run' }).click()+ await expect(page.locator('[data-attr=sql-editor-output-pane-empty-state]')).not.toBeVisible()+ await expect(saveAsInsight).toBeEnabled({ timeout: 15000 })+ }).toPass({ timeout: 60000 })+ await saveAsInsight.click()const saveModal = page.locator('.LemonModal').filter({ hasText: 'Save as new insight' })await expect(saveModal).toBeVisible()