: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: Fix flaky trends details-table assertions with polling (#60522)
Jordan Mryyan8791591c1f37
diff --git a/playwright/e2e/product-analytics/insights/trends.spec.ts b/playwright/e2e/product-analytics/insights/trends.spec.tsindex 0920e8afa095..f6c7f1c606e5 100644--- a/playwright/e2e/product-analytics/insights/trends.spec.ts+++ b/playwright/e2e/product-analytics/insights/trends.spec.ts@@ -36,9 +36,7 @@ test.describe('Trends insights', () => {})await test.step('verify total pageview count in details table', async () => {- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual([pageviews.expected.total])+ await insight.trends.expectTotals([pageviews.expected.total])})})@@ -50,18 +48,14 @@ test.describe('Trends insights', () => {await test.step('change event to custom event and verify total', async () => {await insight.trends.selectEvent(0, customEventsWithBreakdown.eventName)await insight.trends.waitForChart()- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual([customEventsWithBreakdown.expected.total])+ await insight.trends.expectTotals([customEventsWithBreakdown.expected.total])})await test.step('add second series with pageview and verify both totals', async () => {await insight.trends.addSeries()await insight.trends.selectEvent(1, 'Pageview')await insight.trends.waitForChart()- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual([customEventsWithBreakdown.expected.total, pageviews.expected.total])+ await insight.trends.expectTotals([customEventsWithBreakdown.expected.total, pageviews.expected.total])})await test.step('duplicate first series', async () => {@@ -111,9 +105,7 @@ test.describe('Trends insights', () => {await test.step('cumulative line chart shows total in details table', async () => {await insight.trends.selectChartType(/^Line chart \(cumulative\)/)- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual([pageviews.expected.total])+ await insight.trends.expectTotals([pageviews.expected.total])})await test.step('Number chart shows bold number = 38', async () => {@@ -137,16 +129,12 @@ test.describe('Trends insights', () => {await insight.trends.waitForChart()await test.step('Last 7 days shows total = 38', async () => {- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual([pageviews.expected.total])+ await insight.trends.expectTotals([pageviews.expected.total])})await test.step('Last 24 hours shows total = 2', async () => {await insight.trends.selectDateRange('Last 24 hours')- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual(['2'])+ await insight.trends.expectTotals(['2'])})await test.step('enable comparison and verify no NaN', async () => {@@ -177,18 +165,14 @@ test.describe('Trends insights', () => {})await test.step('verify Chrome = 5 and Firefox = 3', async () => {- const chromeTotal = await insight.trends.details.row('Chrome').column('Total')- const firefoxTotal = await insight.trends.details.row('Firefox').column('Total')- expect(chromeTotal).toEqual(customEventsWithBreakdown.expected.chromeCount)- expect(firefoxTotal).toEqual(customEventsWithBreakdown.expected.firefoxCount)+ await insight.trends.expectRowTotal('Chrome', customEventsWithBreakdown.expected.chromeCount)+ await insight.trends.expectRowTotal('Firefox', customEventsWithBreakdown.expected.firefoxCount)})await test.step('remove breakdown and verify single total returns', async () => {await insight.trends.removeBreakdown()await insight.trends.waitForChart()- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual([customEventsWithBreakdown.expected.total])+ await insight.trends.expectTotals([customEventsWithBreakdown.expected.total])})})@@ -206,9 +190,7 @@ test.describe('Trends insights', () => {await test.step('enable formula A + B and verify computed total', async () => {await insight.trends.setFormula('A + B')await insight.trends.waitForChart()- await insight.trends.waitForDetailsTable()- const totals = await insight.trends.details.column('Total')- expect(totals).toEqual(['46'])+ await insight.trends.expectTotals(['46'])})await test.step('disable formula mode and verify both series return', async () => {diff --git a/playwright/page-models/insights/trendsInsight.ts b/playwright/page-models/insights/trendsInsight.tsindex 1141e4671a8e..fb4140a7e382 100644--- a/playwright/page-models/insights/trendsInsight.ts+++ b/playwright/page-models/insights/trendsInsight.ts@@ -58,6 +58,21 @@ export class TrendsInsight extends ChartInsightBase {await expect(this.detailsLoader).toHaveCount(0)}+ // Re-reads the Total column until it settles on the expected values. A bare+ // snapshot read can capture the previous query's rows: after an action that+ // recomputes the insight, the old table is still mounted and the details+ // loader has not reappeared yet, so waitForDetailsTable returns against stale+ // content. Polling rides out that transition instead of racing it.+ async expectTotals(expected: string[], timeout = 15000): Promise<void> {+ await this.waitForDetailsTable()+ await expect.poll(async () => await this.details.column('Total'), { timeout }).toEqual(expected)+ }++ async expectRowTotal(row: string, expected: string, timeout = 15000): Promise<void> {+ await this.waitForDetailsTable()+ await expect.poll(async () => await this.details.row(row).column('Total'), { timeout }).toEqual(expected)+ }+async addSeries(): Promise<void> {await this.addSeriesButton.click()}