diff --git a/packages/core/src/testWithSynpress.ts b/packages/core/src/testWithSynpress.ts index 26219bc1f..498a8a58e 100644 --- a/packages/core/src/testWithSynpress.ts +++ b/packages/core/src/testWithSynpress.ts @@ -5,4 +5,4 @@ export default function testWithSynpress( customFixtures: TestType ) { return mergeTests(base, customFixtures) -} \ No newline at end of file +} diff --git a/wallets/metamask/playwright.config.ts b/wallets/metamask/playwright.config.ts index 0994ed0a0..b15e7f37b 100644 --- a/wallets/metamask/playwright.config.ts +++ b/wallets/metamask/playwright.config.ts @@ -9,7 +9,7 @@ export default defineConfig({ // We're increasing the timeout to 60 seconds to allow all traces to be recorded. // Sometimes it threw an error saying that traces were not recorded in the 30 seconds timeout limit. - timeout: 60_000, + timeout: 90_000, // Run all tests in parallel. fullyParallel: true, diff --git a/wallets/metamask/src/fixture-actions/importAndConnectForFixtures.ts b/wallets/metamask/src/fixture-actions/importAndConnectForFixtures.ts index 0b41900b7..d672390ac 100644 --- a/wallets/metamask/src/fixture-actions/importAndConnectForFixtures.ts +++ b/wallets/metamask/src/fixture-actions/importAndConnectForFixtures.ts @@ -1,17 +1,32 @@ import type { Page } from '@playwright/test' import { MetaMask } from '..' - -export async function importAndConnectForFixtures(page: Page, seedPhrase: string, password: string, extensionId: string) { +import { retryIfMetaMaskCrashAfterUnlock } from '..' +import { closePopover } from '../pages/HomePage/actions' + +export async function importAndConnectForFixtures( + page: Page, + seedPhrase: string, + password: string, + extensionId: string +) { const metamask = new MetaMask(page.context(), page, password, extensionId) await metamask.importWallet(seedPhrase) + await metamask.openSettings() const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus + await metamask.openSidebarMenu(SidebarMenus.Advanced) await metamask.toggleDismissSecretRecoveryPhraseReminder() + await page.goto(`chrome-extension://${extensionId}/home.html`) + + await retryIfMetaMaskCrashAfterUnlock(page) + + await closePopover(page) + const newPage = await page.context().newPage() await newPage.goto('http://localhost:9999') diff --git a/wallets/metamask/src/fixture-actions/noCachMetaMaskSetup.ts b/wallets/metamask/src/fixture-actions/noCachMetaMaskSetup.ts index 5ac058072..bf847a94b 100644 --- a/wallets/metamask/src/fixture-actions/noCachMetaMaskSetup.ts +++ b/wallets/metamask/src/fixture-actions/noCachMetaMaskSetup.ts @@ -1,10 +1,10 @@ import path from 'node:path' -import { DEFAULT_METAMASK_VERSION, EXTENSION_DOWNLOAD_URL } from '../utils/constants' import { type BrowserContext, chromium } from '@playwright/test' import appRoot from 'app-root-path' import axios from 'axios' import fs from 'fs-extra' import unzipper from 'unzipper' +import { DEFAULT_METAMASK_VERSION, EXTENSION_DOWNLOAD_URL } from '../utils/constants' async function prepareMetaMask(version: string = DEFAULT_METAMASK_VERSION): Promise { let downloadsDirectory @@ -46,28 +46,31 @@ async function unzipArchive(archivePath: string): Promise { try { await new Promise((resolve, reject) => { const stream = fs.createReadStream(archivePath).pipe(unzipper.Parse()) - stream.on('entry', async (entry: { path: string; type: string; pipe: (arg: unknown) => void, autodrain: () => void }) => { + stream.on( + 'entry', + async (entry: { path: string; type: string; pipe: (arg: unknown) => void; autodrain: () => void }) => { const fileName = entry.path const type = entry.type as 'Directory' | 'File' if (type === 'Directory') { - await fs.mkdir(path.join(outputPath, fileName), { recursive: true }); - entry.autodrain(); - return; + await fs.mkdir(path.join(outputPath, fileName), { recursive: true }) + entry.autodrain() + return } if (type === 'File') { - const writeStream = fs.createWriteStream(path.join(outputPath, fileName)); - entry.pipe(writeStream); - + const writeStream = fs.createWriteStream(path.join(outputPath, fileName)) + entry.pipe(writeStream) + await new Promise((res, rej) => { - writeStream.on('finish', res); - writeStream.on('error', rej); - }); + writeStream.on('finish', res) + writeStream.on('error', rej) + }) } - }) - stream.on('finish', resolve); - stream.on('error', reject); + } + ) + stream.on('finish', resolve) + stream.on('error', reject) }) } catch (error: unknown) { console.error(`[unzipArchive] Error unzipping archive: ${(error as { message: string }).message}`) diff --git a/wallets/metamask/src/fixture-actions/unlockForFixture.ts b/wallets/metamask/src/fixture-actions/unlockForFixture.ts index 36bfa5916..16cf6d252 100644 --- a/wallets/metamask/src/fixture-actions/unlockForFixture.ts +++ b/wallets/metamask/src/fixture-actions/unlockForFixture.ts @@ -40,7 +40,7 @@ async function unlockWalletButReloadIfSpinnerDoesNotVanish(metamask: MetaMask) { } } -async function retryIfMetaMaskCrashAfterUnlock(page: Page) { +export async function retryIfMetaMaskCrashAfterUnlock(page: Page) { const homePageLogoLocator = page.locator(HomePage.selectors.logo) const isHomePageLogoVisible = await homePageLogoLocator.isVisible() diff --git a/wallets/metamask/src/fixtures/metaMaskFixtures.ts b/wallets/metamask/src/fixtures/metaMaskFixtures.ts index 1dd081a7b..6b187771a 100644 --- a/wallets/metamask/src/fixtures/metaMaskFixtures.ts +++ b/wallets/metamask/src/fixtures/metaMaskFixtures.ts @@ -11,13 +11,13 @@ import { } from '@synthetixio/synpress-cache' import { type Anvil, type CreateAnvilOptions, createPool } from '@viem/anvil' import fs from 'fs-extra' -import { SEED_PHRASE } from '../utils/constants' import { importAndConnectForFixtures } from '../fixture-actions/importAndConnectForFixtures' import { cachelessSetupMetaMask } from '../fixture-actions/noCachMetaMaskSetup' import { persistLocalStorage } from '../fixture-actions/persistLocalStorage' +import { SEED_PHRASE } from '../utils/constants' // console.log(process.env.SYNPRESS_USE_CACHE, process.platform) -const USECACHE = (false || process.platform === 'win32'); +const USECACHE = false || process.platform === 'win32' type MetaMaskFixtures = { _contextPath: string @@ -100,7 +100,8 @@ export const metaMaskFixtures = (walletSetup: ReturnType { const classes = await toggleLocator.getAttribute('class') @@ -20,8 +18,8 @@ export async function toggle(toggleLocator: Locator) { throw new Error('[ToggleShowTestNetworks] Toggle class returned null inside waitFor') } - if (isOn) { - return classes.includes('toggle-button--off') + if (!isOn) { + await toggleLocator.click() } return classes.includes('toggle-button--on') diff --git a/wallets/metamask/test/e2e/connectToDapp.spec.ts b/wallets/metamask/test/e2e/connectToDapp.spec.ts index 1fa603ac8..0154c27d2 100644 --- a/wallets/metamask/test/e2e/connectToDapp.spec.ts +++ b/wallets/metamask/test/e2e/connectToDapp.spec.ts @@ -12,9 +12,12 @@ test('should connect wallet to dapp', async ({ context, page, extensionId }) => await page.goto('/') - await page.locator('#connectButton').click() + const disabled = await page.locator('#connectButton').isDisabled() - await metamask.connectToDapp() + if (!disabled) { + await page.locator('#connectButton').click() + await metamask.connectToDapp() + } await expect(page.locator('#accounts')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') }) @@ -26,6 +29,7 @@ test('should connect multiple wallets to dapp', async ({ context, page, metamask await metamask.addNewAccount('Account x3') await page.goto('/') + await page.locator('#connectButton').click() // "accounts" param is order agnostic diff --git a/wallets/metamask/test/wallet-setup/basic.setup.d.ts b/wallets/metamask/test/wallet-setup/basic.setup.d.ts index 97d7a02cd..1bc70ea7c 100644 --- a/wallets/metamask/test/wallet-setup/basic.setup.d.ts +++ b/wallets/metamask/test/wallet-setup/basic.setup.d.ts @@ -1,9 +1,9 @@ -export declare const SEED_PHRASE = "test test test test test test test test test test test junk"; -export declare const PASSWORD = "Tester@1234"; +export declare const SEED_PHRASE = 'test test test test test test test test test test test junk' +export declare const PASSWORD = 'Tester@1234' declare const _default: { - hash: string; - fn: import("@synthetixio/synpress-cache").WalletSetupFunction; - walletPassword: string; -}; -export default _default; -//# sourceMappingURL=basic.setup.d.ts.map \ No newline at end of file + hash: string + fn: import('@synthetixio/synpress-cache').WalletSetupFunction + walletPassword: string +} +export default _default +//# sourceMappingURL=basic.setup.d.ts.map