From ac7423f8c62e1c5dce1e4369d6896b800fe5bf48 Mon Sep 17 00:00:00 2001 From: Volodymyr Makukha Date: Tue, 2 Dec 2025 13:01:58 +0000 Subject: [PATCH 1/2] Clean up e2e tests --- e2e/blueprints.test.ts | 8 +------- e2e/import-export.test.ts | 8 +------- e2e/import.test.ts | 8 +------- e2e/localization.test.ts | 17 ++--------------- e2e/overview-customize-links.test.ts | 6 +----- e2e/page-objects/add-site-modal.ts | 5 +++++ e2e/page-objects/main-sidebar.ts | 16 +++++++--------- e2e/page-objects/onboarding.ts | 14 +++++++++++--- e2e/page-objects/whats-new-modal.ts | 4 ---- e2e/sites.test.ts | 10 +--------- metrics/tests/site-editor.test.ts | 7 +------ metrics/tests/site-startup.test.ts | 7 +------ 12 files changed, 32 insertions(+), 78 deletions(-) diff --git a/e2e/blueprints.test.ts b/e2e/blueprints.test.ts index f1a9ba47dc..221910e44a 100644 --- a/e2e/blueprints.test.ts +++ b/e2e/blueprints.test.ts @@ -5,7 +5,6 @@ import { E2ESession } from './e2e-helpers'; import MainSidebar from './page-objects/main-sidebar'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; import { getUrlWithAutoLogin } from './utils'; test.describe( 'Blueprints', () => { @@ -14,14 +13,9 @@ test.describe( 'Blueprints', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, DEFAULT_SITE_NAME ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/import-export.test.ts b/e2e/import-export.test.ts index ec0466d894..94e4316cef 100644 --- a/e2e/import-export.test.ts +++ b/e2e/import-export.test.ts @@ -3,7 +3,6 @@ import { test, expect } from '@playwright/test'; import { E2ESession } from './e2e-helpers'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; import type { MessageBoxOptions } from 'electron'; const global = globalThis as unknown as { @@ -17,14 +16,9 @@ test.describe( 'Import / Export', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, defaultSiteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/import.test.ts b/e2e/import.test.ts index e561d1dc6b..3de69bbd9f 100644 --- a/e2e/import.test.ts +++ b/e2e/import.test.ts @@ -5,7 +5,6 @@ import { E2ESession } from './e2e-helpers'; import MainSidebar from './page-objects/main-sidebar'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; /** * Import Tests @@ -29,14 +28,9 @@ test.describe( 'Import', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, defaultSiteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/localization.test.ts b/e2e/localization.test.ts index 289b7ebe11..2901a6889d 100644 --- a/e2e/localization.test.ts +++ b/e2e/localization.test.ts @@ -43,14 +43,9 @@ test.describe( 'Localization', () => { test.beforeAll( async () => { await session.launch(); - // Complete onboarding before tests const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding(); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, 'My WordPress Website' ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); @@ -101,15 +96,7 @@ test.describe( 'Localization', () => { // Onboarding not visible, continue with test } - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - try { - const visible = await whatsNewModal.locator.isVisible( { timeout: 2000 } ); - if ( visible ) { - await whatsNewModal.closeButton.click(); - } - } catch ( error ) { - // What's New modal not visible, continue with test - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, 'My WordPress Website' ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/overview-customize-links.test.ts b/e2e/overview-customize-links.test.ts index c157b21e25..8c2b338bff 100644 --- a/e2e/overview-customize-links.test.ts +++ b/e2e/overview-customize-links.test.ts @@ -76,11 +76,7 @@ test.describe( 'Overview customize links', () => { const onboarding = new Onboarding( session.mainWindow ); await onboarding.completeOnboarding( { customSiteName: siteName } ); - - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.close(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, siteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); diff --git a/e2e/page-objects/add-site-modal.ts b/e2e/page-objects/add-site-modal.ts index 3a597fead7..162bca6502 100644 --- a/e2e/page-objects/add-site-modal.ts +++ b/e2e/page-objects/add-site-modal.ts @@ -5,6 +5,11 @@ import SiteForm from './site-form'; export default class AddSiteModal { constructor( private page: Page ) {} + async open() { + await this.page.getByTestId( 'add-site-button' ).click(); + await expect( this.locator ).toBeVisible(); + } + get locator() { return this.page.getByRole( 'dialog' ); } diff --git a/e2e/page-objects/main-sidebar.ts b/e2e/page-objects/main-sidebar.ts index a9a83e73e2..51d37a275e 100644 --- a/e2e/page-objects/main-sidebar.ts +++ b/e2e/page-objects/main-sidebar.ts @@ -10,7 +10,7 @@ export default class MainSidebar { } get addSiteButton() { - return this.page.getByTestId( 'add-site-button' ); + return this.locator.getByTestId( 'add-site-button' ); } getSiteNavButton( siteName: string ) { @@ -20,15 +20,13 @@ export default class MainSidebar { async openAddSiteModal() { const isButtonVisible = await this.addSiteButton.isVisible().catch( () => false ); - if ( isButtonVisible ) { - // Sites exist - need to open the modal - await this.addSiteButton.click(); - const dialog = new AddSiteModal( this.page ); - await expect( dialog.locator ).toBeVisible(); - return dialog; + if ( ! isButtonVisible ) { + throw new Error( 'Add Site button not found on the main sidebar' ); } - // No Add Site button visible means we're on empty screen - content is directly on page (no dialog wrapper) - return new AddSiteModal( this.page ); + await this.addSiteButton.click(); + const dialog = new AddSiteModal( this.page ); + await expect( dialog.locator ).toBeVisible(); + return dialog; } } diff --git a/e2e/page-objects/onboarding.ts b/e2e/page-objects/onboarding.ts index 462d1923a3..487f736911 100644 --- a/e2e/page-objects/onboarding.ts +++ b/e2e/page-objects/onboarding.ts @@ -1,6 +1,7 @@ import { type Page } from '@playwright/test'; import { expect } from '@playwright/test'; -import MainSidebar from './main-sidebar'; +import AddSiteModal from './add-site-modal'; +import WhatsNewModal from './whats-new-modal'; export default class Onboarding { constructor( private page: Page ) {} @@ -20,8 +21,8 @@ export default class Onboarding { await expect( this.heading ).toBeVisible(); await this.locator.getByRole( 'button', { name: 'Skip →' } ).click(); - const sidebar = new MainSidebar( this.page ); - const modal = await sidebar.openAddSiteModal(); + const modal = new AddSiteModal( this.page ); + await modal.open(); await modal.createSiteButton.click(); if ( customSiteName ) { @@ -42,4 +43,11 @@ export default class Onboarding { localPath, }; } + + async closeWhatsNew() { + const whatsNewModal = new WhatsNewModal( this.page ); + if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { + await whatsNewModal.closeButton.click(); + } + } } diff --git a/e2e/page-objects/whats-new-modal.ts b/e2e/page-objects/whats-new-modal.ts index ecedd84e3f..a23f6bd591 100644 --- a/e2e/page-objects/whats-new-modal.ts +++ b/e2e/page-objects/whats-new-modal.ts @@ -10,8 +10,4 @@ export default class WhatsNewModal { get closeButton() { return this.locator.getByRole( 'button', { name: 'Close' } ); } - - async close() { - await this.closeButton.click(); - } } diff --git a/e2e/sites.test.ts b/e2e/sites.test.ts index e16da3435e..1c3e973704 100644 --- a/e2e/sites.test.ts +++ b/e2e/sites.test.ts @@ -8,7 +8,6 @@ import { E2ESession } from './e2e-helpers'; import MainSidebar from './page-objects/main-sidebar'; import Onboarding from './page-objects/onboarding'; import SiteContent from './page-objects/site-content'; -import WhatsNewModal from './page-objects/whats-new-modal'; import { getUrlWithAutoLogin } from './utils'; const skipTestOnWindows = process.platform === 'win32' ? test.skip : test; @@ -35,7 +34,7 @@ test.describe( 'Servers', () => { customFolderName, } ); - await closeWhatsNew(); + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, siteName ); await expect( siteContent.siteNameHeading ).toBeVisible( { timeout: 120_000 } ); @@ -46,13 +45,6 @@ test.describe( 'Servers', () => { }; } - async function closeWhatsNew() { - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } - } - test.afterEach( async () => { await session.cleanup(); } ); diff --git a/metrics/tests/site-editor.test.ts b/metrics/tests/site-editor.test.ts index 40354fe1f8..c24843bc5f 100644 --- a/metrics/tests/site-editor.test.ts +++ b/metrics/tests/site-editor.test.ts @@ -37,12 +37,7 @@ test.describe( 'Site Editor Load Metrics', () => { // Wait for store initialization to complete (provider constants loading) await new Promise( ( resolve ) => setTimeout( resolve, 500 ) ); await onboarding.completeOnboarding( { customSiteName: siteName } ); - - // Handle the What's New modal if it appears - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); const siteContent = new SiteContent( session.mainWindow, siteName ); diff --git a/metrics/tests/site-startup.test.ts b/metrics/tests/site-startup.test.ts index 1f4409c22a..59a95a1bb6 100644 --- a/metrics/tests/site-startup.test.ts +++ b/metrics/tests/site-startup.test.ts @@ -41,12 +41,7 @@ test.describe( 'Startup Metrics', () => { await expect( onboarding.heading ).toBeVisible(); const startTime = Date.now(); await onboarding.completeOnboarding(); - - // Handle the What's New modal if it appears - const whatsNewModal = new WhatsNewModal( session.mainWindow ); - if ( await whatsNewModal.locator.isVisible( { timeout: 5000 } ) ) { - await whatsNewModal.closeButton.click(); - } + await onboarding.closeWhatsNew(); siteContent = new SiteContent( session.mainWindow, siteName ); await expect( siteContent.runningButton ).toBeAttached(); From f5ca55870d719aad19e2e96fa52362cf2e736ded Mon Sep 17 00:00:00 2001 From: Volodymyr Makukha Date: Tue, 2 Dec 2025 13:24:27 +0000 Subject: [PATCH 2/2] Remove unnecessary --- e2e/page-objects/add-site-modal.ts | 5 ----- e2e/page-objects/onboarding.ts | 1 - 2 files changed, 6 deletions(-) diff --git a/e2e/page-objects/add-site-modal.ts b/e2e/page-objects/add-site-modal.ts index 162bca6502..3a597fead7 100644 --- a/e2e/page-objects/add-site-modal.ts +++ b/e2e/page-objects/add-site-modal.ts @@ -5,11 +5,6 @@ import SiteForm from './site-form'; export default class AddSiteModal { constructor( private page: Page ) {} - async open() { - await this.page.getByTestId( 'add-site-button' ).click(); - await expect( this.locator ).toBeVisible(); - } - get locator() { return this.page.getByRole( 'dialog' ); } diff --git a/e2e/page-objects/onboarding.ts b/e2e/page-objects/onboarding.ts index 487f736911..876638169d 100644 --- a/e2e/page-objects/onboarding.ts +++ b/e2e/page-objects/onboarding.ts @@ -22,7 +22,6 @@ export default class Onboarding { await expect( this.heading ).toBeVisible(); await this.locator.getByRole( 'button', { name: 'Skip →' } ).click(); const modal = new AddSiteModal( this.page ); - await modal.open(); await modal.createSiteButton.click(); if ( customSiteName ) {