@@ -21,21 +21,29 @@ export const byTestId = (testId: string) => $(`[data-testid="${testId}"]`);
2121 */
2222export async function waitForModalClose ( timeout = TIMEOUT . short ) : Promise < void > {
2323 try {
24- const overlay = await $ ( '.fixed.inset-0.bg-black\\/20' ) ;
25- const exists = await overlay . isExisting ( ) . catch ( ( ) => false ) ;
26-
27- if ( ! exists ) {
28- return ; // No modal, nothing to wait for
29- }
30-
31- // Try to wait for it to close naturally
32- const closed = await overlay . waitForDisplayed ( { timeout, reverse : true } ) . then ( ( ) => true ) . catch ( ( ) => false ) ;
33-
34- if ( ! closed ) {
35- // Modal still open - try to dismiss it with Escape key
36- console . log ( '[waitForModalClose] Modal still displayed, trying Escape key' ) ;
37- await browser . keys ( 'Escape' ) ;
38- await browser . pause ( 500 ) ;
24+ // Match any fixed fullscreen overlay (bg-black/20, bg-black/50, bg-black/60)
25+ const overlays = await $$ ( '.fixed.inset-0' ) ;
26+
27+ for ( const overlay of overlays ) {
28+ const isDisplayed = await overlay . isDisplayed ( ) . catch ( ( ) => false ) ;
29+ if ( ! isDisplayed ) continue ;
30+
31+ // Check if it looks like a modal backdrop (has bg-black in its classes)
32+ const cls = await overlay . getAttribute ( 'class' ) . catch ( ( ) => '' ) ?? '' ;
33+ if ( ! cls . includes ( 'bg-black' ) ) continue ;
34+
35+ // Try to wait for it to close naturally
36+ const closed = await overlay
37+ . waitForDisplayed ( { timeout, reverse : true } )
38+ . then ( ( ) => true )
39+ . catch ( ( ) => false ) ;
40+
41+ if ( ! closed ) {
42+ // Modal still open - try to dismiss it with Escape key
43+ console . log ( '[waitForModalClose] Modal still displayed, trying Escape key' ) ;
44+ await browser . keys ( 'Escape' ) ;
45+ await browser . pause ( 500 ) ;
46+ }
3947 }
4048 } catch {
4149 // Silently continue - modal handling shouldn't fail tests
0 commit comments