Skip to content
Prev Previous commit
Resort to waiting for canvas after editor is open
  • Loading branch information
WunderBart authored and fullofcaffeine committed Feb 6, 2024
commit 0d829f202f150e28722fcb805f2b6ae25764616c
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export async function createNewPost(
welcomeGuide: options.showWelcomeGuide ?? false,
fullscreenMode: false,
} );

await this.editor.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
}
2 changes: 2 additions & 0 deletions packages/e2e-test-utils-playwright/src/admin/edit-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export async function editPost( this: Admin, postId: string | number ) {
welcomeGuide: false,
fullscreenMode: false,
} );

await this.editor.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
}
4 changes: 3 additions & 1 deletion packages/e2e-test-utils-playwright/src/editor/get-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export async function getBlocks(
this: Editor,
{ clientId, full = false }: { clientId?: string; full?: boolean } = {}
) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction(
() => window?.wp?.blocks && window?.wp?.data
);

return await this.page.evaluate(
( [ _full, _clientId ] ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Editor } from './index';
* @return Promise resolving with post content markup.
*/
export async function getEditedPostContent( this: Editor ) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction( () => window?.wp?.data );

return await this.page.evaluate( () =>
window.wp.data.select( 'core/editor' ).getEditedPostContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async function insertBlock(
blockRepresentation: BlockRepresentation,
{ clientId }: { clientId?: string } = {}
) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction(
() => window?.wp?.blocks && window?.wp?.data
);

await this.page.evaluate(
( [ _blockRepresentation, _clientId ] ) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/e2e-test-utils-playwright/src/editor/set-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type { Editor } from './index';
* @param html Serialized block HTML.
*/
async function setContent( this: Editor, html: string ) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction(
() => window?.wp?.blocks && window?.wp?.data
);

await this.page.evaluate( ( _html ) => {
const blocks = window.wp.blocks.parse( _html );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Editor } from './index';
* @param isFixed Boolean value true/false for on/off.
*/
export async function setIsFixedToolbar( this: Editor, isFixed: boolean ) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction( () => window?.wp?.data );

await this.page.evaluate( ( _isFixed ) => {
window.wp.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function setPreferences(
context: PreferencesContext,
preferences: Record< string, any >
) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction( () => window?.wp?.data );

await this.page.evaluate(
async ( props ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Editor } from './index';
* @param this
*/
export async function switchToLegacyCanvas( this: Editor ) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction( () => window?.wp?.blocks );

await this.page.evaluate( () => {
window.wp.blocks.registerBlockType( 'test/v2', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type { Editor } from './index';
* @param name Block name.
*/
export async function transformBlockTo( this: Editor, name: string ) {
await this.canvas.locator( 'body' ).waitFor( { state: 'visible' } );
await this.page.waitForFunction(
() => window?.wp?.blocks && window?.wp?.data
);

await this.page.evaluate(
( [ blockName ] ) => {
Expand Down