Skip to content

Add built-in command for selecting the editor canvas when it is iframed #134

Description

@Joe-Rouse

Is your feature request related to a problem? Please describe.

On WordPress 6.3 and above, the editor canvas can be iframed if there are no blocks registered with an API version lower than 3. In a future version of WordPress this will be standard no matter what blocks are registered. More info on this can be found here: https://make.wordpress.org/core/2023/07/18/miscellaneous-editor-changes-in-wordpress-6-3/#post-editor-iframed

This makes it harder as any selectors that try and get elements within the editor canvas don't work as you'd expect as they are now inside an iframe.

Describe the solution you'd like

There have been a few projects that implement the workaround documented in this Cypress blog post.

For example, on NewsPress' text only mode plugin:

const getIframeDocument = () => {
	return (
		cy
			.get( 'iframe[name="editor-canvas"]' )
			.its( '0.contentDocument' )
			.should( 'exist' )
	);
};

Cypress.Commands.add( 'getIframe', () => {
	return (
		getIframeDocument()
			.its( 'body' )
			.should( 'not.be.undefined' )
			.then( cy.wrap )
	);
} );

Cypress.Commands.add( 'getIntroParagraph', () => {
	return cy.getIframe().find( '.textOnly_content-intro' );
} );

It would be handy to have this as a command provided by the wp-cypress plugin to save having to add and maintain this across all projects that need it.

Describe alternatives you've considered

N/A

Additional context

N/A

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions