File tree Expand file tree Collapse file tree 8 files changed +102
-1
lines changed
packages/compass-e2e-tests/helpers Expand file tree Collapse file tree 8 files changed +102
-1
lines changed Original file line number Diff line number Diff line change 1+ import type { ChainablePromiseArray } from 'webdriverio' ;
2+
3+ import { Selectors } from '../compass' ;
4+ import type { CompassBrowser } from '../compass-browser' ;
5+
6+ export function getOpenModals (
7+ browser : CompassBrowser ,
8+ selector : string = Selectors . LGModal
9+ ) : ChainablePromiseArray {
10+ return browser . custom$$ ( 'dialogOpen' , selector ) ;
11+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ export async function hideVisibleModal(browser: CompassBrowser): Promise<void> {
1515 const waitOptions = { timeout : 2_000 } ;
1616 try {
1717 await browser . clickVisible ( Selectors . LGModalClose , waitOptions ) ;
18- await browser . $ ( Selectors . LGModal ) . waitForDisplayed ( { reverse : true } ) ;
18+ await browser
19+ . $ ( Selectors . LGModal )
20+ . waitForDisplayed ( { reverse : true , ...waitOptions } ) ;
1921 } catch ( err ) {
2022 // if the modal disappears by itself in the meantime, that's fine
2123 debug ( 'ignoring' , err ) ;
Original file line number Diff line number Diff line change @@ -67,3 +67,7 @@ export * from './read-stage-operators';
6767export * from './click-confirmation-action' ;
6868export * from './get-input-by-label' ;
6969export * from './resize-window' ;
70+ export * from './get-open-modals' ;
71+ export * from './is-modal-open' ;
72+ export * from './is-modal-eventually-open' ;
73+ export * from './wait-for-open-modal' ;
Original file line number Diff line number Diff line change 1+ import { Selectors } from '../compass' ;
2+ import type { CompassBrowser } from '../compass-browser' ;
3+
4+ export async function isModalEventuallyOpen (
5+ browser : CompassBrowser ,
6+ selector : string = Selectors . LGModal ,
7+ timeout ?: number
8+ ) : Promise < boolean > {
9+ try {
10+ await browser . waitForOpenModal ( selector , { timeout } ) ;
11+ // return true if it opens before the timeout expires
12+ return true ;
13+ } catch {
14+ return false ;
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ import { Selectors } from '../compass' ;
2+ import type { CompassBrowser } from '../compass-browser' ;
3+
4+ export async function isModalOpen (
5+ browser : CompassBrowser ,
6+ selector : string = Selectors . LGModal
7+ ) : Promise < boolean > {
8+ const modals = await browser . getOpenModals ( selector ) ;
9+ const count = await modals . length ;
10+ return count > 0 ;
11+ }
Original file line number Diff line number Diff line change 1+ import { inspect } from 'node:util' ;
2+ import type { WaitForOptions } from 'webdriverio' ;
3+ import type { CompassBrowser } from '../compass-browser' ;
4+
5+ export async function waitForOpenModal (
6+ browser : CompassBrowser ,
7+ selector : string ,
8+ { reverse = false , ...options } : WaitForOptions = { }
9+ ) : Promise < void > {
10+ await browser . waitUntil (
11+ async ( ) => {
12+ const modals = await browser . getOpenModals ( selector ) ;
13+ const count = await modals . length ;
14+ if ( reverse ) {
15+ return count === 0 ;
16+ } else if ( count === 0 ) {
17+ return false ;
18+ } else {
19+ for ( const modal of modals ) {
20+ // Ensure any modals are interactable if open
21+ await modal . waitForClickable ( {
22+ timeoutMsg : 'Timeout waiting for open modal to become clickable' ,
23+ ...options ,
24+ } ) ;
25+ }
26+ return true ;
27+ }
28+ } ,
29+ {
30+ timeoutMsg : `Timeout waiting for modal '${ inspect ( selector ) } ' to ${
31+ reverse ? 'close' : 'open'
32+ } `,
33+ ...options ,
34+ }
35+ ) ;
36+ }
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ import treeKill from 'tree-kill';
4444import { downloadPath } from './downloads' ;
4545import path from 'path' ;
4646import { globalFixturesAbortController } from './test-runner-global-fixtures' ;
47+ import { dialogOpenLocator } from './dialog-open-locator-strategy' ;
4748
4849const killAsync = async ( pid : number , signal ?: string ) => {
4950 return new Promise < void > ( ( resolve , reject ) => {
@@ -200,6 +201,9 @@ export class Compass {
200201 }
201202 ) ;
202203
204+ // Adding a custom locator strategy to help locate open dialogs from a selector synchronously
205+ browser . addLocatorStrategy ( 'dialogOpen' , dialogOpenLocator ) ;
206+
203207 this . addDebugger ( ) ;
204208 }
205209
Original file line number Diff line number Diff line change 1+ export function dialogOpenLocator ( selector : string ) {
2+ // eslint-disable-next-line no-restricted-globals -- This runs in the browser
3+ const result : HTMLDialogElement [ ] = [ ] ;
4+ // eslint-disable-next-line no-restricted-globals -- This runs in the browser
5+ const elements = document . querySelectorAll ( selector ) ;
6+ for ( let i = 0 ; i < elements . length ; i ++ ) {
7+ const element = elements [ i ] ;
8+ if (
9+ // eslint-disable-next-line no-restricted-globals -- This runs in the browser
10+ element instanceof HTMLDialogElement &&
11+ element . open
12+ ) {
13+ result . push ( element ) ;
14+ }
15+ }
16+ return result ;
17+ }
You can’t perform that action at this time.
0 commit comments