From c3480f8277040da4a493ed81d2868c78f3e39afe Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 26 Aug 2024 10:54:12 +0100 Subject: [PATCH] fix(e2e): deal with the fact that the modal might already be closed (#6153) * deal with the fact that the modal might already be closed * pull out the hide modal logic, use it in two places --- .../helpers/commands/disconnect.ts | 6 +---- .../helpers/commands/hide-visible-modal.ts | 24 +++++++++++++++++++ .../helpers/commands/index.ts | 1 + .../helpers/commands/remove-connections.ts | 6 +---- 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 packages/compass-e2e-tests/helpers/commands/hide-visible-modal.ts diff --git a/packages/compass-e2e-tests/helpers/commands/disconnect.ts b/packages/compass-e2e-tests/helpers/commands/disconnect.ts index 3b04ebf3699..c9f2d0788fa 100644 --- a/packages/compass-e2e-tests/helpers/commands/disconnect.ts +++ b/packages/compass-e2e-tests/helpers/commands/disconnect.ts @@ -48,11 +48,7 @@ async function resetForDisconnect( closeToasts?: boolean; } = {} ) { - if (await browser.$(Selectors.LGModal).isDisplayed()) { - // close any modals that might be in the way - await browser.clickVisible(Selectors.LGModalClose); - await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true }); - } + await browser.hideVisibleModal(); // Collapse all the connections so that they will all hopefully fit on screen // and therefore be rendered. diff --git a/packages/compass-e2e-tests/helpers/commands/hide-visible-modal.ts b/packages/compass-e2e-tests/helpers/commands/hide-visible-modal.ts new file mode 100644 index 00000000000..11125cc4e83 --- /dev/null +++ b/packages/compass-e2e-tests/helpers/commands/hide-visible-modal.ts @@ -0,0 +1,24 @@ +import type { CompassBrowser } from '../compass-browser'; +import * as Selectors from '../selectors'; + +import Debug from 'debug'; + +const debug = Debug('compass-e2e-tests'); + +export async function hideVisibleModal(browser: CompassBrowser): Promise { + // If there's some race condition where something else is closing the modal at + // the same time we're trying to close the modal, then make it error out + // quickly so it can be ignored and we move on. + + if (await browser.$(Selectors.LGModal).isDisplayed()) { + // close any modals that might be in the way + const waitOptions = { timeout: 2_000 }; + try { + await browser.clickVisible(Selectors.LGModalClose, waitOptions); + await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true }); + } catch (err) { + // if the modal disappears by itself in the meantime, that's fine + debug('ignoring', err); + } + } +} diff --git a/packages/compass-e2e-tests/helpers/commands/index.ts b/packages/compass-e2e-tests/helpers/commands/index.ts index 45c9d427af0..50e7b830042 100644 --- a/packages/compass-e2e-tests/helpers/commands/index.ts +++ b/packages/compass-e2e-tests/helpers/commands/index.ts @@ -59,5 +59,6 @@ export * from './create-index'; export * from './drop-index'; export * from './hide-index'; export * from './unhide-index'; +export * from './hide-visible-modal'; export * from './hide-visible-toasts'; export * from './sidebar-collection'; diff --git a/packages/compass-e2e-tests/helpers/commands/remove-connections.ts b/packages/compass-e2e-tests/helpers/commands/remove-connections.ts index a58ff2b7575..74e654e9c2d 100644 --- a/packages/compass-e2e-tests/helpers/commands/remove-connections.ts +++ b/packages/compass-e2e-tests/helpers/commands/remove-connections.ts @@ -3,11 +3,7 @@ import type { CompassBrowser } from '../compass-browser'; import * as Selectors from '../selectors'; async function resetForRemove(browser: CompassBrowser) { - if (await browser.$(Selectors.LGModal).isDisplayed()) { - // close any modals that might be in the way - await browser.clickVisible(Selectors.LGModalClose); - await browser.$(Selectors.LGModal).waitForDisplayed({ reverse: true }); - } + await browser.hideVisibleModal(); // Collapse all the connections so that they will all hopefully fit on screen // and therefore be rendered.