@@ -44,7 +44,25 @@ export class TestingBehatDomUtilsService {
4444 * @returns Whether the element is visible or not.
4545 */
4646 isElementVisible ( element : HTMLElement , container ?: HTMLElement ) : boolean {
47- if ( element . getAttribute ( 'aria-hidden' ) === 'true' || getComputedStyle ( element ) . display === 'none' ) {
47+ if ( element . getAttribute ( 'aria-hidden' ) === 'true' ) {
48+ if (
49+ element === document . body . querySelector ( 'ion-app > ion-router-outlet' ) &&
50+ ( document . body . querySelector ( 'ion-toast.hydrated:not(.overlay-hidden)' ) ||
51+ ! document . body . querySelector (
52+ 'ion-action-sheet.hydrated:not(.overlay-hidden), ion-alert.hydrated:not(.overlay-hidden)\
53+ ion-loading.hydrated:not(.overlay-hidden), ion-modal.hydrated:not(.overlay-hidden),\
54+ ion-picker.hydrated:not(.overlay-hidden), ion-popover.hydrated:not(.overlay-hidden)' ,
55+ ) )
56+ ) {
57+ // Main ion-router-outlet is aria-hidden when a toast is open but the UI is not blocked...
58+ // It also may be hidden due to an error in Ionic. See fixOverlayAriaHidden function.
59+ return true ;
60+ }
61+
62+ return false ;
63+ }
64+
65+ if ( getComputedStyle ( element ) . display === 'none' ) {
4866 return false ;
4967 }
5068
@@ -371,30 +389,34 @@ export class TestingBehatDomUtilsService {
371389 */
372390 protected getCurrentTopContainerElements ( containerName ?: string ) : HTMLElement [ ] {
373391 let containers = Array . from ( document . body . querySelectorAll < HTMLElement > ( [
374- 'ion-alert.hydrated' ,
375- 'ion-popover.hydrated' ,
376- 'ion-action-sheet.hydrated' ,
377- 'ion-modal.hydrated' ,
392+ 'ion-alert.hydrated:not(.overlay-hidden) ' ,
393+ 'ion-popover.hydrated:not(.overlay-hidden) ' ,
394+ 'ion-action-sheet.hydrated:not(.overlay-hidden) ' ,
395+ 'ion-modal.hydrated:not(.overlay-hidden) ' ,
378396 'core-user-tours-user-tour.is-active' ,
379- 'ion-toast.hydrated' ,
380- 'page-core-mainmenu' ,
381- 'ion-app' ,
397+ 'ion-toast.hydrated:not(.overlay-hidden)' ,
398+ 'page-core-mainmenu > ion-tabs:not(.tabshidden) > .mainmenu-tabs' ,
399+ 'page-core-mainmenu > .core-network-message' ,
400+ '.ion-page:not(.ion-page-hidden)' ,
382401 ] . join ( ', ' ) ) ) ;
402+ const ionApp = document . querySelector < HTMLElement > ( 'ion-app' ) ?? undefined ;
383403
384404 containers = containers
385405 . filter ( container => {
386- if ( ! this . isElementVisible ( container ) ) {
387- // Ignore containers not visible.
388- return false ;
389- }
390406
391407 if ( container . tagName === 'ION-ALERT' ) {
392408 // For some reason, in Behat sometimes alerts aren't removed from DOM, the close animation doesn't finish.
393409 // Filter alerts with pointer-events none since that style is set before the close animation starts.
394410 return container . style . pointerEvents !== 'none' ;
395411 }
396412
397- return true ;
413+ // Avoid searching in the whole app.
414+ if ( container . tagName === 'ION-APP' || container . tagName === 'PAGE-CORE-MAINMENU' ) {
415+ return false ;
416+ }
417+
418+ // Ignore not visible containers.
419+ return this . isElementVisible ( container , ionApp ) ;
398420 } )
399421 // Sort them by z-index.
400422 . sort ( ( a , b ) => Number ( getComputedStyle ( b ) . zIndex ) - Number ( getComputedStyle ( a ) . zIndex ) ) ;
0 commit comments