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.

chore(playwright): deflake google login auth test (#61170)

Raúl Negrón-Oteroac8ff3ba048f
diff --git a/playwright/e2e/auth.spec.ts b/playwright/e2e/auth.spec.ts
index a5a5d619adc4..a3e7e2a44e9e 100644
--- a/playwright/e2e/auth.spec.ts
+++ b/playwright/e2e/auth.spec.ts
@@ -1,5 +1,3 @@
-import { PreflightStatus } from '~/types'
-
import { LoginPage } from '../page-models/loginPage'
import { LOGIN_PASSWORD, LOGIN_USERNAME, expect, test } from '../utils/playwright-test-base'
@@ -32,13 +30,28 @@ test.describe('Auth', () => {
})
test('Logout and verify Google login button has correct link', async ({ page }) => {
- await page.locator('[data-attr=new-account-menu-logout-button]').click()
+ // available_social_auth_providers comes from POSTHOG_APP_CONTEXT, which is server-rendered into the
+ // login page HTML and read directly by preflightLogic on mount — so API mocks don't apply. Patch the
+ // context before the page scripts run; mutating it after the page has loaded is racy and only
+ // renders the button on lucky timing.
+ await page.addInitScript(() => {
+ let _context: any = undefined
+ Object.defineProperty(window, 'POSTHOG_APP_CONTEXT', {
+ get() {
+ if (_context?.preflight) {
+ _context.preflight.available_social_auth_providers ??= {}
+ _context.preflight.available_social_auth_providers['google-oauth2'] = true
+ }
+ return _context
+ },
+ set(value) {
+ _context = value
+ },
+ configurable: true,
+ })
+ })
- await page.setAppContext('preflight', {
- available_social_auth_providers: {
- 'google-oauth2': true,
- },
- } as Partial<PreflightStatus> as PreflightStatus)
+ await page.locator('[data-attr=new-account-menu-logout-button]').click()
await expect(page.locator('a[href="/login/google-oauth2/"]')).toBeVisible()
})
diff --git a/playwright/utils/playwright-test-core.ts b/playwright/utils/playwright-test-core.ts
index 9e41c69a1c04..0429fc08dd28 100644
--- a/playwright/utils/playwright-test-core.ts
+++ b/playwright/utils/playwright-test-core.ts
@@ -1,19 +1,12 @@
import { Page, test as base } from '@playwright/test'
-import { AppContext } from '~/types'
-
import { Identifier, Navigation } from './navigation'
export const LOGIN_USERNAME = process.env.LOGIN_USERNAME || '[email protected]'
export const LOGIN_PASSWORD = process.env.LOGIN_PASSWORD || '12345678'
-export type WindowWithPostHog = typeof globalThis & {
- POSTHOG_APP_CONTEXT: AppContext
-}
-
declare module '@playwright/test' {
interface Page {
- setAppContext<K extends keyof AppContext>(key: K, value: AppContext[K]): Promise<void>
goToMenuItem(name: string): Promise<void>
}
}
@@ -25,16 +18,6 @@ declare module '@playwright/test' {
export const test = base.extend<{ page: Page }>({
page: async ({ page }, use) => {
// Add custom methods to the page object
- page.setAppContext = async function <K extends keyof AppContext>(key: K, value: AppContext[K]): Promise<void> {
- await page.evaluate(
- ([key, value]) => {
- const appContext = (window as WindowWithPostHog).POSTHOG_APP_CONTEXT
- // @ts-expect-error - Type safety is handled by the generic constraint
- appContext[key] = value
- },
- [key, value]
- )
- }
page.goToMenuItem = async function (name: Identifier): Promise<void> {
await new Navigation(page).openMenuItem(name)
}