From 6ad9a8137da803979ba0e2904bfe8d8ab3b664cc Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Sat, 11 Nov 2023 01:18:03 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(metamask):=20Move?= =?UTF-8?q?=20and=20update=20`getNotificationPage`=20(#986)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationPage/actions/connectToDapp.ts | 10 +------ .../utils/getNotificationPage.ts | 29 ------------------- .../src/pages/NotificationPage/utils/index.ts | 1 - .../metamask/src/utils/getNotificationPage.ts | 22 ++++++++++++++ 4 files changed, 23 insertions(+), 39 deletions(-) delete mode 100644 wallets/metamask/src/pages/NotificationPage/utils/getNotificationPage.ts delete mode 100644 wallets/metamask/src/pages/NotificationPage/utils/index.ts create mode 100644 wallets/metamask/src/utils/getNotificationPage.ts 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 +}