From a4f6a0cc4de7d8c14e762cd7f5ac58e59d86062f Mon Sep 17 00:00:00 2001 From: Enes Date: Wed, 6 May 2026 12:47:38 +0300 Subject: [PATCH] fix(tests): capture window.open URL before redirects in clickOpenWebApp Some wallets' webapp_link points to URLs that immediately redirect to external services (e.g. MathWallet's webapp_link is chromewebstore.google.com which redirects through consent.google.com, dropping the ?uri= query param). Reading lastTab.url() after a 500ms timeout races against these redirects, making the wallet-features.spec.ts:131 "open web app wallet" test flaky on CI. Patch window.open in the page context to capture the URL synchronously at call time, before any navigation/redirect happens. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../tests/shared/pages/ModalPage.ts | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/apps/laboratory/tests/shared/pages/ModalPage.ts b/apps/laboratory/tests/shared/pages/ModalPage.ts index 54963df15b..70d9b599ef 100644 --- a/apps/laboratory/tests/shared/pages/ModalPage.ts +++ b/apps/laboratory/tests/shared/pages/ModalPage.ts @@ -924,30 +924,38 @@ export class ModalPage { } async clickOpenWebApp() { - let url = '' - const openButton = this.page.getByTestId('w3m-connecting-widget-secondary-button') await expect(openButton).toBeVisible() await expect(openButton).toHaveText('Open') - while (!url) { - await openButton.click() - await this.page.waitForTimeout(500) - - const pages = this.page.context().pages() - - // Check if more than 1 tab is open - if (pages.length > 1) { - const lastTab = pages[pages.length - 1] - - if (lastTab) { - url = lastTab.url() - break - } + /* + * Patch window.open to capture the URL synchronously at the moment AppKit + * calls it. Reading lastTab.url() after the click races against external + * redirects (e.g. some wallets' webapp_link points to chromewebstore.google.com + * which immediately redirects to a Google consent page, dropping the ?uri= param). + */ + await this.page.evaluate(() => { + const original = window.open + ;(window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl = '' + window.open = function open(...args: Parameters) { + ;(window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl = String( + args[0] ?? '' + ) + + return original.apply(this, args) } - } + }) - return url + await openButton.click() + await this.page.waitForFunction( + () => (window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl !== '', + undefined, + { timeout: 10_000 } + ) + + return this.page.evaluate( + () => (window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl + ) } async search(value: string) {