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(test): add retry logic to Playwright login to prevent flaky fetch failures (#64763)

mendral-app[bot]f39990a2f813
diff --git a/playwright/utils/playwright-setup.ts b/playwright/utils/playwright-setup.ts
index 14bff88b9cbf..2529df306ffa 100644
--- a/playwright/utils/playwright-setup.ts
+++ b/playwright/utils/playwright-setup.ts
@@ -275,15 +275,32 @@ export class PlaywrightSetup {
async login(page: Page, workspace: PlaywrightWorkspaceSetupResult): Promise<void> {
await page.goto(`${this.baseURL}/login`)
+ await page.waitForLoadState('networkidle')
await page.evaluate(
async ({ email, password }) => {
- await fetch('/api/login/', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ email, password }),
- })
+ const maxAttempts = 3
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
+ try {
+ const res = await fetch('/api/login/', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ email, password }),
+ })
+ if (res.ok) {
+ return
+ }
+ if (attempt === maxAttempts || res.status < 500) {
+ throw new Error(`Login failed with status ${res.status}`)
+ }
+ } catch (e) {
+ if (attempt === maxAttempts) {
+ throw e
+ }
+ }
+ await new Promise((r) => setTimeout(r, 500 * attempt))
+ }
},
{
email: workspace.user_email,