From 5261ddb3edb651df1fda6bd28b77b94962c4e09e Mon Sep 17 00:00:00 2001 From: "Marius L. J" Date: Wed, 28 Jun 2023 10:45:16 +0000 Subject: [PATCH] Build/Test Tools: Switch frame container when testing block editor output. When the block editor is rendered, the editor content is wrapped inside an iframe tag; The tool used to run End to End (E2E) tests, Puppeteer, puts all such frames into separate containers, but the initial test was checking if the parent page had a given selector, which was leading to timeout failures. By actively switching the container to the iframe wrapper,and setting it as the active context, it helps ensure the expected selectors can be found, and its content can be verrified. See #58592. Props joemcgill, SergeyBiryukov, talldanwp, oglekler, Clorith. git-svn-id: https://develop.svn.wordpress.org/trunk@56089 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/e2e/specs/edit-posts.test.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/e2e/specs/edit-posts.test.js b/tests/e2e/specs/edit-posts.test.js index 51d8824bb5..0dce05163f 100644 --- a/tests/e2e/specs/edit-posts.test.js +++ b/tests/e2e/specs/edit-posts.test.js @@ -27,15 +27,17 @@ describe( 'Edit Posts', () => { await page.waitForSelector( '#the-list .type-post' ); - // Expect there to be one row in the post list. - const posts = await page.$$( '#the-list .type-post' ); - expect( posts.length ).toBe( 1 ); + // Wait for the editor iframe to load, and switch to it as the active content frame. + const editorFrame = await page.waitForSelector( 'iframe[name="editor-canvas"]' ); - const [ firstPost ] = posts; + const innerFrame = await editorFrame.contentFrame(); - // Expect the title of the post to be correct. - const postTitle = await firstPost.$x( - `//a[contains(@class, "row-title")][contains(text(), "${ title }")]` + // Wait for title field to render onscreen. + await innerFrame.waitForSelector( '.editor-post-title__input' ); + + // Expect to now be in the editor with the correct post title shown. + const editorPostTitleInput = await innerFrame.$x( + `//h1[contains(@class, "editor-post-title__input")][contains(text(), "${ title }")]` ); expect( postTitle.length ).toBe( 1 ); } );