From 7e24ae4f91ee565145b67cb3bd829d98548b1c5f Mon Sep 17 00:00:00 2001 From: Bart Kalisz Date: Tue, 21 May 2024 16:46:26 +0200 Subject: [PATCH] E2E: Fix canvas waiter in visitSiteEditor (#61816) Co-authored-by: WunderBart Co-authored-by: ellatrix --- .../src/admin/visit-site-editor.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts b/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts index 0c9da7b695be07..f0a7db5ad966ff 100644 --- a/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts +++ b/packages/e2e-test-utils-playwright/src/admin/visit-site-editor.ts @@ -37,31 +37,32 @@ export async function visitSiteEditor( query.set( 'canvas', canvas ); } - const canvasLoader = this.page.locator( - // Spinner was used instead of the progress bar in an earlier version of - // the site editor. - '.edit-site-canvas-loader, .edit-site-canvas-spinner' - ); - await this.visitAdminPage( 'site-editor.php', query.toString() ); - // Try waiting for the canvas loader to appear first, so that the locator - // that waits for it to disappear doesn't resolve prematurely. - await canvasLoader.waitFor().catch( () => {} ); - /** * @todo This is a workaround for the fact that the editor canvas is seen as * ready and visible before the loading spinner is hidden. Ideally, the * content underneath the loading overlay should be marked inert until the * loading is done. */ - await canvasLoader.waitFor( { - state: 'hidden', - // Bigger timeout is needed for larger entities, like the Large Post - // HTML fixture that we load for performance tests, which often doesn't - // make it under the default timeout value. - timeout: 60_000, - } ); + if ( ! query.size || postId || canvas === 'edit' ) { + const canvasLoader = this.page.locator( + // Spinner was used instead of the progress bar in an earlier + // version of the site editor. + '.edit-site-canvas-loader, .edit-site-canvas-spinner' + ); + + // Wait for the canvas loader to appear first, so that the locator that + // waits for the hidden state doesn't resolve prematurely. + await canvasLoader.waitFor( { state: 'visible' } ); + await canvasLoader.waitFor( { + state: 'hidden', + // Bigger timeout is needed for larger entities, like the Large Post + // HTML fixture that we load for performance tests, which often + // doesn't make it under the default timeout value. + timeout: 60_000, + } ); + } if ( ! options.showWelcomeGuide ) { await this.editor.setPreferences( 'core/edit-site', {