Skip to content

Commit

Permalink
error handling on selector level
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSero committed Jun 21, 2024
1 parent 51e053a commit 49f08a9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wallets/metamask/src/utils/waitFor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Page } from '@playwright/test'
import { errors } from '@playwright/test'

export const waitUntilStable = async (page: Page) => {
await page.waitForLoadState('domcontentloaded')
Expand All @@ -7,7 +8,17 @@ export const waitUntilStable = async (page: Page) => {

export const waitForSelector = async (selector: string, page: Page, timeout: number) => {
await waitUntilStable(page)
await page.waitForSelector(selector, { state: 'hidden', timeout })

try {
await page.waitForSelector(selector, { state: 'hidden', timeout })
} catch (error) {
if (error instanceof errors.TimeoutError) {
console.log(`Loading indicator '${selector}' not found - continuing.`)
} else {
console.log(`Error while waiting for loading indicator '${selector}' to disappear`)
throw error
}
}
}

// Inlining the sleep function here cause this is one of the few places in the entire codebase where sleep should be used!
Expand Down

0 comments on commit 49f08a9

Please sign in to comment.