Skip to content

: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.

fix(e2e): replace UI-based createSavedTrendsInsight with API call (#73217)

mendral-app[bot]b7412c076705
diff --git a/playwright/e2e/product-analytics/dashboards.spec.ts b/playwright/e2e/product-analytics/dashboards.spec.ts
index 170aa543e118..5af895389a1e 100644
--- a/playwright/e2e/product-analytics/dashboards.spec.ts
+++ b/playwright/e2e/product-analytics/dashboards.spec.ts
@@ -5,14 +5,32 @@ import { InsightPage } from '../../page-models/insightPage'
import { randomString } from '../../utils'
import { PlaywrightWorkspaceSetupResult, expect, test } from '../../utils/workspace-test-base'
-async function createSavedTrendsInsight(page: Page, insightName: string): Promise<void> {
- const insight = new InsightPage(page)
-
- await insight.goToNewTrends()
- await insight.trends.waitForChart()
- await insight.editName(insightName)
- await insight.save()
- await expect(insight.editButton).toBeVisible()
+/**
+ * Creates a saved Trends insight via the API (no UI interaction).
+ * This avoids flakiness from chart rendering timeouts under CI load.
+ */
+async function createSavedTrendsInsight(
+ page: Page,
+ insightName: string,
+ workspace: PlaywrightWorkspaceSetupResult
+): Promise<void> {
+ const response = await page.request.post(`/api/projects/${workspace.team_id}/insights/`, {
+ headers: {
+ Authorization: `Bearer ${workspace.personal_api_key}`,
+ 'Content-Type': 'application/json',
+ },
+ data: {
+ name: insightName,
+ query: {
+ kind: 'InsightVizNode',
+ source: {
+ kind: 'TrendsQuery',
+ series: [{ kind: 'EventsNode', event: '$pageview' }],
+ },
+ },
+ },
+ })
+ expect(response.ok()).toBe(true)
}
test.describe('Dashboards', () => {
@@ -32,7 +50,7 @@ test.describe('Dashboards', () => {
const insightName = randomString('dash-trends')
await test.step('create a saved Trends insight', async () => {
- await createSavedTrendsInsight(page, insightName)
+ await createSavedTrendsInsight(page, insightName, workspace!)
})
await test.step('create a dashboard', async () => {
@@ -53,7 +71,7 @@ test.describe('Dashboards', () => {
let dashboardUrl: string
await test.step('create a saved Trends insight', async () => {
- await createSavedTrendsInsight(page, insightName)
+ await createSavedTrendsInsight(page, insightName, workspace!)
})
await test.step('create a dashboard with an insight', async () => {
@@ -275,7 +293,7 @@ test.describe('Dashboards', () => {
const insightName = randomString('dash-trends')
await test.step('create a saved Trends insight', async () => {
- await createSavedTrendsInsight(page, insightName)
+ await createSavedTrendsInsight(page, insightName, workspace!)
})
await test.step('create a dashboard with an insight', async () => {
@@ -469,7 +487,7 @@ test.describe('Dashboard compact cards and inline editing', () => {
const insightName = randomString('dash-trends')
await test.step('create a saved Trends insight', async () => {
- await createSavedTrendsInsight(page, insightName)
+ await createSavedTrendsInsight(page, insightName, workspace!)
})
await test.step('create a dashboard with an insight', async () => {
@@ -493,7 +511,7 @@ test.describe('Dashboard compact cards and inline editing', () => {
const updatedTitle = randomString('inline-title')
await test.step('create a saved Trends insight', async () => {
- await createSavedTrendsInsight(page, insightName)
+ await createSavedTrendsInsight(page, insightName, workspace!)
})
await test.step('create a dashboard with an insight', async () => {
@@ -528,7 +546,7 @@ test.describe('Dashboard compact cards and inline editing', () => {
const description = randomString('inline-desc')
await test.step('create a saved Trends insight', async () => {
- await createSavedTrendsInsight(page, insightName)
+ await createSavedTrendsInsight(page, insightName, workspace!)
})
await test.step('create a dashboard with an insight', async () => {