Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions run/desktop/DesktopWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,9 @@ export class DesktopWrapper implements IBaseDeviceWrapper {
/** Returns immediately if the loader never shows — see the helper for why that is a pass. */
public async waitForLoadingAnimationToFinish(
loader: DataTestId,
appearWithinMs?: number,
finishWithinMs?: number
options?: { appearWithinMs?: number; finishWithinMs?: number; windowMayClose?: boolean }
): Promise<void> {
await waitForLoadingAnimationToFinish(this.page, loader, appearWithinMs, finishWithinMs);
await waitForLoadingAnimationToFinish(this.page, loader, options);
}

public async clickOnTextMessage(
Expand Down
25 changes: 22 additions & 3 deletions run/desktop/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,18 @@ export async function waitForMatchingPlaceholder(
* `network_page.spec.ts` grew its own `networkDataLoaded` rather than use this: a loader that never
* cleared used to hang until the test timed out with nothing to go on. Now it fails against this
* selector, which says what was still spinning.
*
* `windowMayClose` is for the work that restarts the app (clearing all data): the loader goes away
* with the window, which Playwright reports as a target-closed error rather than a hidden element.
*/
export async function waitForLoadingAnimationToFinish(
window: Page,
loader: DataTestId,
appearWithinMs = 2_000,
finishWithinMs = 60_000
{
appearWithinMs = 2_000,
finishWithinMs = 60_000,
windowMayClose = false,
}: { appearWithinMs?: number; finishWithinMs?: number; windowMayClose?: boolean } = {}
) {
const selector = buildSelectorEscapeText({ strategy: 'data-testid', selector: loader });

Expand All @@ -234,10 +240,23 @@ export async function waitForLoadingAnimationToFinish(
}

console.info(`${loader} was found, waiting for it to be gone`);
await window.waitForSelector(selector, { timeout: finishWithinMs, state: 'hidden' });
try {
await window.waitForSelector(selector, { timeout: finishWithinMs, state: 'hidden' });
} catch (e) {
if (!windowMayClose || !windowWentAway(window, e as Error)) {
throw e;
}
console.info(`${loader} went away with its window — the app restarted`);
return;
}
console.info('Loading animation has finished');
}

/** `isClosed()` does not always flip before the pending wait rejects, hence the message check too. */
function windowWentAway(window: Page, e: Error): boolean {
return window.isClosed() || /closed/i.test(e.message);
}

/**
* The absence counterpart to `waitForElement`. `hidden` covers never-attached, so it also suits an
* element that should never have rendered.
Expand Down
11 changes: 6 additions & 5 deletions run/test/specs/desktop/delete_account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ sessionTestTwoWindows('Delete account from swarm', async ([windowA, windowB]) =>
// Confirm deletion by clicking Clear, twice
await windowA.clickOnMatchingText(tStripped('clear'));
await windowA.clickOnMatchingText(tStripped('clear'));
await windowA.waitForLoadingAnimationToFinish(Global.loadingSpinner.selector);
// await sleepFor(7500);
// Wait for window to close and reopen

// await windowA.close();
// The delete restarts the app, so the spinner is optional at both ends: on a fast network it
// can be gone before we look, and when we do catch it, it leaves with the window.
await windowA.waitForLoadingAnimationToFinish(Global.loadingSpinner.selector, {
appearWithinMs: 1_000,
windowMayClose: true,
});
restoringWindows = await openAppsAndWaitWindows(1); // not using sessionTest here as we need to close and reopen one of the window
const [restoringWindowPage] = restoringWindows;
const restoringWindow = new DesktopWrapper(restoringWindowPage, 'alice-restoring');
Expand Down