diff --git a/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts b/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts index c00dbe0cf..74cb0618f 100644 --- a/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts +++ b/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts @@ -1,17 +1,9 @@ import type { BrowserContext } from '@playwright/test' -import { getNotificationPage } from '../utils' +import { getNotificationPage } from '../../../utils/getNotificationPage' export async function connectToDapp(context: BrowserContext, extensionId: string) { const notificationPage = await getNotificationPage(context, extensionId) - if (!process.env.HEADLESS) { - // Set pop-up window viewport size to resemble the actual MetaMask pop-up window. - await notificationPage.setViewportSize({ - width: 360, - height: 592 - }) - } - // Click `Next`. await notificationPage.getByRole('button').nth(1).click() diff --git a/wallets/metamask/src/pages/NotificationPage/utils/getNotificationPage.ts b/wallets/metamask/src/pages/NotificationPage/utils/getNotificationPage.ts deleted file mode 100644 index cb11452a6..000000000 --- a/wallets/metamask/src/pages/NotificationPage/utils/getNotificationPage.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { BrowserContext, Page } from '@playwright/test' - -export async function getNotificationPage(context: BrowserContext, extensionId: string) { - const notificationPageUrl = `chrome-extension://${extensionId}/notification.html` - - /** - * If running in headless mode, create a new notification page manually. - * - * This is a workaround due to a bug in Chromium/MetaMask where pop-up windows - * are not created in the new headless mode. - */ - if (process.env.HEADLESS) { - const notificationPage = await context.newPage() - await notificationPage.goto(notificationPageUrl) - - return notificationPage - } - - const isNotificationPage = (page: Page) => page.url().includes(notificationPageUrl) - - // Check if notification page is already open. - const notificationPage = context.pages().find(isNotificationPage) - - if (notificationPage) { - return notificationPage - } - - return await context.waitForEvent('page', { predicate: isNotificationPage }) -} diff --git a/wallets/metamask/src/pages/NotificationPage/utils/index.ts b/wallets/metamask/src/pages/NotificationPage/utils/index.ts deleted file mode 100644 index 8cb7625be..000000000 --- a/wallets/metamask/src/pages/NotificationPage/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './getNotificationPage' diff --git a/wallets/metamask/src/utils/getNotificationPage.ts b/wallets/metamask/src/utils/getNotificationPage.ts new file mode 100644 index 000000000..16fcc7a5e --- /dev/null +++ b/wallets/metamask/src/utils/getNotificationPage.ts @@ -0,0 +1,22 @@ +import type { BrowserContext, Page } from '@playwright/test' + +export async function getNotificationPage(context: BrowserContext, extensionId: string) { + const notificationPageUrl = `chrome-extension://${extensionId}/notification.html` + + const isNotificationPage = (page: Page) => page.url().includes(notificationPageUrl) + + // Check if notification page is already open. + let notificationPage = context.pages().find(isNotificationPage) + + if (!notificationPage) { + notificationPage = await context.waitForEvent('page', { predicate: isNotificationPage }) + } + + // Set pop-up window viewport size to resemble the actual MetaMask pop-up window. + await notificationPage.setViewportSize({ + width: 360, + height: 592 + }) + + return notificationPage +}