diff --git a/tests/e2e/fixtures/base.ts b/tests/e2e/fixtures/base.ts index d544404f..f7ff7974 100644 --- a/tests/e2e/fixtures/base.ts +++ b/tests/e2e/fixtures/base.ts @@ -1,7 +1,6 @@ import { test as base, type BrowserContext, type Page } from '@playwright/test'; import { getBackground, - getExtensionId, loadContext, BrowserIntl, type Background, @@ -51,13 +50,8 @@ export const test = base.extend<{ page: Page }, BaseScopeWorker>({ ], popup: [ - async ({ background, persistentContext, browserName, channel }, use) => { - const extensionId = getExtensionId(browserName, background); - const popup = await openPopup( - persistentContext, - { browserName, channel }, - extensionId, - ); + async ({ background, persistentContext }, use) => { + const popup = await openPopup(persistentContext, background); await use(popup); await popup.close(); diff --git a/tests/e2e/fixtures/helpers.ts b/tests/e2e/fixtures/helpers.ts index 327dd51b..528b529a 100644 --- a/tests/e2e/fixtures/helpers.ts +++ b/tests/e2e/fixtures/helpers.ts @@ -5,6 +5,8 @@ import net from 'node:net'; import path from 'node:path'; import { readFileSync } from 'node:fs'; import { readFile } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { format } from 'date-fns'; import { chromium, firefox, @@ -142,10 +144,16 @@ export async function loadContext( { browserName, channel }: BrowserInfo, workerInfo: WorkerInfo, ) { + const userDataDir = path.join( + tmpdir(), + 'wm-extension-playwright', + `${browserName}-${channel}`, + format(new Date(), 'yyyyMMdd-HHmmss'), + ); const pathToExtension = getPathToExtension(browserName); let context: BrowserContext | undefined; if (browserName === 'chromium') { - context = await chromium.launchPersistentContext('', { + context = await chromium.launchPersistentContext(userDataDir, { headless: true, channel, args: [ diff --git a/tests/e2e/pages/popup.ts b/tests/e2e/pages/popup.ts index 8479a00f..aceae56d 100644 --- a/tests/e2e/pages/popup.ts +++ b/tests/e2e/pages/popup.ts @@ -1,5 +1,5 @@ import type { BrowserContext } from '@playwright/test'; -import type { BrowserIntl, BrowserInfo } from '../fixtures/helpers'; +import type { BrowserIntl, Background } from '../fixtures/helpers'; export type Popup = Awaited>; @@ -7,10 +7,9 @@ export { connectWallet } from '../helpers/testWallet'; export async function openPopup( context: BrowserContext, - { browserName, channel }: BrowserInfo, - extensionId: string, + background: Background, ) { - const url = getPopupUrl({ browserName, channel }, extensionId); + const url = await background.evaluate(() => chrome.action.getPopup({})); const page = await context.newPage(); const popupPromise = page.waitForEvent('popup'); await page.evaluate(() => { @@ -28,25 +27,6 @@ export async function openPopup( return popup; } -function getPopupUrl( - { browserName, channel }: BrowserInfo, - extensionId: string, -) { - let url: string; - if (browserName === 'chromium') { - if (channel === 'edge') { - url = `extension://${extensionId}/popup/index.html`; - } else { - url = `chrome-extension://${extensionId}/popup/index.html`; - } - } else if (browserName === 'firefox') { - url = `moz-extension://${extensionId}/popup/index.html`; - } else { - throw new Error('Unsupported browser: ' + browserName); - } - return url; -} - export async function disconnectWallet(popup: Popup) { await popup.locator(`[href="/settings"]`).click(); await popup.locator('button').getByText('Disconnect').click();