-
-
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.
✨ feat(metamask): Add basic
connectToDapp
function (#922)
- Loading branch information
1 parent
5378e6d
commit 71dc46a
Showing
4 changed files
with
71 additions
and
6 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,20 @@ | ||
import type { BrowserContext } from '@playwright/test' | ||
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() | ||
|
||
// Click `Connect`. | ||
await notificationPage.getByRole('button').nth(1).click() | ||
} |
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,29 @@ | ||
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 }) | ||
} |
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