-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add
unlockForFixture
action
- Loading branch information
1 parent
1b4dfc0
commit c837c55
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './connectToDapp' | ||
export * from './lock' | ||
export * from './unlock' | ||
export * from './unlockForFixture' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { Page } from '@playwright/test' | ||
import { errors as playwrightErrors } from '@playwright/test' | ||
import { CrashPageSelectors, HomePageSelectors, LoadingSelectors, unlock } from '../' | ||
|
||
export async function unlockForFixture(page: Page, password: string) { | ||
await unlock(page, password) | ||
|
||
await page.locator(LoadingSelectors.spinner).waitFor({ | ||
state: 'hidden', | ||
timeout: 3000 // TODO: Extract & Make this timeout configurable. | ||
}) | ||
|
||
await retryIfMetaMaskCrashAfterUnlock(page) | ||
} | ||
|
||
async function retryIfMetaMaskCrashAfterUnlock(page: Page) { | ||
const isHomePageVisible = await page.locator(HomePageSelectors.logo).isVisible() | ||
|
||
if (!isHomePageVisible) { | ||
if (await page.locator(CrashPageSelectors.header).isVisible()) { | ||
const errors = await page.locator(CrashPageSelectors.errors).allTextContents() | ||
|
||
console.warn(['[RetryIfMetaMaskCrashAfterUnlock] MetaMask crashed due to:', ...errors].join('\n')) | ||
|
||
console.log('[RetryIfMetaMaskCrashAfterUnlock] Reloading page...') | ||
await page.reload() | ||
|
||
try { | ||
await page.locator(HomePageSelectors.logo).waitFor({ | ||
state: 'visible', | ||
timeout: 10_000 // TODO: Extract & Make this timeout configurable. | ||
}) | ||
console.log('[RetryIfMetaMaskCrashAfterUnlock] Successfully restored MetaMask!') | ||
} catch (e) { | ||
if (e instanceof playwrightErrors.TimeoutError) { | ||
throw new Error( | ||
['[RetryIfMetaMaskCrashAfterUnlock] Reload did not help. Throwing with the crash cause:', ...errors].join( | ||
'\n' | ||
) | ||
) | ||
} | ||
|
||
throw e | ||
} | ||
} | ||
} | ||
} |