Skip to content

Commit a063965

Browse files
mchestrclaude
andcommitted
fix: make onboarding E2E test more robust against redirect timing
Uses Promise.race to wait for either the sign-in button (home page after redirect) or the onboarding wizard heading, eliminating race conditions with URL-based checks during server-side redirects. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3e1090a commit a063965

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

e2e/public-flows.spec.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,31 @@ test.describe('Public Flows', () => {
5151
});
5252

5353
test('onboarding page accessibility check', async ({ page }) => {
54-
5554
await page.goto('/onboarding');
5655

57-
const isHome = page.url().endsWith('/');
58-
const isSignin = page.url().includes('signin');
59-
const isOnboarding = page.url().includes('/onboarding');
60-
61-
if (isOnboarding) {
62-
// If we stay on onboarding, verify the wizard is visible
63-
await expect(page.getByTestId('onboarding-wizard-heading')).toBeVisible();
64-
await expect(page.getByTestId('onboarding-wizard-subheading')).toBeVisible();
65-
} else {
66-
// If redirected, ensure we are on a safe page
67-
expect(isHome || isSignin).toBeTruthy();
56+
// Unauthenticated users should be redirected to home
57+
// Wait for either the sign-in button (home page) or the onboarding wizard
58+
// Using waitForSelector with a race condition to handle either outcome
59+
const signInButton = page.getByTestId('sign-in-button');
60+
const onboardingHeading = page.getByTestId('onboarding-wizard-heading');
61+
62+
// Wait for either element to appear (whichever comes first)
63+
await Promise.race([
64+
signInButton.waitFor({ state: 'visible', timeout: WAIT_TIMEOUTS.PAGE_CONTENT }),
65+
onboardingHeading.waitFor({ state: 'visible', timeout: WAIT_TIMEOUTS.PAGE_CONTENT }),
66+
]);
67+
68+
// After one element is visible, check which state we're in
69+
const isOnHome = await signInButton.isVisible();
70+
const isOnOnboarding = await onboardingHeading.isVisible();
71+
72+
// For unauthenticated users (the default in this test), we expect redirect to home
73+
// For authenticated users with incomplete onboarding, we'd see the wizard
74+
expect(isOnHome || isOnOnboarding).toBeTruthy();
75+
76+
if (isOnOnboarding) {
77+
// Verify the subheading as well
78+
await expect(page.getByTestId('onboarding-wizard-subheading')).toBeVisible({ timeout: WAIT_TIMEOUTS.PAGE_CONTENT });
6879
}
6980
});
7081

0 commit comments

Comments
 (0)