: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): retry comparison selection if the click is swallowed (#63167)
Sam Penningtonc5a0efe4ff11
diff --git a/playwright/page-models/insights/chartInsightBase.ts b/playwright/page-models/insights/chartInsightBase.tsindex 102988327efd..54823e37c847 100644--- a/playwright/page-models/insights/chartInsightBase.ts+++ b/playwright/page-models/insights/chartInsightBase.ts@@ -3,6 +3,9 @@ import { Locator, Page, expect } from '@playwright/test'export class ChartInsightBase {readonly chart: Locatorreadonly tooltip: Locator+ readonly dateRangeButton: Locator+ readonly chartTypeButton: Locator+ readonly comparisonButton: Locatorconstructor(protected readonly page: Page,@@ -10,6 +13,61 @@ export class ChartInsightBase {) {this.chart = chartLocatorthis.tooltip = page.getByTestId('insight-tooltip')+ this.dateRangeButton = page.getByTestId('date-filter')+ this.chartTypeButton = page.getByTestId('chart-filter')+ this.comparisonButton = page.getByTestId('compare-filter')+ }++ async waitForChart(): Promise<void> {+ await this.page.getByTestId('insight-loading-waiting-message').waitFor({ state: 'detached', timeout: 30000 })+ await expect(this.chart).toBeVisible({ timeout: 30000 })+ }++ async selectChartType(namePattern: RegExp): Promise<void> {+ await this.page.keyboard.press('Escape')+ await expect(async () => {+ await this.chartTypeButton.click({ timeout: 500 })+ await this.page.getByRole('menuitem', { name: namePattern }).click({ timeout: 500 })+ await expect(this.chartTypeButton).toHaveText(namePattern, { timeout: 1000 })+ }).toPass({ timeout: 15000 })+ await this.waitForChart()+ }++ async selectDateRange(text: string): Promise<void> {+ await this.page.keyboard.press('Escape')+ const dataAttr = `date-filter-${text.toLowerCase().replace(/\s+/g, '-')}`+ await expect(async () => {+ await this.dateRangeButton.click({ timeout: 500 })+ await this.page.getByTestId(dataAttr).click({ timeout: 500 })+ // Verify the selection actually applied — an edit-mode remount can+ // swallow the click, leaving the old range. Retry the whole open+click.+ await expect(this.dateRangeButton).toContainText(text, { timeout: 1000 })+ }).toPass({ timeout: 15000 })+ await this.waitForChart()+ }++ async selectComparison(text: string): Promise<void> {+ await this.page.keyboard.press('Escape')+ // Maps each dropdown option to the button label it produces. On narrow+ // viewports the button shows a short label ("Previous period" / "No+ // comparison"), so match a substring common to both variants.+ const appliedLabels: Record<string, RegExp> = {+ 'No comparison between periods': /no comparison/i,+ 'Compare to previous period': /previous period/i,+ }+ const appliedLabel = appliedLabels[text]+ if (!appliedLabel) {+ throw new Error(`selectComparison: no expected button label mapped for option "${text}"`)+ }+ await expect(async () => {+ await this.comparisonButton.click({ timeout: 500 })+ await this.page.getByRole('menuitem', { name: text }).click({ timeout: 500 })+ // Verify the selection actually applied — an edit-mode remount can swallow+ // the click, and the resulting query update is debounced by 500ms. Retry+ // the whole open+click if the button label doesn't change.+ await expect(this.comparisonButton).toContainText(appliedLabel, { timeout: 2000 })+ }).toPass({ timeout: 15000 })+ await this.waitForChart()}async hoverChartAt(xFraction: number = 0.3, yFraction: number = 0.5): Promise<void> {diff --git a/playwright/page-models/insights/retentionInsight.ts b/playwright/page-models/insights/retentionInsight.tsindex 4377b6c6118f..27c8fe8f8a62 100644--- a/playwright/page-models/insights/retentionInsight.ts+++ b/playwright/page-models/insights/retentionInsight.ts@@ -59,7 +59,7 @@ export class RetentionInsight extends ChartInsightBase {}).toPass({ timeout: 30000 })}- async waitForChart(): Promise<void> {+ override async waitForChart(): Promise<void> {const loading = this.page.getByTestId('insight-loading-waiting-message')// Wait for the loading indicator to appear (query started), then disappear.// Short timeout on 'attached' handles cached/instant queries where it never appears.diff --git a/playwright/page-models/insights/stickinessInsight.ts b/playwright/page-models/insights/stickinessInsight.tsindex cc90ed695545..1155f5a76d2d 100644--- a/playwright/page-models/insights/stickinessInsight.ts+++ b/playwright/page-models/insights/stickinessInsight.ts@@ -8,9 +8,6 @@ export class StickinessInsight extends ChartInsightBase {readonly detailsTable: Locatorreadonly firstSeries: Locatorreadonly secondSeries: Locator- readonly dateRangeButton: Locator- readonly chartTypeButton: Locator- readonly comparisonButton: Locatorreadonly taxonomicFilter: TaxonomicFilterprivate readonly detailsLoader: Locator@@ -24,9 +21,6 @@ export class StickinessInsight extends ChartInsightBase {this.addSeriesButton = page.getByTestId('add-action-event-button')this.firstSeries = page.getByTestId('trend-element-subject-0')this.secondSeries = page.getByTestId('trend-element-subject-1')- this.dateRangeButton = page.getByTestId('date-filter')- this.chartTypeButton = page.getByTestId('chart-filter')- this.comparisonButton = page.getByTestId('compare-filter')this.taxonomicFilter = new TaxonomicFilter(page)}@@ -34,11 +28,6 @@ export class StickinessInsight extends ChartInsightBase {return this.page.getByTestId(`trend-element-subject-${index}`)}- async waitForChart(): Promise<void> {- await this.page.getByTestId('insight-loading-waiting-message').waitFor({ state: 'detached', timeout: 30000 })- await expect(this.chart).toBeVisible({ timeout: 30000 })- }-async waitForDetailsTable(): Promise<void> {await this.detailsTable.locator('tbody tr').first().waitFor()await expect(this.detailsLoader).toHaveCount(0)@@ -54,35 +43,6 @@ export class StickinessInsight extends ChartInsightBase {await this.taxonomicFilter.selectItem(eventName)}- async selectChartType(namePattern: RegExp): Promise<void> {- await this.page.keyboard.press('Escape')- await expect(async () => {- await this.chartTypeButton.click({ timeout: 500 })- await this.page.getByRole('menuitem', { name: namePattern }).click({ timeout: 500 })- await expect(this.chartTypeButton).toHaveText(namePattern, { timeout: 1000 })- }).toPass({ timeout: 15000 })- await this.waitForChart()- }-- async selectDateRange(text: string): Promise<void> {- await this.page.keyboard.press('Escape')- const dataAttr = `date-filter-${text.toLowerCase().replace(/\s+/g, '-')}`- await expect(async () => {- await this.dateRangeButton.click({ timeout: 500 })- await this.page.getByTestId(dataAttr).click({ timeout: 500 })- // Verify the selection actually applied — an edit-mode remount can- // swallow the click, leaving the old range. Retry the whole open+click.- await expect(this.dateRangeButton).toContainText(text, { timeout: 1000 })- }).toPass({ timeout: 15000 })- await this.waitForChart()- }-- async selectComparison(text: string): Promise<void> {- await this.comparisonButton.click()- await this.page.getByText(text).click()- await this.waitForChart()- }-get details(): TableHelper {return new TableHelper(this.detailsTable)}diff --git a/playwright/page-models/insights/trendsInsight.ts b/playwright/page-models/insights/trendsInsight.tsindex 045cad748094..6593b0005fc4 100644--- a/playwright/page-models/insights/trendsInsight.ts+++ b/playwright/page-models/insights/trendsInsight.ts@@ -12,9 +12,6 @@ export class TrendsInsight extends ChartInsightBase {readonly breakdownButton: Locatorreadonly formulaSwitch: Locatorreadonly formulaInput: Locator- readonly dateRangeButton: Locator- readonly chartTypeButton: Locator- readonly comparisonButton: Locatorreadonly taxonomicFilter: TaxonomicFilterreadonly boldNumber: Locatorreadonly boldNumberComparison: Locator@@ -34,9 +31,6 @@ export class TrendsInsight extends ChartInsightBase {this.breakdownButton = page.getByTestId('add-breakdown-button')this.formulaSwitch = page.locator('#trends-formula-switch')this.formulaInput = page.getByPlaceholder('Example: (A + B) / 100')- this.dateRangeButton = page.getByTestId('date-filter')- this.chartTypeButton = page.getByTestId('chart-filter')- this.comparisonButton = page.getByTestId('compare-filter')this.taxonomicFilter = new TaxonomicFilter(page)this.boldNumber = page.getByTestId('bold-number-value')this.boldNumberComparison = page.getByTestId('bold-number-comparison')@@ -46,11 +40,6 @@ export class TrendsInsight extends ChartInsightBase {return this.page.getByTestId(`trend-element-subject-${index}`)}- async waitForChart(): Promise<void> {- await this.page.getByTestId('insight-loading-waiting-message').waitFor({ state: 'detached', timeout: 30000 })- await expect(this.chart).toBeVisible({ timeout: 30000 })- }-async waitForDetailsTable(): Promise<void> {await this.detailsTable.locator('tbody tr').first().waitFor()await expect(this.detailsLoader).toHaveCount(0)@@ -133,29 +122,6 @@ export class TrendsInsight extends ChartInsightBase {await this.waitForChart()}- async selectChartType(namePattern: RegExp): Promise<void> {- await this.page.keyboard.press('Escape')- await expect(async () => {- await this.chartTypeButton.click({ timeout: 500 })- await this.page.getByRole('menuitem', { name: namePattern }).click({ timeout: 500 })- await expect(this.chartTypeButton).toHaveText(namePattern, { timeout: 1000 })- }).toPass({ timeout: 15000 })- await this.waitForChart()- }-- async selectDateRange(text: string): Promise<void> {- await this.page.keyboard.press('Escape')- const dataAttr = `date-filter-${text.toLowerCase().replace(/\s+/g, '-')}`- await expect(async () => {- await this.dateRangeButton.click({ timeout: 500 })- await this.page.getByTestId(dataAttr).click({ timeout: 500 })- // Verify the selection actually applied — an edit-mode remount can- // swallow the click, leaving the old range. Retry the whole open+click.- await expect(this.dateRangeButton).toContainText(text, { timeout: 1000 })- }).toPass({ timeout: 15000 })- await this.waitForChart()- }-async openOptionsPanel(): Promise<void> {await this.page.locator('[data-attr="insight-filters"]').getByRole('button', { name: 'Options' }).click()}@@ -184,12 +150,6 @@ export class TrendsInsight extends ChartInsightBase {await this.waitForChart()}- async selectComparison(text: string): Promise<void> {- await this.comparisonButton.click()- await this.page.getByText(text).click()- await this.waitForChart()- }-async removeBreakdown(index: number = 0): Promise<void> {await this.page.keyboard.press('Escape')await this.expandBreakdownPanel()