Skip to content

Commit 44c0d84

Browse files
enesozturkclaude
andcommitted
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) <noreply@anthropic.com>
1 parent f913185 commit 44c0d84

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

apps/laboratory/tests/shared/pages/ModalPage.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -924,30 +924,37 @@ export class ModalPage {
924924
}
925925

926926
async clickOpenWebApp() {
927-
let url = ''
928-
929927
const openButton = this.page.getByTestId('w3m-connecting-widget-secondary-button')
930928
await expect(openButton).toBeVisible()
931929
await expect(openButton).toHaveText('Open')
932930

933-
while (!url) {
934-
await openButton.click()
935-
await this.page.waitForTimeout(500)
936-
937-
const pages = this.page.context().pages()
938-
939-
// Check if more than 1 tab is open
940-
if (pages.length > 1) {
941-
const lastTab = pages[pages.length - 1]
942-
943-
if (lastTab) {
944-
url = lastTab.url()
945-
break
946-
}
931+
/*
932+
* Patch window.open to capture the URL synchronously at the moment AppKit
933+
* calls it. Reading lastTab.url() after the click races against external
934+
* redirects (e.g. some wallets' webapp_link points to chromewebstore.google.com
935+
* which immediately redirects to a Google consent page, dropping the ?uri= param).
936+
*/
937+
await this.page.evaluate(() => {
938+
const original = window.open
939+
;(window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl = ''
940+
window.open = function patchedOpen(...args: Parameters<typeof window.open>) {
941+
;(window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl = String(
942+
args[0] ?? ''
943+
)
944+
return original.apply(this, args)
947945
}
948-
}
946+
})
949947

950-
return url
948+
await openButton.click()
949+
await this.page.waitForFunction(
950+
() => (window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl !== '',
951+
undefined,
952+
{ timeout: 10_000 }
953+
)
954+
955+
return this.page.evaluate(
956+
() => (window as unknown as { __capturedOpenUrl: string }).__capturedOpenUrl
957+
)
951958
}
952959

953960
async search(value: string) {

0 commit comments

Comments
 (0)