diff --git a/wallets/metamask/src/actions/index.ts b/wallets/metamask/src/actions/index.ts deleted file mode 100644 index 435a3f487..000000000 --- a/wallets/metamask/src/actions/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './connectToDapp' -export * from './lock' -export * from './unlock' -export * from './unlockForFixture' diff --git a/wallets/metamask/src/actions/lock.ts b/wallets/metamask/src/actions/lock.ts deleted file mode 100644 index 1e10e6801..000000000 --- a/wallets/metamask/src/actions/lock.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Page } from '@playwright/test' -import { HomePageSelectors } from '../selectors' - -export async function lock(page: Page) { - await page.locator(HomePageSelectors.accountMenu.accountMenuButton).click() - await page.locator(HomePageSelectors.accountMenu.lockButton).click() -} diff --git a/wallets/metamask/src/actions/unlock.ts b/wallets/metamask/src/actions/unlock.ts deleted file mode 100644 index 3458f8fe3..000000000 --- a/wallets/metamask/src/actions/unlock.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { Page } from '@playwright/test' -import { UnlockPageSelectors } from '../selectors' -import { waitForSpinnerToVanish } from '../utils/waitForSpinnerToVanish' - -export async function unlock(page: Page, password: string) { - await page.locator(UnlockPageSelectors.passwordInput).fill(password) - await page.locator(UnlockPageSelectors.submitButton).click() - - await waitForSpinnerToVanish(page) -} diff --git a/wallets/metamask/src/actions/unlockForFixture.ts b/wallets/metamask/src/fixture-actions/unlockForFixture.ts similarity index 69% rename from wallets/metamask/src/actions/unlockForFixture.ts rename to wallets/metamask/src/fixture-actions/unlockForFixture.ts index 2cbc16c51..f52514462 100644 --- a/wallets/metamask/src/actions/unlockForFixture.ts +++ b/wallets/metamask/src/fixture-actions/unlockForFixture.ts @@ -1,9 +1,13 @@ import type { Page } from '@playwright/test' import { errors as playwrightErrors } from '@playwright/test' -import { CrashPageSelectors, HomePageSelectors, LoadingSelectors, unlock } from '../' +import { MetaMask } from '../metamask' +import { CrashPage, HomePage } from '../pages' +import { LoadingSelectors } from '../selectors' export async function unlockForFixture(page: Page, password: string) { - await unlock(page, password) + const metamask = new MetaMask(page.context(), page, password) + + await metamask.unlock() await page.locator(LoadingSelectors.spinner).waitFor({ state: 'hidden', @@ -14,11 +18,11 @@ export async function unlockForFixture(page: Page, password: string) { } async function retryIfMetaMaskCrashAfterUnlock(page: Page) { - const isHomePageVisible = await page.locator(HomePageSelectors.logo).isVisible() + const isHomePageVisible = await page.locator(HomePage.selectors.logo).isVisible() if (!isHomePageVisible) { - if (await page.locator(CrashPageSelectors.header).isVisible()) { - const errors = await page.locator(CrashPageSelectors.errors).allTextContents() + 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')) @@ -26,7 +30,7 @@ async function retryIfMetaMaskCrashAfterUnlock(page: Page) { await page.reload() try { - await page.locator(HomePageSelectors.logo).waitFor({ + await page.locator(HomePage.selectors.logo).waitFor({ state: 'visible', timeout: 10_000 // TODO: Extract & Make this timeout configurable. }) diff --git a/wallets/metamask/src/index.ts b/wallets/metamask/src/index.ts index 14db46201..e43dca1e9 100644 --- a/wallets/metamask/src/index.ts +++ b/wallets/metamask/src/index.ts @@ -1,5 +1,2 @@ -export * from './prepareExtension' -export * from './pages' -export * from './actions' -export * from './selectors' -export * from './utils/getExtensionId' +export * from './metamask' +export * from './fixture-actions/unlockForFixture' diff --git a/wallets/metamask/src/metamask.ts b/wallets/metamask/src/metamask.ts new file mode 100644 index 000000000..ee0d193b1 --- /dev/null +++ b/wallets/metamask/src/metamask.ts @@ -0,0 +1,35 @@ +import type { BrowserContext, Page } from '@playwright/test' +import { CrashPage, HomePage, LockPage, NotificationPage, OnboardingPage } from './pages' + +export class MetaMask { + crashPage: CrashPage + onboardingPage: OnboardingPage + lockPage: LockPage + homePage: HomePage + notificationPage: NotificationPage + + constructor(readonly context: BrowserContext, readonly page: Page, readonly password: string) { + this.crashPage = new CrashPage() + + this.onboardingPage = new OnboardingPage(page) + this.lockPage = new LockPage(page) + this.homePage = new HomePage(page) + this.notificationPage = new NotificationPage(page) + } + + async importWallet(seedPhrase: string) { + await this.onboardingPage.importWallet(seedPhrase, this.password) + } + + async connectToDapp(extensionId: string) { + await this.notificationPage.connectToDapp(extensionId) + } + + async lock() { + await this.homePage.lock() + } + + async unlock() { + await this.lockPage.unlock(this.password) + } +} diff --git a/wallets/metamask/src/pages/CrashPage/page.ts b/wallets/metamask/src/pages/CrashPage/page.ts new file mode 100644 index 000000000..8c9f2c31c --- /dev/null +++ b/wallets/metamask/src/pages/CrashPage/page.ts @@ -0,0 +1,6 @@ +import Selectors from './selectors' + +export class CrashPage { + static readonly selectors = Selectors + readonly selectors = Selectors +} diff --git a/wallets/metamask/src/selectors/crash/index.ts b/wallets/metamask/src/pages/CrashPage/selectors/index.ts similarity index 79% rename from wallets/metamask/src/selectors/crash/index.ts rename to wallets/metamask/src/pages/CrashPage/selectors/index.ts index 594d1e139..0c94db8ba 100644 --- a/wallets/metamask/src/selectors/crash/index.ts +++ b/wallets/metamask/src/pages/CrashPage/selectors/index.ts @@ -1,6 +1,6 @@ const container = 'section.error-page' -export const CrashPageSelectors = { +export default { header: `${container} > .error-page__header`, errors: `${container} > .error-page__details li` } diff --git a/wallets/metamask/src/pages/HomePage/actions/index.ts b/wallets/metamask/src/pages/HomePage/actions/index.ts new file mode 100644 index 000000000..14ee81f76 --- /dev/null +++ b/wallets/metamask/src/pages/HomePage/actions/index.ts @@ -0,0 +1 @@ +export * from './lock' diff --git a/wallets/metamask/src/pages/HomePage/actions/lock.ts b/wallets/metamask/src/pages/HomePage/actions/lock.ts new file mode 100644 index 000000000..f6e109820 --- /dev/null +++ b/wallets/metamask/src/pages/HomePage/actions/lock.ts @@ -0,0 +1,7 @@ +import type { Page } from '@playwright/test' +import Selectors from '../selectors' + +export async function lock(page: Page) { + await page.locator(Selectors.accountMenu.accountMenuButton).click() + await page.locator(Selectors.accountMenu.lockButton).click() +} diff --git a/wallets/metamask/src/pages/HomePage/page.ts b/wallets/metamask/src/pages/HomePage/page.ts new file mode 100644 index 000000000..d8b280ee1 --- /dev/null +++ b/wallets/metamask/src/pages/HomePage/page.ts @@ -0,0 +1,18 @@ +import type { Page } from '@playwright/test' +import { lock } from './actions' +import Selectors from './selectors' + +export class HomePage { + static readonly selectors = Selectors + readonly selectors = Selectors + + readonly page: Page + + constructor(page: Page) { + this.page = page + } + + async lock() { + await lock(this.page) + } +} diff --git a/wallets/metamask/src/selectors/main/homePage.ts b/wallets/metamask/src/pages/HomePage/selectors/index.ts similarity index 74% rename from wallets/metamask/src/selectors/main/homePage.ts rename to wallets/metamask/src/pages/HomePage/selectors/index.ts index 20360d76c..30111cfc7 100644 --- a/wallets/metamask/src/selectors/main/homePage.ts +++ b/wallets/metamask/src/pages/HomePage/selectors/index.ts @@ -1,4 +1,4 @@ -import { createDataTestSelector } from '../../utils/selectors/createDataTestSelector' +import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' const container = '.account-menu' const accountMenu = { diff --git a/wallets/metamask/src/pages/LockPage/actions/index.ts b/wallets/metamask/src/pages/LockPage/actions/index.ts new file mode 100644 index 000000000..b0dce8ac2 --- /dev/null +++ b/wallets/metamask/src/pages/LockPage/actions/index.ts @@ -0,0 +1 @@ +export * from './unlock' diff --git a/wallets/metamask/src/pages/LockPage/actions/unlock.ts b/wallets/metamask/src/pages/LockPage/actions/unlock.ts new file mode 100644 index 000000000..3fabef333 --- /dev/null +++ b/wallets/metamask/src/pages/LockPage/actions/unlock.ts @@ -0,0 +1,10 @@ +import type { Page } from '@playwright/test' +import { waitForSpinnerToVanish } from '../../../utils/waitForSpinnerToVanish' +import Selectors from '../selectors' + +export async function unlock(page: Page, password: string) { + await page.locator(Selectors.passwordInput).fill(password) + await page.locator(Selectors.submitButton).click() + + await waitForSpinnerToVanish(page) +} diff --git a/wallets/metamask/src/pages/LockPage/page.ts b/wallets/metamask/src/pages/LockPage/page.ts new file mode 100644 index 000000000..ce95f7c0f --- /dev/null +++ b/wallets/metamask/src/pages/LockPage/page.ts @@ -0,0 +1,18 @@ +import type { Page } from '@playwright/test' +import { unlock } from './actions' +import Selectors from './selectors' + +export class LockPage { + static readonly selectors = Selectors + readonly selectors = Selectors + + readonly page: Page + + constructor(page: Page) { + this.page = page + } + + async unlock(password: string) { + await unlock(this.page, password) + } +} diff --git a/wallets/metamask/src/pages/LockPage/selectors/index.ts b/wallets/metamask/src/pages/LockPage/selectors/index.ts new file mode 100644 index 000000000..233814296 --- /dev/null +++ b/wallets/metamask/src/pages/LockPage/selectors/index.ts @@ -0,0 +1,6 @@ +import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' + +export default { + passwordInput: createDataTestSelector('unlock-password'), + submitButton: createDataTestSelector('unlock-submit') +} diff --git a/wallets/metamask/src/actions/connectToDapp.ts b/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts similarity index 89% rename from wallets/metamask/src/actions/connectToDapp.ts rename to wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts index cb1d239bc..c00dbe0cf 100644 --- a/wallets/metamask/src/actions/connectToDapp.ts +++ b/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts @@ -1,5 +1,5 @@ import type { BrowserContext } from '@playwright/test' -import { getNotificationPage } from '../utils/getNotificationPage' +import { getNotificationPage } from '../utils' export async function connectToDapp(context: BrowserContext, extensionId: string) { const notificationPage = await getNotificationPage(context, extensionId) diff --git a/wallets/metamask/src/pages/NotificationPage/actions/index.ts b/wallets/metamask/src/pages/NotificationPage/actions/index.ts new file mode 100644 index 000000000..0b0b193ac --- /dev/null +++ b/wallets/metamask/src/pages/NotificationPage/actions/index.ts @@ -0,0 +1 @@ +export * from './connectToDapp' diff --git a/wallets/metamask/src/pages/NotificationPage/page.ts b/wallets/metamask/src/pages/NotificationPage/page.ts new file mode 100644 index 000000000..33be594b5 --- /dev/null +++ b/wallets/metamask/src/pages/NotificationPage/page.ts @@ -0,0 +1,14 @@ +import type { Page } from '@playwright/test' +import { connectToDapp } from './actions' + +export class NotificationPage { + readonly page: Page + + constructor(page: Page) { + this.page = page + } + + async connectToDapp(extensionId: string) { + await connectToDapp(this.page.context(), extensionId) + } +} diff --git a/wallets/metamask/src/utils/getNotificationPage.ts b/wallets/metamask/src/pages/NotificationPage/utils/getNotificationPage.ts similarity index 100% rename from wallets/metamask/src/utils/getNotificationPage.ts rename to wallets/metamask/src/pages/NotificationPage/utils/getNotificationPage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/utils/index.ts b/wallets/metamask/src/pages/NotificationPage/utils/index.ts new file mode 100644 index 000000000..8cb7625be --- /dev/null +++ b/wallets/metamask/src/pages/NotificationPage/utils/index.ts @@ -0,0 +1 @@ +export * from './getNotificationPage' diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts b/wallets/metamask/src/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts index 2a4936a6f..6103bfff9 100644 --- a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts +++ b/wallets/metamask/src/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts @@ -1,7 +1,7 @@ import type { Page } from '@playwright/test' -import { SecretRecoveryPhrasePageSelectors } from '../../selectors' +import Selectors from '../../selectors' -const StepSelectors = SecretRecoveryPhrasePageSelectors.recoveryStep +const StepSelectors = Selectors.SecretRecoveryPhrasePageSelectors.recoveryStep export async function confirmSecretRecoveryPhrase(page: Page, seedPhrase: string) { const seedPhraseWords = seedPhrase.split(' ') diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/createPassword.ts b/wallets/metamask/src/pages/OnboardingPage/actions/helpers/createPassword.ts index 028a1974e..7990a7975 100644 --- a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/createPassword.ts +++ b/wallets/metamask/src/pages/OnboardingPage/actions/helpers/createPassword.ts @@ -1,7 +1,7 @@ import type { Page } from '@playwright/test' -import { SecretRecoveryPhrasePageSelectors } from '../../selectors' +import Selectors from '../../selectors' -const StepSelectors = SecretRecoveryPhrasePageSelectors.passwordStep +const StepSelectors = Selectors.SecretRecoveryPhrasePageSelectors.passwordStep export async function createPassword(page: Page, password: string) { await page.locator(StepSelectors.passwordInput).fill(password) diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/importWallet.ts b/wallets/metamask/src/pages/OnboardingPage/actions/importWallet.ts index f84a5ea62..ada53835d 100644 --- a/wallets/metamask/src/pages/OnboardingPage/actions/importWallet.ts +++ b/wallets/metamask/src/pages/OnboardingPage/actions/importWallet.ts @@ -1,23 +1,18 @@ import type { Page } from '@playwright/test' -import { - AnalyticsPageSelectors, - GetStartedPageSelectors, - PinExtensionPageSelectors, - WalletCreationSuccessPageSelectors -} from '../selectors' +import Selectors from '../selectors' import { confirmSecretRecoveryPhrase, createPassword } from './helpers' export async function importWallet(page: Page, seedPhrase: string, password: string) { - await page.locator(GetStartedPageSelectors.importWallet).click() + await page.locator(Selectors.GetStartedPageSelectors.importWallet).click() - await page.locator(AnalyticsPageSelectors.optOut).click() + await page.locator(Selectors.AnalyticsPageSelectors.optOut).click() // Secret Recovery Phrase Page await confirmSecretRecoveryPhrase(page, seedPhrase) await createPassword(page, password) - await page.locator(WalletCreationSuccessPageSelectors.confirmButton).click() + await page.locator(Selectors.WalletCreationSuccessPageSelectors.confirmButton).click() - await page.locator(PinExtensionPageSelectors.nextButton).click() - await page.locator(PinExtensionPageSelectors.confirmButton).click() + await page.locator(Selectors.PinExtensionPageSelectors.nextButton).click() + await page.locator(Selectors.PinExtensionPageSelectors.confirmButton).click() } diff --git a/wallets/metamask/src/pages/OnboardingPage/page.ts b/wallets/metamask/src/pages/OnboardingPage/page.ts index dfafe9177..67ce03f0e 100644 --- a/wallets/metamask/src/pages/OnboardingPage/page.ts +++ b/wallets/metamask/src/pages/OnboardingPage/page.ts @@ -1,11 +1,13 @@ import type { Page } from '@playwright/test' import { importWallet } from './actions' -import * as Selectors from './selectors' +import Selectors from './selectors' export class OnboardingPage { - readonly page: Page + static readonly selectors = Selectors readonly selectors = Selectors + readonly page: Page + constructor(page: Page) { this.page = page } diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/index.ts b/wallets/metamask/src/pages/OnboardingPage/selectors/index.ts index 85e9fd7a3..3fcc0ceb4 100644 --- a/wallets/metamask/src/pages/OnboardingPage/selectors/index.ts +++ b/wallets/metamask/src/pages/OnboardingPage/selectors/index.ts @@ -5,7 +5,7 @@ import SecretRecoveryPhrasePageSelectors from './secretRecoveryPhrasePage' import WalletCreationSuccessPageSelectors from './walletCreationSuccessPage' // biome-ignore format: empty lines should be preserved -export { +export default { // Initial Welcome Page GetStartedPageSelectors, diff --git a/wallets/metamask/src/pages/index.ts b/wallets/metamask/src/pages/index.ts index 2db1a41d6..9388f7d49 100644 --- a/wallets/metamask/src/pages/index.ts +++ b/wallets/metamask/src/pages/index.ts @@ -1 +1,5 @@ export * from './OnboardingPage/page' +export * from './CrashPage/page' +export * from './LockPage/page' +export * from './HomePage/page' +export * from './NotificationPage/page' diff --git a/wallets/metamask/src/selectors/index.ts b/wallets/metamask/src/selectors/index.ts index b5113d2b8..0ac86beb1 100644 --- a/wallets/metamask/src/selectors/index.ts +++ b/wallets/metamask/src/selectors/index.ts @@ -1,4 +1 @@ -export * from './unlocking' export * from './loading' -export * from './crash' -export * from './main' diff --git a/wallets/metamask/src/selectors/main/index.ts b/wallets/metamask/src/selectors/main/index.ts deleted file mode 100644 index 75d7fa25a..000000000 --- a/wallets/metamask/src/selectors/main/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import HomePageSelectors from './homePage' - -export { HomePageSelectors } diff --git a/wallets/metamask/src/selectors/unlocking/index.ts b/wallets/metamask/src/selectors/unlocking/index.ts deleted file mode 100644 index 02708a857..000000000 --- a/wallets/metamask/src/selectors/unlocking/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { createDataTestSelector } from '../../utils/selectors/createDataTestSelector' - -export const UnlockPageSelectors = { - passwordInput: createDataTestSelector('unlock-password'), - submitButton: createDataTestSelector('unlock-submit') -} diff --git a/wallets/metamask/src/utils/getExtensionId.ts b/wallets/metamask/src/utils/getExtensionId.ts deleted file mode 100644 index 951dd8686..000000000 --- a/wallets/metamask/src/utils/getExtensionId.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { BrowserContext } from '@playwright/test' -import { z } from 'zod' - -const Extension = z.object({ - id: z.string(), - name: z.string() -}) - -const Extensions = z.array(Extension) - -export async function getExtensionId(context: BrowserContext, extensionName: string) { - const page = await context.newPage() - await page.goto('chrome://extensions') - - const unparsedExtensions = await page.evaluate('chrome.management.getAll()') - - const allExtensions = Extensions.parse(unparsedExtensions) - const targetExtension = allExtensions.find( - (extension) => extension.name.toLowerCase() === extensionName.toLowerCase() - ) - - if (!targetExtension) { - throw new Error( - [ - `[GetExtensionId] Extension with name ${extensionName} not found.`, - `Available extensions: ${allExtensions.map((extension) => extension.name).join(', ')}` - ].join('\n') - ) - } - - await page.close() - - return targetExtension.id -} diff --git a/wallets/metamask/test/e2e/getExtensionId.spec.ts b/wallets/metamask/test/e2e/getExtensionId.spec.ts deleted file mode 100644 index 0277aad47..000000000 --- a/wallets/metamask/test/e2e/getExtensionId.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { testWithSynpress } from 'fixtures' -import { getExtensionId, unlockForFixture } from '../../src' - -import basicSetup from './wallet-setup/basic.setup' - -const test = testWithSynpress(basicSetup, unlockForFixture) - -const { describe, expect } = test - -describe('getExtensionId', () => { - test('should return the extension id', async ({ context }) => { - const extensionId = await getExtensionId(context, 'MetaMask') - expect(extensionId).toMatch(/^[a-z]{32}$/) - }) -}) diff --git a/wallets/metamask/test/e2e/lock.spec.ts b/wallets/metamask/test/e2e/lock.spec.ts deleted file mode 100644 index 8304caacb..000000000 --- a/wallets/metamask/test/e2e/lock.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { testWithSynpress } from 'fixtures' -import { UnlockPageSelectors, lock, unlockForFixture } from '../../src' - -import basicSetup from './wallet-setup/basic.setup' - -const test = testWithSynpress(basicSetup, unlockForFixture) - -const { describe, expect } = test - -describe('lock', () => { - test('should lock the wallet', async ({ metamaskPage }) => { - await lock(metamaskPage) - - await expect(metamaskPage.locator(UnlockPageSelectors.submitButton)).toBeVisible() - }) -}) diff --git a/wallets/metamask/test/e2e/connectToDapp.spec.ts b/wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts similarity index 50% rename from wallets/metamask/test/e2e/connectToDapp.spec.ts rename to wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts index 1f62492cf..c306cfb6d 100644 --- a/wallets/metamask/test/e2e/connectToDapp.spec.ts +++ b/wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts @@ -1,21 +1,21 @@ import { testWithSynpress } from 'fixtures' -import { connectToDapp, getExtensionId, unlockForFixture } from '../../src' +import { MetaMask, unlockForFixture } from '../../../src' -import basicSetup from './wallet-setup/basic.setup' +import basicSetup from '../wallet-setup/basic.setup' const test = testWithSynpress(basicSetup, unlockForFixture) const { describe, expect } = test -describe('connectToDapp', () => { - test('should connect wallet to dapp', async ({ context, page }) => { - const extensionId = await getExtensionId(context, 'MetaMask') +describe('MetaMask.connectToDapp', () => { + test('should connect wallet to dapp', async ({ context, page, extensionId }) => { + const metamask = new MetaMask(context, page, basicSetup.walletPassword) await page.goto('https://metamask.github.io/test-dapp/') await page.locator('#connectButton').click() - await connectToDapp(context, extensionId) + await metamask.connectToDapp(extensionId) await expect(page.locator('#accounts')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') }) diff --git a/wallets/metamask/test/e2e/importWallet.spec.ts b/wallets/metamask/test/e2e/metamask/importWallet.spec.ts similarity index 82% rename from wallets/metamask/test/e2e/importWallet.spec.ts rename to wallets/metamask/test/e2e/metamask/importWallet.spec.ts index f2b141f85..888a5d77d 100644 --- a/wallets/metamask/test/e2e/importWallet.spec.ts +++ b/wallets/metamask/test/e2e/metamask/importWallet.spec.ts @@ -1,5 +1,6 @@ import { type BrowserContext, type Page, chromium, test as base } from '@playwright/test' -import { OnboardingPage, prepareExtension } from '../../src' +import { MetaMask } from '../../../src' +import { prepareExtension } from '../../../src/prepareExtension' const SEED_PHRASE = 'test test test test test test test test test test test junk' const PASSWORD = 'Tester@1234' @@ -50,11 +51,14 @@ const test = base.extend<{ const { describe, expect } = test -describe('importWallet', () => { - test('should go through the onboarding flow and import wallet from seed phrase', async ({ metamaskPage }) => { - const onboardingPage = new OnboardingPage(metamaskPage) +describe('MetaMask.importWallet', () => { + test('should go through the onboarding flow and import wallet from seed phrase', async ({ + context, + metamaskPage + }) => { + const metamask = new MetaMask(context, metamaskPage, PASSWORD) - await onboardingPage.importWallet(SEED_PHRASE, PASSWORD) + await metamask.importWallet(SEED_PHRASE) await expect(metamaskPage.getByText('Account 1')).toBeVisible() await expect(metamaskPage.getByText('0xf39...2266')).toBeVisible() diff --git a/wallets/metamask/test/e2e/metamask/lock.spec.ts b/wallets/metamask/test/e2e/metamask/lock.spec.ts new file mode 100644 index 000000000..786189f84 --- /dev/null +++ b/wallets/metamask/test/e2e/metamask/lock.spec.ts @@ -0,0 +1,18 @@ +import { testWithSynpress } from 'fixtures' +import { MetaMask, unlockForFixture } from '../../../src' + +import basicSetup from '../wallet-setup/basic.setup' + +const test = testWithSynpress(basicSetup, unlockForFixture) + +const { describe, expect } = test + +describe('MetaMask.lock', () => { + test('should lock the wallet', async ({ context, metamaskPage }) => { + const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) + + await metamask.lock() + + await expect(metamaskPage.locator(metamask.lockPage.selectors.submitButton)).toBeVisible() + }) +}) diff --git a/wallets/metamask/test/e2e/metamask/unlock.spec.ts b/wallets/metamask/test/e2e/metamask/unlock.spec.ts new file mode 100644 index 000000000..e2c14912b --- /dev/null +++ b/wallets/metamask/test/e2e/metamask/unlock.spec.ts @@ -0,0 +1,20 @@ +import { testWithSynpress } from 'fixtures' +import { MetaMask, unlockForFixture } from '../../../src' + +import basicSetup from '../wallet-setup/basic.setup' + +const test = testWithSynpress(basicSetup, unlockForFixture) + +const { describe, expect } = test + +describe('MetaMask.unlock', () => { + test('should unlock the wallet', async ({ context, metamaskPage }) => { + const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) + + await metamask.lock() + + await metamask.unlock() + + await expect(metamaskPage.locator(metamask.homePage.selectors.logo)).toBeVisible() + }) +}) diff --git a/wallets/metamask/test/e2e/unlock.spec.ts b/wallets/metamask/test/e2e/unlock.spec.ts deleted file mode 100644 index 6bae01f54..000000000 --- a/wallets/metamask/test/e2e/unlock.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { testWithSynpress } from 'fixtures' -import { HomePageSelectors, lock, unlock, unlockForFixture } from '../../src' - -import basicSetup from './wallet-setup/basic.setup' - -const test = testWithSynpress(basicSetup, unlockForFixture) - -const { describe, expect } = test - -describe('unlock', () => { - test('should unlock the wallet', async ({ metamaskPage }) => { - await lock(metamaskPage) - - await unlock(metamaskPage, basicSetup.walletPassword) - - await expect(metamaskPage.locator(HomePageSelectors.logo)).toBeVisible() - }) -}) diff --git a/wallets/metamask/test/e2e/wallet-setup/basic.setup.ts b/wallets/metamask/test/e2e/wallet-setup/basic.setup.ts index 3a1bd34f7..ae0df552a 100644 --- a/wallets/metamask/test/e2e/wallet-setup/basic.setup.ts +++ b/wallets/metamask/test/e2e/wallet-setup/basic.setup.ts @@ -1,10 +1,12 @@ import { defineWalletSetup } from 'core' -import { importWallet } from './utils/importWallet' +import { MetaMask } from '../../../src' const SEED_PHRASE = 'test test test test test test test test test test test junk' const PASSWORD = 'Tester@1234' -export default defineWalletSetup(PASSWORD, async (_, walletPage) => { - await importWallet(walletPage, SEED_PHRASE, PASSWORD) +export default defineWalletSetup(PASSWORD, async (context, walletPage) => { + const metamask = new MetaMask(context, walletPage, PASSWORD) + + await metamask.importWallet(SEED_PHRASE) }) diff --git a/wallets/metamask/test/e2e/wallet-setup/utils/importWallet.ts b/wallets/metamask/test/e2e/wallet-setup/utils/importWallet.ts deleted file mode 100644 index 46273ab84..000000000 --- a/wallets/metamask/test/e2e/wallet-setup/utils/importWallet.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Page } from '@playwright/test' -import { OnboardingPage } from '../../../../src' - -export async function importWallet(walletPage: Page, seedPhrase: string, password: string) { - const onboardingPage = new OnboardingPage(walletPage) - - await onboardingPage.importWallet(seedPhrase, password) -}