From 0ed628b240e7d36258352a53bc8671fb339873e8 Mon Sep 17 00:00:00 2001 From: Vincent T Date: Wed, 7 Aug 2024 14:30:53 -0400 Subject: [PATCH] Fixed tests failing when ran together, now run in sequence. Signed-off-by: Vincent T --- app/app-e2e-tests/e2e/tests/demo-test.spec.ts | 42 ++++++------------- app/app-e2e-tests/e2e/tests/demo-test.ts | 2 - app/app-e2e-tests/playwright.config.ts | 16 ++++--- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/app/app-e2e-tests/e2e/tests/demo-test.spec.ts b/app/app-e2e-tests/e2e/tests/demo-test.spec.ts index 9f43e66ca53..6e034439537 100644 --- a/app/app-e2e-tests/e2e/tests/demo-test.spec.ts +++ b/app/app-e2e-tests/e2e/tests/demo-test.spec.ts @@ -1,9 +1,10 @@ -import { test } from '@playwright/test'; -import { _electron } from '@playwright/test'; +import {test } from '@playwright/test'; +import { _electron, ElectronApplication, Page } from 'playwright'; import { headlampAppPage } from './demo-test'; const electron = _electron; -let electronApp; +let electronApp: ElectronApplication; +let page: Page; test.beforeAll(async () => { // Launch Electron app. @@ -12,41 +13,22 @@ test.beforeAll(async () => { timeout: 0, args: ['main.js'], }); -}); -test('launch app / check homepage', async () => { - // Launch Electron app. + // Get the first window. + page = await electronApp.firstWindow(); +}); - // note: may use .context() instead of .firstWindow()? - // const context = await electronApp.context(); +test.afterAll(async () => { + // Close the Electron app. + await electronApp.close(); +}); - // note: firstWindow returns a page object so we can replace the window object - const page = await electronApp.firstWindow(); +test('launch app / check homepage', async () => { const headlampPage = new headlampAppPage(page); - await headlampPage.navHomepage(); - - electronApp.close(); - // electronApp.on('window', async () => { - // await headlampPage.homepage(); - // }); }); test('launch app / check notifications', async () => { - // Launch Electron app. - // const electronApp = await electron.launch({ - // cwd: '/home/vtaylor/headlamp/app/electron', - // timeout: 0, - // args: ['main.js'], - // }); - - const page = await electronApp.firstWindow(); const headlampPage = new headlampAppPage(page); - await headlampPage.navNotifactions(); - - electronApp.close(); - // electronApp.on('window', async () => { - // await headlampPage.notifications(); - // }); }); diff --git a/app/app-e2e-tests/e2e/tests/demo-test.ts b/app/app-e2e-tests/e2e/tests/demo-test.ts index a5f10bc43e5..40526d11007 100644 --- a/app/app-e2e-tests/e2e/tests/demo-test.ts +++ b/app/app-e2e-tests/e2e/tests/demo-test.ts @@ -4,7 +4,6 @@ export class headlampAppPage { constructor(private page: Page) {} async navHomepage() { - await this.page.waitForLoadState('domcontentloaded'); await this.page.goto('http://localhost:3000/'); await expect(this.page.getByRole('button', { name: 'Home' })).toBeVisible(); @@ -12,7 +11,6 @@ export class headlampAppPage { } async navNotifactions() { - await this.page.waitForLoadState('domcontentloaded'); await this.page.goto('http://localhost:3000/'); await expect(this.page.getByRole('button', { name: 'Notifications' })).toBeVisible(); diff --git a/app/app-e2e-tests/playwright.config.ts b/app/app-e2e-tests/playwright.config.ts index 08e12bee977..dbdee264326 100644 --- a/app/app-e2e-tests/playwright.config.ts +++ b/app/app-e2e-tests/playwright.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, devices } from '@playwright/test'; +import { defineConfig } from '@playwright/test'; /** * Read environment variables from file. @@ -17,13 +17,13 @@ export default defineConfig({ timeout: 60000, }, /* Run tests in files in parallel */ - fullyParallel: true, + fullyParallel: false, /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, /* Retry on CI only */ retries: process.env.CI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: 1, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'html', /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ @@ -40,9 +40,15 @@ export default defineConfig({ /* Configure projects for major browsers */ projects: [ { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + name: 'electron', + use: { + browserName: 'chromium', + }, }, + // { + // name: 'chromium', + // use: { ...devices['Desktop Chrome'] }, + // }, // { // name: 'firefox',