-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1179ad
commit b39afcd
Showing
3 changed files
with
149 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { Page } from '@playwright/test' | ||
import { errors as playwrightErrors } from '@playwright/test' | ||
import { KeplrWallet } from '..' | ||
Check notice Code scanning / CodeQL Unused variable, import, function or class Note
Unused import KeplrWallet.
|
||
import { CrashPage, HomePage } from '../pages' | ||
import { closePopover, closeRecoveryPhraseReminder } from '../pages/HomePage/actions' | ||
import { waitForSpinnerToVanish } from '../utils/waitForSpinnerToVanish' | ||
|
||
/** | ||
* A more advanced version of the `MetaMask.unlock()` function that incorporates various workarounds for MetaMask issues, among other things. | ||
* This function should be used instead of the `MetaMask.unlock()` when passing it to the `testWithSynpress` function. | ||
* | ||
* @param page - The MetaMask tab page. | ||
* @param password - The password of the MetaMask wallet. | ||
*/ | ||
export async function unlockForFixture(page: Page, password: string) { | ||
const metamask = new MetaMask(page.context(), page, password) | ||
|
||
await unlockWalletButReloadIfSpinnerDoesNotVanish(metamask) | ||
|
||
await retryIfMetaMaskCrashAfterUnlock(page) | ||
|
||
await closePopover(page) | ||
await closeRecoveryPhraseReminder(page) | ||
} | ||
|
||
async function unlockWalletButReloadIfSpinnerDoesNotVanish(metamask: MetaMask) { | ||
try { | ||
await metamask.unlock() | ||
} catch (e) { | ||
if (e instanceof playwrightErrors.TimeoutError) { | ||
console.warn('[UnlockWalletButReloadIfSpinnerDoesNotVanish] Unlocking MetaMask timed out. Reloading page...') | ||
|
||
const page = metamask.page | ||
|
||
await page.reload() | ||
await waitForSpinnerToVanish(page) | ||
} else { | ||
throw e | ||
} | ||
} | ||
} | ||
|
||
async function retryIfMetaMaskCrashAfterUnlock(page: Page) { | ||
const homePageLogoLocator = page.locator(HomePage.selectors.logo) | ||
|
||
const isHomePageLogoVisible = await homePageLogoLocator.isVisible() | ||
const isPopoverVisible = await page.locator(HomePage.selectors.popover.closeButton).isVisible() | ||
|
||
if (!isHomePageLogoVisible && !isPopoverVisible) { | ||
if (await page.locator(CrashPage.selectors.header).isVisible()) { | ||
const errors = await page.locator(CrashPage.selectors.errors).allTextContents() | ||
|
||
console.warn(['[RetryIfMetaMaskCrashAfterUnlock] MetaMask crashed due to:', ...errors].join('\n')) | ||
|
||
console.log('[RetryIfMetaMaskCrashAfterUnlock] Reloading page...') | ||
await page.reload() | ||
|
||
try { | ||
await homePageLogoLocator.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 | ||
} | ||
} | ||
} | ||
} |
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
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,4 +1,5 @@ | ||
import { testWithSynpress } from "@synthetixio/synpress-core"; | ||
import { keplrFixtures } from "../src"; | ||
import connectedSetup from "./wallet-setup/connected.setup"; | ||
|
||
export default testWithSynpress(keplrFixtures) | ||
export default testWithSynpress(keplrFixtures(connectedSetup)) |