From aefbf3e247dbc51762e769152876ecdb5c0546de Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 29 May 2026 03:50:38 +0200 Subject: [PATCH] FIx E2E context manager --- playwright.config.ts | 2 +- tests/e2e/utils/contextManager.ts | 2 +- tests/e2e/web/fixtures/signInFixture.ts | 9 +++++++++ tests/e2e/web/pages/app.ts | 12 ++++++------ tests/e2e/web/specs/signIn.spec.ts | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index a568c83d..95359cfb 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -37,7 +37,7 @@ export default defineConfig({ // No retries by default (even in CI) because it slows the CI pipeline and masks real bugs // If there is a known intermittent browser timing issue for some tests, it's fine to give 1 retry to those flaky tests retries: process.env.CI ? 0 : 0, - workers: process.env.CI ? 1 : undefined, + workers: process.env.CI ? 1 : 4, reporter: [ ['list'], ['html', {outputFolder: `tests/reports/playwright-report`, open: 'on-failure'}], diff --git a/tests/e2e/utils/contextManager.ts b/tests/e2e/utils/contextManager.ts index dc056248..c1b2d378 100644 --- a/tests/e2e/utils/contextManager.ts +++ b/tests/e2e/utils/contextManager.ts @@ -16,7 +16,7 @@ export class ContextManager { const context = await this.browser.newContext() try { const page = await context.newPage() - const app = new App(page, false) + const app = new App(page) this.contexts.set(name, app) return app } catch (error) { diff --git a/tests/e2e/web/fixtures/signInFixture.ts b/tests/e2e/web/fixtures/signInFixture.ts index 729b17b4..1c5ffa05 100644 --- a/tests/e2e/web/fixtures/signInFixture.ts +++ b/tests/e2e/web/fixtures/signInFixture.ts @@ -7,6 +7,7 @@ import {deleteUser} from '../utils/deleteUser' export const test = base.extend<{ app: App + app2: App devOneAccount: UserAccountInformation devTwoAccount: UserAccountInformation specAccount: UserAccountInformation @@ -21,6 +22,14 @@ export const test = base.extend<{ await use(appPage) await appPage.contextManager?.closeAll() }, + app2: async ({browser}, use) => { + // Totally isolated app which can be used to sign in a different user + // Use {storageState: 'auth/receiver.json'} later on to save compute time by signing in only once + const context = await browser.newContext() + const page = await context.newPage() + await use(new App(page)) + await context.close() // guaranteed teardown, even on failure/timeout + }, signedInAccount: async ({app}: {app: App}, use) => { const account = testAccounts.faker_account() await seedUser( diff --git a/tests/e2e/web/pages/app.ts b/tests/e2e/web/pages/app.ts index 148afe0d..18f44333 100644 --- a/tests/e2e/web/pages/app.ts +++ b/tests/e2e/web/pages/app.ts @@ -33,7 +33,7 @@ export class App { constructor( public readonly page: Page, - createContextManager = true, + // createContextManager = true, ) { this.auth = new AuthPage(page) this.compatibility = new CompatibilityPage(page) @@ -49,11 +49,11 @@ export class App { this.messages = new MessagesPage(page) this.context = page.context() - if (createContextManager) { - const browser = page.context().browser() - if (!browser) throw new Error('Could not get Browser from page.context().browser()') - this.contextManager = new ContextManager(browser) - } + // if (createContextManager) { + // const browser = page.context().browser() + // if (!browser) throw new Error('Could not get Browser from page.context().browser()') + // this.contextManager = new ContextManager(browser) + // } } async deleteProfileFromSettings() { diff --git a/tests/e2e/web/specs/signIn.spec.ts b/tests/e2e/web/specs/signIn.spec.ts index 151451ff..4109e1a2 100644 --- a/tests/e2e/web/specs/signIn.spec.ts +++ b/tests/e2e/web/specs/signIn.spec.ts @@ -264,10 +264,10 @@ test.describe('when given valid input', () => { const message = 'This is a message' test('be able to send a message from the messages page', async ({ app, + app2: receiverApp, signedInAccount: sender, signedOutAccount: receiver, }) => { - const receiverApp = await app.contextManager!.createContext() await receiverApp.signinWithEmail(receiver) await app.home.clickMessagesLink() @@ -281,10 +281,10 @@ test.describe('when given valid input', () => { test('be able to send a message from the people page', async ({ app, + app2: receiverApp, signedInAccount: sender, signedOutAccount: receiver, }) => { - const receiverApp = await app.contextManager!.createContext() await receiverApp.signinWithEmail(receiver) // To pass the min character limit for message intro (250 chars)