@@ -20,59 +20,22 @@ export async function loginOnCurrentPage(page: Page) {
2020 await expect ( connectBtn ) . toBeVisible ( { timeout : 15000 } ) ;
2121
2222 // Allow SvelteKit hydration to complete.
23- // Use 'load' waitUntil for the initial page navigation so we know JS has loaded.
24- // Then add extra wait to ensure Svelte components are fully initialized.
2523 await page . waitForTimeout ( 3000 ) ;
2624
27- // Try the normal click first (most reliable when hydration is complete)
25+ // Click the Connect button.
2826 await connectBtn . click ( { force : true } ) ;
2927
30- // Wait for menu to open
31- let menuOpened = await page . locator ( '.dev-key-input' ) . count ( ) > 0 ;
28+ // Use expect.poll to wait for the dev-key-input to appear in the DOM.
29+ // This polls every 200ms for up to 15 seconds, which handles CI timing variations.
30+ // The element only appears when both: (1) menu is open AND (2) isTestnet is true.
31+ await expect
32+ . poll (
33+ async ( ) => ( await page . locator ( '.dev-key-input' ) . count ( ) ) > 0 ,
34+ { timeout : 15000 , intervals : [ 200 , 500 , 1000 , 2000 ] }
35+ )
36+ . toBe ( true ) ;
3237
33- // If click didn't work, try SMUI menu.setOpen directly via page.evaluate
34- if ( ! menuOpened ) {
35- await page . waitForTimeout ( 500 ) ;
36- menuOpened = await page . locator ( '.dev-key-input' ) . count ( ) > 0 ;
37- }
38-
39- // If still not open, find the SMUI menu component and call setOpen(true)
40- if ( ! menuOpened ) {
41- await page . evaluate ( ( ) => {
42- // Find SMUI menu instances and call setOpen(true)
43- const menuSurfaces = document . querySelectorAll ( '.mdc-menu-surface' ) ;
44- for ( const surface of menuSurfaces ) {
45- const menu = ( surface as HTMLElement & { _menu ?: { setOpen : ( v : boolean ) => void } } ) . _menu ;
46- if ( menu ?. setOpen ) {
47- menu . setOpen ( true ) ;
48- break ;
49- }
50- }
51- } ) ;
52- await page . waitForTimeout ( 500 ) ;
53- menuOpened = await page . locator ( '.dev-key-input' ) . count ( ) > 0 ;
54- }
55-
56- // Final fallback: try dispatchEvent click
57- if ( ! menuOpened ) {
58- await page . evaluate ( ( ) => {
59- const btns = document . querySelectorAll ( 'header button' ) ;
60- for ( const btn of btns ) {
61- if ( btn . textContent ?. trim ( ) . includes ( 'Connect' ) ) {
62- btn . dispatchEvent ( new MouseEvent ( 'click' , { bubbles : true , cancelable : true } ) ) ;
63- break ;
64- }
65- }
66- } ) ;
67- await page . waitForTimeout ( 1000 ) ;
68- menuOpened = await page . locator ( '.dev-key-input' ) . count ( ) > 0 ;
69- }
70-
71- if ( ! menuOpened ) {
72- throw new Error ( 'Menu did not open after all fallback attempts' ) ;
73- }
74-
75- // Now the element is in the DOM — wait for it to be visible (animation complete).
38+ // The element is in the DOM — wait for it to be visible (animation complete).
7639 const keyInput = page . locator ( '.dev-key-input' ) ;
7740 await expect ( keyInput ) . toBeVisible ( { timeout : 10000 } ) ;
7841 await keyInput . fill ( TEST_PRIVATE_KEY ) ;
0 commit comments