Skip to content

Commit 7c6d69d

Browse files
committed
Fix e2e enterprise tests
1 parent 362e693 commit 7c6d69d

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

frontend/src/components/misc/login.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,29 @@ const LoginPage = observer(() => {
222222
const searchParams = new URLSearchParams(searchStr);
223223

224224
useEffect(() => {
225-
authenticationApi.refreshAuthenticationMethods();
225+
let cancelled = false;
226+
const fetchWithRetry = async () => {
227+
for (let attempt = 0; attempt < 5; attempt++) {
228+
if (cancelled) {
229+
return;
230+
}
231+
try {
232+
await authenticationApi.refreshAuthenticationMethods();
233+
} catch {
234+
// authentication client not yet initialized - retry
235+
}
236+
if (authenticationApi.methods.length > 0 || authenticationApi.methodsErrorResponse) {
237+
return;
238+
}
239+
if (attempt < 4) {
240+
await new Promise<void>((resolve) => setTimeout(resolve, 1500));
241+
}
242+
}
243+
};
244+
fetchWithRetry();
245+
return () => {
246+
cancelled = true;
247+
};
226248
}, []);
227249

228250
return (

frontend/tests/test-variant-console-enterprise/auth.setup.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,33 @@ async function dismissErrorModalIfPresent(page: Page): Promise<void> {
2121
}
2222
}
2323

24+
/**
25+
* Navigates to the login page and waits for the username input to be visible.
26+
* Retries with page reload if the form doesn't appear (backend may not be fully ready yet).
27+
*/
28+
async function navigateToLoginPage(page: Page): Promise<void> {
29+
// Navigate directly to /login to avoid redirect timing issues from /
30+
await page.goto('/login', { waitUntil: 'domcontentloaded' });
31+
32+
// Wait for login form with reload retry (backend auth system may need a moment)
33+
const usernameInput = page.getByTestId('auth-username-input');
34+
const maxAttempts = 5;
35+
36+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
37+
const isVisible = await usernameInput.isVisible({ timeout: 8000 }).catch(() => false);
38+
if (isVisible) {
39+
return;
40+
}
41+
42+
if (attempt < maxAttempts) {
43+
// Reload the page and try again — the backend auth system may still be initializing
44+
await page.reload({ waitUntil: 'domcontentloaded' });
45+
}
46+
}
47+
}
48+
2449
setup('authenticate', async ({ page }) => {
25-
await page.goto('/', { waitUntil: 'networkidle' });
50+
await navigateToLoginPage(page);
2651

2752
// Wait for login form to be visible
2853
await page.getByTestId('auth-username-input').waitFor({ state: 'visible', timeout: 30_000 });

0 commit comments

Comments
 (0)