@@ -65,19 +65,33 @@ export class DashboardPage {
6565 await this . dashboardTitle . waitFor ( { state : 'visible' , timeout : 60000 } ) ;
6666 await this . ensureMenuVisible ( ) ;
6767
68- try {
69- await this . pimMenu . scrollIntoViewIfNeeded ( ) ;
70- await this . pimMenu . waitFor ( { state : 'visible' , timeout : 15000 } ) ;
71- await this . pimMenu . click ( ) ;
72- await this . page . waitForURL ( / .* p i m / , { timeout : 30000 } ) ;
73- } catch ( e ) {
74- // Fallback: navigate directly via URL if menu click fails
75- await this . page . goto ( '/web/index.php/pim/viewEmployeeList' ) ;
76- await this . page . waitForURL ( / .* p i m / , { timeout : 30000 } ) ;
77- }
68+ await this . pimMenu . waitFor ( { state : 'attached' , timeout : 30000 } ) ;
69+ await this . pimMenu . scrollIntoViewIfNeeded ( ) ;
7870
79- // Verify PIM page loaded
80- await this . page . getByRole ( 'heading' , { name : 'PIM' } ) . waitFor ( { state : 'visible' , timeout : 30000 } ) ;
71+ for ( let attempt = 0 ; attempt < 3 ; attempt ++ ) {
72+ try {
73+ await this . pimMenu . waitFor ( { state : 'visible' , timeout : 30000 } ) ;
74+ // Wait for menu to stabilize (animations, especially on mobile)
75+ await this . page . waitForTimeout ( 500 ) ;
76+ await this . pimMenu . click ( { force : true } ) ;
77+ await this . page . waitForURL ( / .* p i m / , { timeout : 90000 } ) ;
78+ await this . page . getByRole ( 'heading' , { name : 'PIM' } ) . waitFor ( { state : 'visible' , timeout : 90000 } ) ;
79+ return ;
80+ } catch ( e ) {
81+ // If this is the last attempt, break and throw below
82+ if ( attempt === 2 ) break ;
83+
84+ // Try to recover — but guard against closed page
85+ try {
86+ await this . ensureMenuVisible ( ) ;
87+ await this . page . waitForTimeout ( 3000 ) ;
88+ } catch {
89+ // Page is likely closed/crashed — no point retrying
90+ throw new Error ( `Browser/page was closed unexpectedly during PIM navigation. Original error: ${ e . message } ` ) ;
91+ }
92+ }
93+ }
94+ throw new Error ( 'Could not navigate to PIM menu after 3 attempts' ) ;
8195 }
8296
8397 async navigateToLeave ( ) {
0 commit comments