} Inner HTML.
*/
async function getRichTextInnerHTML() {
- const htmlContent = await page.$$( '*[contenteditable]' );
- return await page.evaluate( ( el ) => {
+ const htmlContent = await canvas().$$( '*[contenteditable]' );
+ return await canvas().evaluate( ( el ) => {
return el.innerHTML;
}, htmlContent[ 0 ] );
}
@@ -105,12 +106,12 @@ describe( 'Using Plugins API', () => {
await clickOnMoreMenuItem( 'Annotations Sidebar' );
- let annotations = await page.$$( ANNOTATIONS_SELECTOR );
+ let annotations = await canvas().$$( ANNOTATIONS_SELECTOR );
expect( annotations ).toHaveLength( 0 );
await annotateFirstBlock( 9, 13 );
- annotations = await page.$$( ANNOTATIONS_SELECTOR );
+ annotations = await canvas().$$( ANNOTATIONS_SELECTOR );
expect( annotations ).toHaveLength( 1 );
const text = await getAnnotatedText();
@@ -118,10 +119,10 @@ describe( 'Using Plugins API', () => {
await clickOnBlockSettingsMenuItem( 'Edit as HTML' );
- const htmlContent = await page.$$(
+ const htmlContent = await canvas().$$(
'.block-editor-block-list__block-html-textarea'
);
- const html = await page.evaluate( ( el ) => {
+ const html = await canvas().evaluate( ( el ) => {
return el.innerHTML;
}, htmlContent[ 0 ] );
@@ -139,8 +140,8 @@ describe( 'Using Plugins API', () => {
await page.keyboard.type( 'D' );
await removeAnnotations();
- const htmlContent = await page.$$( '*[contenteditable]' );
- const html = await page.evaluate( ( el ) => {
+ const htmlContent = await canvas().$$( '*[contenteditable]' );
+ const html = await canvas().evaluate( ( el ) => {
return el.innerHTML;
}, htmlContent[ 0 ] );
diff --git a/packages/e2e-tests/specs/editor/plugins/block-context.test.js b/packages/e2e-tests/specs/editor/plugins/block-context.test.js
index f09df529e70ce..000e925af2da2 100644
--- a/packages/e2e-tests/specs/editor/plugins/block-context.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/block-context.test.js
@@ -8,6 +8,7 @@ import {
insertBlock,
saveDraft,
openPreviewPage,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Block context', () => {
@@ -28,7 +29,7 @@ describe( 'Block context', () => {
// Inserting the context provider block should select the first inner
// block of the template. Verify the contents of the consumer.
- let innerBlockText = await page.evaluate(
+ let innerBlockText = await canvas().evaluate(
() => document.activeElement.textContent
);
expect( innerBlockText ).toBe( 'The record ID is: 0' );
@@ -39,7 +40,7 @@ describe( 'Block context', () => {
// Verify propagated context changes.
await page.keyboard.press( 'ArrowDown' );
- innerBlockText = await page.evaluate(
+ innerBlockText = await canvas().evaluate(
() => document.activeElement.textContent
);
expect( innerBlockText ).toBe( 'The record ID is: 123' );
@@ -60,7 +61,7 @@ describe( 'Block context', () => {
// Return to editor to change context value to non-default.
await editorPage.bringToFront();
- await editorPage.focus(
+ await canvas().focus(
'[data-type="gutenberg/test-context-provider"] input'
);
await editorPage.keyboard.press( 'ArrowRight' );
diff --git a/packages/e2e-tests/specs/editor/plugins/block-directory-add.test.js b/packages/e2e-tests/specs/editor/plugins/block-directory-add.test.js
index dde952f627477..576beefec22de 100644
--- a/packages/e2e-tests/specs/editor/plugins/block-directory-add.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/block-directory-add.test.js
@@ -8,6 +8,7 @@ import {
setUpResponseMocking,
getEditedPostContent,
createJSONResponse,
+ canvas,
} from '@wordpress/e2e-test-utils';
// Urls to mock
@@ -181,7 +182,9 @@ describe( 'adding blocks from block directory', () => {
// Search for the block via the inserter
await insertBlockDirectoryBlock( MOCK_BLOCK1.title );
- await page.waitForSelector( `div[data-type="${ MOCK_BLOCK1.name }"]` );
+ await canvas().waitForSelector(
+ `div[data-type="${ MOCK_BLOCK1.name }"]`
+ );
// The block will auto select and get added, make sure we see it in the content
expect( await getEditedPostContent() ).toMatchSnapshot();
diff --git a/packages/e2e-tests/specs/editor/plugins/block-icons.test.js b/packages/e2e-tests/specs/editor/plugins/block-icons.test.js
index d8fc23bf64e86..cbb4af9615ac8 100644
--- a/packages/e2e-tests/specs/editor/plugins/block-icons.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/block-icons.test.js
@@ -9,6 +9,7 @@ import {
pressKeyWithModifier,
searchForBlock,
openDocumentSettingsSidebar,
+ canvas,
} from '@wordpress/e2e-test-utils';
const INSERTER_BUTTON_SELECTOR =
@@ -17,8 +18,8 @@ const INSERTER_ICON_WRAPPER_SELECTOR = `${ INSERTER_BUTTON_SELECTOR } .block-edi
const INSERTER_ICON_SELECTOR = `${ INSERTER_BUTTON_SELECTOR } .block-editor-block-icon`;
const INSPECTOR_ICON_SELECTOR = '.edit-post-sidebar .block-editor-block-icon';
-async function getInnerHTML( selector ) {
- return await page.$eval( selector, ( element ) => element.innerHTML );
+async function getInnerHTML( selector, frame = page ) {
+ return await frame.$eval( selector, ( element ) => element.innerHTML );
}
async function getBackgroundColor( selector ) {
@@ -83,7 +84,8 @@ describe( 'Correctly Renders Block Icons on Inserter and Inspector', () => {
await insertBlock( blockTitle );
expect(
await getInnerHTML(
- `[data-type="${ blockName }"] [data-type="core/paragraph"]`
+ `[data-type="${ blockName }"] [data-type="core/paragraph"]`,
+ canvas()
)
).toEqual( blockTitle );
} );
diff --git a/packages/e2e-tests/specs/editor/plugins/block-variations.js b/packages/e2e-tests/specs/editor/plugins/block-variations.js
index ef4a17360284a..4d892ff0128c3 100644
--- a/packages/e2e-tests/specs/editor/plugins/block-variations.js
+++ b/packages/e2e-tests/specs/editor/plugins/block-variations.js
@@ -7,6 +7,7 @@ import {
deactivatePlugin,
insertBlock,
searchForBlock,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Block variations', () => {
@@ -52,7 +53,7 @@ describe( 'Block variations', () => {
await insertBlock( 'Large Quote' );
expect(
- await page.$(
+ await canvas().$(
'.wp-block[data-type="core/quote"] blockquote.is-style-large'
)
).toBeDefined();
@@ -82,7 +83,7 @@ describe( 'Block variations', () => {
test( 'Insert the Success Message block variation', async () => {
await insertBlock( 'Success Message' );
- const successMessageBlock = await page.$(
+ const successMessageBlock = await canvas().$(
'.wp-block[data-type="core/paragraph"]'
);
expect( successMessageBlock ).toBeDefined();
@@ -93,12 +94,12 @@ describe( 'Block variations', () => {
test( 'Pick the additional variation in the inserted Columns block', async () => {
await insertBlock( 'Columns' );
- const fourColumnsVariation = await page.waitForSelector(
+ const fourColumnsVariation = await canvas().waitForSelector(
'.wp-block[data-type="core/columns"] .block-editor-block-variation-picker__variation[aria-label="Four columns"]'
);
await fourColumnsVariation.click();
expect(
- await page.$$(
+ await canvas().$$(
'.wp-block[data-type="core/columns"] .wp-block[data-type="core/column"]'
)
).toHaveLength( 4 );
diff --git a/packages/e2e-tests/specs/editor/plugins/child-blocks.test.js b/packages/e2e-tests/specs/editor/plugins/child-blocks.test.js
index 183813a951136..f47be8ff4d60a 100644
--- a/packages/e2e-tests/specs/editor/plugins/child-blocks.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/child-blocks.test.js
@@ -9,6 +9,7 @@ import {
getAllBlockInserterItemTitles,
insertBlock,
openGlobalBlockInserter,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Child Blocks', () => {
@@ -34,10 +35,10 @@ describe( 'Child Blocks', () => {
it( 'shows up in a parent block', async () => {
await insertBlock( 'Child Blocks Unrestricted Parent' );
await closeGlobalBlockInserter();
- await page.waitForSelector(
+ await canvas().waitForSelector(
'[data-type="test/child-blocks-unrestricted-parent"] .block-editor-default-block-appender'
);
- await page.click(
+ await canvas().click(
'[data-type="test/child-blocks-unrestricted-parent"] .block-editor-default-block-appender'
);
await openGlobalBlockInserter();
@@ -49,10 +50,10 @@ describe( 'Child Blocks', () => {
it( 'display in a parent block with allowedItems', async () => {
await insertBlock( 'Child Blocks Restricted Parent' );
await closeGlobalBlockInserter();
- await page.waitForSelector(
+ await canvas().waitForSelector(
'[data-type="test/child-blocks-restricted-parent"] .block-editor-default-block-appender'
);
- await page.click(
+ await canvas().click(
'[data-type="test/child-blocks-restricted-parent"] .block-editor-default-block-appender'
);
await openGlobalBlockInserter();
diff --git a/packages/e2e-tests/specs/editor/plugins/container-blocks.test.js b/packages/e2e-tests/specs/editor/plugins/container-blocks.test.js
index e6d162eb18520..40c0785e2a9c1 100644
--- a/packages/e2e-tests/specs/editor/plugins/container-blocks.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/container-blocks.test.js
@@ -9,6 +9,7 @@ import {
insertBlock,
switchEditorModeTo,
pressKeyWithModifier,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'InnerBlocks Template Sync', () => {
@@ -99,7 +100,7 @@ describe( 'Container block without paragraph support', () => {
await insertBlock( 'Container without paragraph' );
// Open the specific appender used when there's no paragraph support.
- await page.click(
+ await canvas().click(
'.block-editor-inner-blocks .block-list-appender .block-list-appender__toggle'
);
diff --git a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js
index 1eefa0a69ebbf..de6616ed5c64b 100644
--- a/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js
@@ -12,6 +12,7 @@ import {
pressKeyTimes,
pressKeyWithModifier,
setPostContent,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'cpt locking', () => {
@@ -35,7 +36,7 @@ describe( 'cpt locking', () => {
};
const shouldNotAllowBlocksToBeRemoved = async () => {
- await page.type(
+ await canvas().type(
'.block-editor-rich-text__editable[data-type="core/paragraph"]',
'p1'
);
@@ -46,12 +47,12 @@ describe( 'cpt locking', () => {
};
const shouldAllowBlocksToBeMoved = async () => {
- await page.click(
+ await canvas().click(
'.block-editor-rich-text__editable[data-type="core/paragraph"]'
);
expect( await page.$( 'button[aria-label="Move up"]' ) ).not.toBeNull();
await page.click( 'button[aria-label="Move up"]' );
- await page.type(
+ await canvas().type(
'.block-editor-rich-text__editable[data-type="core/paragraph"]',
'p1'
);
@@ -71,14 +72,14 @@ describe( 'cpt locking', () => {
);
it( 'should not allow blocks to be moved', async () => {
- await page.click(
+ await canvas().click(
'.block-editor-rich-text__editable[data-type="core/paragraph"]'
);
expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull();
} );
it( 'should not error when deleting the cotents of a paragraph', async () => {
- await page.click(
+ await canvas().click(
'.block-editor-block-list__block[data-type="core/paragraph"]'
);
const textToType = 'Paragraph';
@@ -88,7 +89,7 @@ describe( 'cpt locking', () => {
} );
it( 'should insert line breaks when using enter and shift-enter', async () => {
- await page.click(
+ await canvas().click(
'.block-editor-block-list__block[data-type="core/paragraph"]'
);
await page.keyboard.type( 'First line' );
@@ -119,8 +120,10 @@ describe( 'cpt locking', () => {
} );
it( 'can use the global inserter in inner blocks', async () => {
- await page.click( 'button[aria-label="Two columns; equal split"]' );
- await page.click(
+ await canvas().click(
+ 'button[aria-label="Two columns; equal split"]'
+ );
+ await canvas().click(
'.wp-block-column .block-editor-button-block-appender'
);
await page.type( '.block-editor-inserter__search-input', 'image' );
@@ -133,7 +136,7 @@ describe( 'cpt locking', () => {
);
await pressKeyTimes( 'Tab', 2 );
await page.keyboard.press( 'Enter' );
- expect( await page.$( '.wp-block-gallery' ) ).not.toBeNull();
+ expect( await canvas().$( '.wp-block-gallery' ) ).not.toBeNull();
} );
} );
@@ -167,7 +170,7 @@ describe( 'cpt locking', () => {
} );
it( 'should allow blocks to be removed', async () => {
- await page.type(
+ await canvas().type(
'.block-editor-rich-text__editable[data-type="core/paragraph"]',
'p1'
);
@@ -187,7 +190,7 @@ describe( 'cpt locking', () => {
} );
it( 'should allow blocks to be removed', async () => {
- await page.type(
+ await canvas().type(
'.block-editor-rich-text__editable[data-type="core/paragraph"]',
'p1'
);
@@ -213,7 +216,7 @@ describe( 'cpt locking', () => {
);
it( 'should not allow blocks to be moved', async () => {
- await page.click(
+ await canvas().click(
'.block-editor-rich-text__editable[data-type="core/paragraph"]'
);
expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull();
@@ -233,7 +236,7 @@ describe( 'cpt locking', () => {
);
it( 'should not allow blocks to be moved', async () => {
- await page.click(
+ await canvas().click(
'.block-editor-rich-text__editable[data-type="core/paragraph"]'
);
expect( await page.$( 'button[aria-label="Move up"]' ) ).toBeNull();
diff --git a/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js b/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js
index 062d8b56c0725..d2bc0d673ce3b 100644
--- a/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js
@@ -7,6 +7,7 @@ import {
deactivatePlugin,
publishPost,
findSidebarPanelWithTitle,
+ canvas,
} from '@wordpress/e2e-test-utils';
const openPageAttributesPanel = async () => {
@@ -40,7 +41,7 @@ describe( 'Test Custom Post Types', () => {
// Create a parent post.
await createNewPost( { postType: 'hierar-no-title' } );
- await page.click( '.block-editor-writing-flow' );
+ await canvas().click( '.block-editor-writing-flow' );
await page.keyboard.type( 'Parent Post' );
await publishPost();
// Create a post that is a child of the previously created post.
@@ -55,7 +56,7 @@ describe( 'Test Custom Post Types', () => {
( element ) => element.textContent
);
await optionToSelect.click();
- await page.click( '.block-editor-writing-flow' );
+ await canvas().click( '.block-editor-writing-flow' );
await page.keyboard.type( 'Child Post' );
await publishPost();
// Reload the child post and verify it is still correctly selected as a child post.
@@ -71,11 +72,12 @@ describe( 'Test Custom Post Types', () => {
[ valueToSelect, PARENT_PAGE_INPUT ]
);
} );
+
it( 'should create a cpt with a legacy block in its template without WSOD', async () => {
await createNewPost( { postType: 'leg_block_in_tpl' } );
- await page.click( '.block-editor-writing-flow' );
+ await canvas().click( '.block-editor-writing-flow' );
await page.keyboard.type( 'Hello there' );
- await page.waitForSelector( '[data-type="core/embed"]' );
+ await canvas().waitForSelector( '[data-type="core/embed"]' );
await publishPost();
} );
} );
diff --git a/packages/e2e-tests/specs/editor/plugins/hooks-api.test.js b/packages/e2e-tests/specs/editor/plugins/hooks-api.test.js
index e015de70257c7..736658cf32346 100644
--- a/packages/e2e-tests/specs/editor/plugins/hooks-api.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/hooks-api.test.js
@@ -7,6 +7,7 @@ import {
createNewPost,
deactivatePlugin,
getEditedPostContent,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Using Hooks API', () => {
@@ -33,7 +34,7 @@ describe( 'Using Hooks API', () => {
it( 'Pressing reset block button resets the block', async () => {
await clickBlockAppender();
await page.keyboard.type( 'First paragraph' );
- const paragraphContent = await page.$eval(
+ const paragraphContent = await canvas().$eval(
'p[data-type="core/paragraph"]',
( element ) => element.textContent
);
diff --git a/packages/e2e-tests/specs/editor/plugins/image-size.test.js b/packages/e2e-tests/specs/editor/plugins/image-size.test.js
index a92ae63046550..aa6e24d8f7b85 100644
--- a/packages/e2e-tests/specs/editor/plugins/image-size.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/image-size.test.js
@@ -16,6 +16,7 @@ import {
deactivatePlugin,
insertBlock,
openDocumentSettingsSidebar,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'changing image size', () => {
@@ -30,7 +31,7 @@ describe( 'changing image size', () => {
it( 'should insert and change my image size', async () => {
await insertBlock( 'Image' );
- await clickButton( 'Media Library' );
+ await clickButton( 'Media Library', canvas() );
// Wait for media modal to appear and upload image.
await page.waitForSelector( '.media-modal input[type=file]' );
@@ -68,7 +69,9 @@ describe( 'changing image size', () => {
await imageSizeSelect.select( 'custom-size-one' );
// Verify that the custom size was applied to the image.
- await page.waitForSelector( '.wp-block-image.size-custom-size-one' );
+ await canvas().waitForSelector(
+ '.wp-block-image.size-custom-size-one'
+ );
await page.waitForFunction(
() =>
document.querySelector(
diff --git a/packages/e2e-tests/specs/editor/plugins/inner-blocks-allowed-blocks.test.js b/packages/e2e-tests/specs/editor/plugins/inner-blocks-allowed-blocks.test.js
index 1e02d4369f1b3..6af995ef5e149 100644
--- a/packages/e2e-tests/specs/editor/plugins/inner-blocks-allowed-blocks.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/inner-blocks-allowed-blocks.test.js
@@ -9,6 +9,7 @@ import {
insertBlock,
openGlobalBlockInserter,
closeGlobalBlockInserter,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Allowed Blocks Setting on InnerBlocks ', () => {
@@ -31,8 +32,8 @@ describe( 'Allowed Blocks Setting on InnerBlocks ', () => {
const childParagraphSelector = `${ parentBlockSelector } ${ paragraphSelector }`;
await insertBlock( 'Allowed Blocks Unset' );
await closeGlobalBlockInserter();
- await page.waitForSelector( childParagraphSelector );
- await page.click( childParagraphSelector );
+ await canvas().waitForSelector( childParagraphSelector );
+ await canvas().click( childParagraphSelector );
await openGlobalBlockInserter();
await expect(
( await getAllBlockInserterItemTitles() ).length
@@ -44,8 +45,8 @@ describe( 'Allowed Blocks Setting on InnerBlocks ', () => {
const childParagraphSelector = `${ parentBlockSelector } ${ paragraphSelector }`;
await insertBlock( 'Allowed Blocks Set' );
await closeGlobalBlockInserter();
- await page.waitForSelector( childParagraphSelector );
- await page.click( childParagraphSelector );
+ await canvas().waitForSelector( childParagraphSelector );
+ await canvas().click( childParagraphSelector );
await openGlobalBlockInserter();
expect( await getAllBlockInserterItemTitles() ).toEqual( [
'Button',
@@ -62,8 +63,8 @@ describe( 'Allowed Blocks Setting on InnerBlocks ', () => {
const parentBlockSelector = '[data-type="test/allowed-blocks-dynamic"]';
const blockAppender = '.block-list-appender button';
const appenderSelector = `${ parentBlockSelector } ${ blockAppender }`;
- await page.waitForSelector( appenderSelector );
- await page.click( appenderSelector );
+ await canvas().waitForSelector( appenderSelector );
+ await canvas().click( appenderSelector );
expect( await getAllBlockInserterItemTitles() ).toEqual( [
'Image',
'List',
@@ -74,8 +75,10 @@ describe( 'Allowed Blocks Setting on InnerBlocks ', () => {
await insertButton.click();
await insertBlock( 'Image' );
await closeGlobalBlockInserter();
- await page.waitForSelector( '.product[data-number-of-children="2"]' );
- await page.click( appenderSelector );
+ await canvas().waitForSelector(
+ '.product[data-number-of-children="2"]'
+ );
+ await canvas().click( appenderSelector );
expect( await getAllBlockInserterItemTitles() ).toEqual( [
'Gallery',
'Video',
diff --git a/packages/e2e-tests/specs/editor/plugins/inner-blocks-render-appender.test.js b/packages/e2e-tests/specs/editor/plugins/inner-blocks-render-appender.test.js
index 182f224d0976f..c89c31bcaa0ec 100644
--- a/packages/e2e-tests/specs/editor/plugins/inner-blocks-render-appender.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/inner-blocks-render-appender.test.js
@@ -9,6 +9,7 @@ import {
getEditedPostContent,
insertBlock,
closeGlobalBlockInserter,
+ canvas,
} from '@wordpress/e2e-test-utils';
const INSERTER_RESULTS_SELECTOR =
@@ -35,17 +36,17 @@ describe( 'RenderAppender prop of InnerBlocks ', () => {
await insertBlock( 'InnerBlocks renderAppender' );
await closeGlobalBlockInserter();
// Wait for the custom block appender to appear.
- await page.waitForSelector( APPENDER_SELECTOR );
+ await canvas().waitForSelector( APPENDER_SELECTOR );
// Verify if the custom block appender text is the expected one.
expect(
- await page.evaluate(
+ await canvas().evaluate(
( el ) => el.innerText,
- await page.$( `${ APPENDER_SELECTOR } > span` )
+ await canvas().$( `${ APPENDER_SELECTOR } > span` )
)
).toEqual( 'My custom awesome appender' );
// Open the inserter of our custom block appender and expand all the categories.
- await page.click(
+ await canvas().click(
`${ APPENDER_SELECTOR } .block-editor-button-block-appender`
);
// Verify if the blocks the custom inserter is rendering are the expected ones.
@@ -72,16 +73,16 @@ describe( 'RenderAppender prop of InnerBlocks ', () => {
await closeGlobalBlockInserter();
// Wait for the custom dynamic block appender to appear.
- await page.waitForSelector( '.' + DYNAMIC_APPENDER_SELECTOR );
+ await canvas().waitForSelector( '.' + DYNAMIC_APPENDER_SELECTOR );
// Verify if the custom block appender text is the expected one.
- await page.waitForXPath(
+ await canvas().waitForXPath(
`//*[contains(@class, "${ DYNAMIC_APPENDER_SELECTOR }")]/span[contains(@class, "empty-blocks-appender")][contains(text(), "Empty Blocks Appender")]`
);
// Open the inserter of our custom block appender and expand all the categories.
const blockAppenderButtonSelector = `.${ DYNAMIC_APPENDER_SELECTOR } .block-editor-button-block-appender`;
- await page.click( blockAppenderButtonSelector );
+ await canvas().click( blockAppenderButtonSelector );
// Verify if the blocks the custom inserter is rendering are the expected ones.
expect( await getAllBlockInserterItemTitles() ).toEqual( [
@@ -99,23 +100,23 @@ describe( 'RenderAppender prop of InnerBlocks ', () => {
await quoteButton.click();
// Verify if the custom block appender text changed as expected.
- await page.waitForXPath(
+ await canvas().waitForXPath(
`//*[contains(@class, "${ DYNAMIC_APPENDER_SELECTOR }")]/span[contains(@class, "single-blocks-appender")][contains(text(), "Single Blocks Appender")]`
);
// Verify that the custom appender button is still being rendered.
- expect( await page.$( blockAppenderButtonSelector ) ).toBeTruthy();
+ expect( await canvas().$( blockAppenderButtonSelector ) ).toBeTruthy();
// Insert a video block.
await insertBlock( 'Video' );
// Verify if the custom block appender text changed as expected.
- await page.waitForXPath(
+ await canvas().waitForXPath(
`//*[contains(@class, "${ DYNAMIC_APPENDER_SELECTOR }")]/span[contains(@class, "multiple-blocks-appender")][contains(text(), "Multiple Blocks Appender")]`
);
// Verify that the custom appender button is now not being rendered.
- expect( await page.$( blockAppenderButtonSelector ) ).toBeFalsy();
+ expect( await canvas().$( blockAppenderButtonSelector ) ).toBeFalsy();
// Verify that final block markup is the expected one.
expect( await getEditedPostContent() ).toMatchSnapshot();
diff --git a/packages/e2e-tests/specs/editor/plugins/innerblocks-locking-all-embed.js b/packages/e2e-tests/specs/editor/plugins/innerblocks-locking-all-embed.js
index a0a83fbf90e61..2ad250ff72e62 100644
--- a/packages/e2e-tests/specs/editor/plugins/innerblocks-locking-all-embed.js
+++ b/packages/e2e-tests/specs/editor/plugins/innerblocks-locking-all-embed.js
@@ -9,6 +9,7 @@ import {
createEmbeddingMatcher,
createJSONResponse,
setUpResponseMocking,
+ canvas,
} from '@wordpress/e2e-test-utils';
const MOCK_RESPONSES = [
@@ -45,12 +46,12 @@ describe( 'Embed block inside a locked all parent', () => {
await insertBlock( 'Test Inner Blocks Locking All Embed' );
const embedInputSelector =
'.components-placeholder__input[aria-label="Embed URL"]';
- await page.waitForSelector( embedInputSelector );
- await page.click( embedInputSelector );
+ await canvas().waitForSelector( embedInputSelector );
+ await canvas().click( embedInputSelector );
// This URL should not have a trailing slash.
await page.keyboard.type( 'https://twitter.com/wordpress' );
await page.keyboard.press( 'Enter' );
// The twitter block should appear correctly.
- await page.waitForSelector( 'figure.wp-block-embed' );
+ await canvas().waitForSelector( 'figure.wp-block-embed' );
} );
} );
diff --git a/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js b/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js
index a11cbb1f6872e..792271623a3c5 100644
--- a/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js
@@ -9,6 +9,7 @@ import {
insertBlock,
saveDraft,
pressKeyTimes,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Block with a meta attribute', () => {
@@ -44,7 +45,7 @@ describe( 'Block with a meta attribute', () => {
await page.waitForSelector( '.edit-post-layout' );
expect( await getEditedPostContent() ).toMatchSnapshot();
- const persistedValue = await page.evaluate(
+ const persistedValue = await canvas().evaluate(
() => document.querySelector( '.my-meta-input' ).value
);
expect( persistedValue ).toBe( 'Meta Value' );
@@ -56,7 +57,7 @@ describe( 'Block with a meta attribute', () => {
await insertBlock( `Test Meta Attribute Block (${ variant })` );
await page.keyboard.type( 'Meta Value' );
- const inputs = await page.$$( '.my-meta-input' );
+ const inputs = await canvas().$$( '.my-meta-input' );
await Promise.all(
inputs.map( async ( input ) => {
// Clicking the input selects the block,
@@ -90,7 +91,7 @@ describe( 'Block with a meta attribute', () => {
await page.waitForSelector( '.edit-post-layout' );
expect( await getEditedPostContent() ).toMatchSnapshot();
- const persistedValue = await page.evaluate(
+ const persistedValue = await canvas().evaluate(
() => document.querySelector( '.my-meta-input' ).value
);
expect( persistedValue ).toBe( 'Meta Value' );
diff --git a/packages/e2e-tests/specs/editor/plugins/meta-boxes.test.js b/packages/e2e-tests/specs/editor/plugins/meta-boxes.test.js
index b7b13a4be08da..07dc140f11adc 100644
--- a/packages/e2e-tests/specs/editor/plugins/meta-boxes.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/meta-boxes.test.js
@@ -10,6 +10,7 @@ import {
openDocumentSettingsSidebar,
publishPost,
saveDraft,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Meta boxes', () => {
@@ -30,7 +31,7 @@ describe( 'Meta boxes', () => {
expect( await page.$( '.editor-post-save-draft' ) ).toBe( null );
// Add title to enable valid non-empty post save.
- await page.type( '.editor-post-title__input', 'Hello Meta' );
+ await canvas().type( '.editor-post-title__input', 'Hello Meta' );
expect( await page.$( '.editor-post-save-draft' ) ).not.toBe( null );
await saveDraft();
@@ -41,14 +42,17 @@ describe( 'Meta boxes', () => {
it( 'Should render dynamic blocks when the meta box uses the excerpt for front end rendering', async () => {
// Publish a post so there's something for the latest posts dynamic block to render.
- await page.type( '.editor-post-title__input', 'A published post' );
+ await canvas().type( '.editor-post-title__input', 'A published post' );
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Hello there!' );
await publishPost();
// Publish a post with the latest posts dynamic block.
await createNewPost();
- await page.type( '.editor-post-title__input', 'Dynamic block test' );
+ await canvas().type(
+ '.editor-post-title__input',
+ 'Dynamic block test'
+ );
await insertBlock( 'Latest Posts' );
await publishPost();
@@ -66,7 +70,7 @@ describe( 'Meta boxes', () => {
it( 'Should render the excerpt in meta based on post content if no explicit excerpt exists', async () => {
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Excerpt from content.' );
- await page.type( '.editor-post-title__input', 'A published post' );
+ await canvas().type( '.editor-post-title__input', 'A published post' );
await publishPost();
// View the post.
@@ -89,7 +93,7 @@ describe( 'Meta boxes', () => {
it( 'Should render the explicitly set excerpt in meta instead of the content based one', async () => {
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Excerpt from content.' );
- await page.type( '.editor-post-title__input', 'A published post' );
+ await canvas().type( '.editor-post-title__input', 'A published post' );
// Open the excerpt panel
await openDocumentSettingsSidebar();
diff --git a/packages/e2e-tests/specs/editor/plugins/templates.test.js b/packages/e2e-tests/specs/editor/plugins/templates.test.js
index 173acdff8c031..862025e629788 100644
--- a/packages/e2e-tests/specs/editor/plugins/templates.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/templates.test.js
@@ -12,6 +12,7 @@ import {
switchUserToAdmin,
switchUserToTest,
visitAdminPage,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'templates', () => {
@@ -35,7 +36,7 @@ describe( 'templates', () => {
it( 'Should respect user edits to not re-apply template after save (single block removal)', async () => {
// Remove a block from the template to verify that it's not
// re-added after saving and reloading the editor.
- await page.click( '.editor-post-title__input' );
+ await canvas().click( '.editor-post-title__input' );
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.press( 'Backspace' );
await saveDraft();
@@ -48,7 +49,7 @@ describe( 'templates', () => {
it( 'Should respect user edits to not re-apply template after save (full delete)', async () => {
// Remove all blocks from the template to verify that they're not
// re-added after saving and reloading the editor.
- await page.type( '.editor-post-title__input', 'My Empty Book' );
+ await canvas().type( '.editor-post-title__input', 'My Empty Book' );
await page.keyboard.press( 'ArrowDown' );
await pressKeyWithModifier( 'primary', 'A' );
await page.keyboard.press( 'Backspace' );
@@ -99,7 +100,10 @@ describe( 'templates', () => {
// Remove the default block template to verify that it's not
// re-added after saving and reloading the editor.
- await page.type( '.editor-post-title__input', 'My Image Format' );
+ await canvas().type(
+ '.editor-post-title__input',
+ 'My Image Format'
+ );
await clickBlockAppender();
await page.keyboard.press( 'Backspace' );
await page.keyboard.press( 'Backspace' );
diff --git a/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js b/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js
index 761830e8481c7..8d7d78e69f382 100644
--- a/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js
+++ b/packages/e2e-tests/specs/editor/plugins/wp-editor-meta-box.test.js
@@ -6,6 +6,7 @@ import {
createNewPost,
deactivatePlugin,
publishPost,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'WP Editor Meta Boxes', () => {
@@ -20,7 +21,7 @@ describe( 'WP Editor Meta Boxes', () => {
it( 'Should save the changes', async () => {
// Add title to enable valid non-empty post save.
- await page.type( '.editor-post-title__input', 'Hello Meta' );
+ await canvas().type( '.editor-post-title__input', 'Hello Meta' );
// Type something
await expect( page ).toClick( '#test_tinymce_id-html' );
diff --git a/packages/e2e-tests/specs/editor/various/adding-blocks.test.js b/packages/e2e-tests/specs/editor/various/adding-blocks.test.js
index 5f71713055595..a9cc9f402baa2 100644
--- a/packages/e2e-tests/specs/editor/various/adding-blocks.test.js
+++ b/packages/e2e-tests/specs/editor/various/adding-blocks.test.js
@@ -10,6 +10,7 @@ import {
closeGlobalBlockInserter,
searchForBlock,
showBlockToolbar,
+ canvas,
} from '@wordpress/e2e-test-utils';
/** @typedef {import('puppeteer').ElementHandle} ElementHandle */
@@ -71,7 +72,7 @@ describe( 'adding blocks', () => {
await page.$( '.interface-interface-skeleton__content' )
);
expect(
- await page.waitForSelector( '[data-type="core/paragraph"]' )
+ await canvas().waitForSelector( '[data-type="core/paragraph"]' )
).not.toBeNull();
await page.keyboard.type( 'Paragraph block' );
@@ -125,11 +126,11 @@ describe( 'adding blocks', () => {
await page.keyboard.type( 'lines preserved[/myshortcode]' );
// Unselect blocks to avoid conflicts with the inbetween inserter
- await page.click( '.editor-post-title__input' );
+ await canvas().click( '.editor-post-title__input' );
await closeGlobalBlockInserter();
// Using the between inserter
- const insertionPoint = await page.$( '[data-type="core/quote"]' );
+ const insertionPoint = await canvas().$( '[data-type="core/quote"]' );
const rect = await insertionPoint.boundingBox();
await page.mouse.move( rect.x + rect.width / 2, rect.y - 10, {
steps: 10,
@@ -225,13 +226,13 @@ describe( 'adding blocks', () => {
await page.keyboard.type( '1.1' );
// After inserting the Buttons block the inner button block should be selected.
- const selectedButtonBlocks = await page.$$(
+ const selectedButtonBlocks = await canvas().$$(
'.wp-block-button.is-selected'
);
expect( selectedButtonBlocks.length ).toBe( 1 );
// Specifically click the root container appender.
- await page.click(
+ await canvas().click(
'.block-editor-block-list__layout.is-root-container > .block-list-appender .block-editor-inserter__toggle'
);
@@ -268,7 +269,7 @@ describe( 'adding blocks', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
// Using the between inserter
- const insertionPoint = await page.$( '[data-type="core/heading"]' );
+ const insertionPoint = await canvas().$( '[data-type="core/heading"]' );
const rect = await insertionPoint.boundingBox();
await page.mouse.move( rect.x + rect.width / 2, rect.y - 10, {
steps: 10,
@@ -308,10 +309,10 @@ describe( 'adding blocks', () => {
await page.keyboard.type( 'First paragraph' );
await insertBlock( 'Image' );
await showBlockToolbar();
- const paragraphBlock = await page.$(
+ const paragraphBlock = await canvas().$(
'p[aria-label="Paragraph block"]'
);
- paragraphBlock.click();
+ await paragraphBlock.click();
await showBlockToolbar();
// Open the global inserter and search for the Heading block.
@@ -341,7 +342,9 @@ describe( 'adding blocks', () => {
await insertBlock( 'Group' );
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Paragraph after group' );
- await page.click( '[data-type="core/group"] [aria-label="Add block"]' );
+ await canvas().click(
+ '[data-type="core/group"] [aria-label="Add block"]'
+ );
const browseAll = await page.waitForXPath(
'//button[text()="Browse all"]'
);
diff --git a/packages/e2e-tests/specs/editor/various/autosave.test.js b/packages/e2e-tests/specs/editor/various/autosave.test.js
index 6608b286980ba..d9e5ac60728d7 100644
--- a/packages/e2e-tests/specs/editor/various/autosave.test.js
+++ b/packages/e2e-tests/specs/editor/various/autosave.test.js
@@ -9,6 +9,7 @@ import {
publishPost,
saveDraft,
toggleOfflineMode,
+ canvas,
} from '@wordpress/e2e-test-utils';
// Constant to override editor preference
@@ -258,7 +259,7 @@ describe( 'autosave', () => {
await page.keyboard.type( 'before publish' );
await publishPost();
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
await page.keyboard.type( ' after publish' );
// Trigger remote autosave
diff --git a/packages/e2e-tests/specs/editor/various/block-deletion.test.js b/packages/e2e-tests/specs/editor/various/block-deletion.test.js
index 80d9d3a11e19b..f68934c6c4560 100644
--- a/packages/e2e-tests/specs/editor/various/block-deletion.test.js
+++ b/packages/e2e-tests/specs/editor/various/block-deletion.test.js
@@ -10,6 +10,7 @@ import {
pressKeyWithModifier,
pressKeyTimes,
insertBlock,
+ canvas,
} from '@wordpress/e2e-test-utils';
const addThreeParagraphsToNewPost = async () => {
@@ -110,10 +111,10 @@ describe( 'block deletion -', () => {
await page.keyboard.press( 'Enter' );
// Click on something that's not a block.
- await page.click( '.editor-post-title' );
+ await canvas().click( '.editor-post-title' );
// Click on the image block so that its wrapper is selected and backspace to delete it.
- await page.click(
+ await canvas().click(
'.wp-block[data-type="core/image"] .components-placeholder__label'
);
await page.keyboard.press( 'Backspace' );
@@ -158,7 +159,7 @@ describe( 'deleting all blocks', () => {
// There is a default block:
expect(
- await page.$$( '.block-editor-block-list__block' )
+ await canvas().$$( '.block-editor-block-list__block' )
).toHaveLength( 1 );
// But the effective saved content is still empty:
@@ -189,7 +190,7 @@ describe( 'deleting all blocks', () => {
// Add and remove a block.
await insertBlock( 'Image' );
- await page.waitForSelector( 'figure[data-type="core/image"]' );
+ await canvas().waitForSelector( 'figure[data-type="core/image"]' );
await page.keyboard.press( 'Backspace' );
// Verify there is no selected block.
diff --git a/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js b/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js
index 919a10bebe0f1..877d91af83947 100644
--- a/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js
+++ b/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js
@@ -8,6 +8,7 @@ import {
pressKeyTimes,
pressKeyWithModifier,
openDocumentSettingsSidebar,
+ canvas,
} from '@wordpress/e2e-test-utils';
async function openBlockNavigator() {
@@ -39,7 +40,7 @@ describe( 'Navigating the block hierarchy', () => {
it( 'should navigate using the block hierarchy dropdown menu', async () => {
await insertBlock( 'Columns' );
- await page.click( '[aria-label="Two columns; equal split"]' );
+ await canvas().click( '[aria-label="Two columns; equal split"]' );
// Add a paragraph in the first column.
await page.keyboard.press( 'Tab' ); // Tab to inserter.
@@ -91,7 +92,7 @@ describe( 'Navigating the block hierarchy', () => {
it( 'should navigate block hierarchy using only the keyboard', async () => {
await insertBlock( 'Columns' );
await openDocumentSettingsSidebar();
- await page.click( '[aria-label="Two columns; equal split"]' );
+ await canvas().click( '[aria-label="Two columns; equal split"]' );
// Add a paragraph in the first column.
await page.keyboard.press( 'Tab' ); // Tab to inserter.
@@ -118,7 +119,9 @@ describe( 'Navigating the block hierarchy', () => {
await openBlockNavigator();
await pressKeyTimes( 'ArrowDown', 4 );
await page.keyboard.press( 'Enter' );
- await page.waitForSelector( '.is-selected[data-type="core/column"]' );
+ await canvas().waitForSelector(
+ '.is-selected[data-type="core/column"]'
+ );
// Insert text in the last column block
await page.keyboard.press( 'Tab' ); // Tab to inserter.
@@ -160,7 +163,7 @@ describe( 'Navigating the block hierarchy', () => {
// Insert some random blocks.
// The last block shouldn't be a textual block.
- await page.click( '.block-list-appender .block-editor-inserter' );
+ await canvas().click( '.block-list-appender .block-editor-inserter' );
const paragraphMenuItem = (
await page.$x( `//button//span[contains(text(), 'Paragraph')]` )
)[ 0 ];
@@ -172,7 +175,7 @@ describe( 'Navigating the block hierarchy', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
// Unselect the blocks
- await page.click( '.editor-post-title' );
+ await canvas().click( '.editor-post-title' );
// Try selecting the group block using the Outline
await page.click( '[aria-label="Outline"]' );
@@ -184,7 +187,7 @@ describe( 'Navigating the block hierarchy', () => {
await groupMenuItem.click();
// The group block's wrapper should be selected.
- const isGroupBlockSelected = await page.evaluate(
+ const isGroupBlockSelected = await canvas().evaluate(
() =>
document.activeElement.getAttribute( 'data-type' ) ===
'core/group'
diff --git a/packages/e2e-tests/specs/editor/various/block-mover.test.js b/packages/e2e-tests/specs/editor/various/block-mover.test.js
index c3a04f6f3a6c4..b239b378f4aea 100644
--- a/packages/e2e-tests/specs/editor/various/block-mover.test.js
+++ b/packages/e2e-tests/specs/editor/various/block-mover.test.js
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
-import { createNewPost, showBlockToolbar } from '@wordpress/e2e-test-utils';
+import {
+ createNewPost,
+ showBlockToolbar,
+ canvas,
+} from '@wordpress/e2e-test-utils';
describe( 'block mover', () => {
beforeEach( async () => {
@@ -10,13 +14,13 @@ describe( 'block mover', () => {
it( 'should show block mover when more than one block exists', async () => {
// Create a two blocks on the page.
- await page.click( '.block-editor-default-block-appender' );
+ await canvas().click( '.block-editor-default-block-appender' );
await page.keyboard.type( 'First Paragraph' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Second Paragraph' );
// Select a block so the block mover is rendered.
- await page.focus( '.block-editor-block-list__block' );
+ await canvas().focus( '.block-editor-block-list__block' );
await showBlockToolbar();
@@ -27,11 +31,11 @@ describe( 'block mover', () => {
it( 'should hide block mover when only one block exists', async () => {
// Create a single block on the page.
- await page.click( '.block-editor-default-block-appender' );
+ await canvas().click( '.block-editor-default-block-appender' );
await page.keyboard.type( 'First Paragraph' );
// Select a block so the block mover has the possibility of being rendered.
- await page.focus( '.block-editor-block-list__block' );
+ await canvas().focus( '.block-editor-block-list__block' );
await showBlockToolbar();
diff --git a/packages/e2e-tests/specs/editor/various/change-detection.test.js b/packages/e2e-tests/specs/editor/various/change-detection.test.js
index 8bac378e8aaa1..e27c60e467345 100644
--- a/packages/e2e-tests/specs/editor/various/change-detection.test.js
+++ b/packages/e2e-tests/specs/editor/various/change-detection.test.js
@@ -10,6 +10,7 @@ import {
saveDraft,
openDocumentSettingsSidebar,
isCurrentURL,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Change detection', () => {
@@ -77,7 +78,7 @@ describe( 'Change detection', () => {
} );
it( 'Should autosave post', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Force autosave to occur immediately.
await Promise.all( [
@@ -93,7 +94,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt to confirm unsaved changes for autosaved draft for non-content fields', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Toggle post as needing review (not persisted for autosave).
await ensureSidebarOpened();
@@ -116,7 +117,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt to confirm unsaved changes for autosaved published post', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
await publishPost();
@@ -129,7 +130,7 @@ describe( 'Change detection', () => {
] );
// Should be dirty after autosave change of published post.
- await page.type( '.editor-post-title__input', '!' );
+ await canvas().type( '.editor-post-title__input', '!' );
await Promise.all( [
page.waitForSelector( '.editor-post-publish-button.is-busy' ),
@@ -159,7 +160,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt if property changed without save', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
await assertIsDirty( true );
} );
@@ -172,7 +173,7 @@ describe( 'Change detection', () => {
} );
it( 'Should not prompt if changes saved', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
await saveDraft();
@@ -189,7 +190,7 @@ describe( 'Change detection', () => {
} );
it( 'Should not save if all changes saved', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
await saveDraft();
@@ -202,7 +203,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt if save failed', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
await page.setOfflineMode( true );
@@ -228,7 +229,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt if changes and save is in-flight', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Hold the posts request so we don't deal with race conditions of the
// save completing early. Other requests should be allowed to continue,
@@ -244,7 +245,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt if changes made while save is in-flight', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Hold the posts request so we don't deal with race conditions of the
// save completing early. Other requests should be allowed to continue,
@@ -254,7 +255,7 @@ describe( 'Change detection', () => {
// Keyboard shortcut Ctrl+S save.
await pressKeyWithModifier( 'primary', 'S' );
- await page.type( '.editor-post-title__input', '!' );
+ await canvas().type( '.editor-post-title__input', '!' );
await page.waitForSelector( '.editor-post-save-draft' );
await releaseSaveIntercept();
@@ -263,7 +264,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt if property changes made while save is in-flight, and save completes', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Hold the posts request so we don't deal with race conditions of the
// save completing early.
@@ -273,7 +274,7 @@ describe( 'Change detection', () => {
await pressKeyWithModifier( 'primary', 'S' );
// Dirty post while save is in-flight.
- await page.type( '.editor-post-title__input', '!' );
+ await canvas().type( '.editor-post-title__input', '!' );
// Allow save to complete. Disabling interception flushes pending.
await Promise.all( [
@@ -285,7 +286,7 @@ describe( 'Change detection', () => {
} );
it( 'Should prompt if block revision is made while save is in-flight, and save completes', async () => {
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Hold the posts request so we don't deal with race conditions of the
// save completing early.
@@ -315,7 +316,7 @@ describe( 'Change detection', () => {
await saveDraft();
// Verify that the title is empty.
- const title = await page.$eval(
+ const title = await canvas().$eval(
'.editor-post-title__input',
( element ) => element.innerHTML
);
@@ -327,7 +328,7 @@ describe( 'Change detection', () => {
it( 'should not prompt to confirm unsaved changes when trashing an existing post', async () => {
// Enter title.
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Save
await saveDraft();
@@ -371,12 +372,12 @@ describe( 'Change detection', () => {
] );
// Increase the paragraph's font size.
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
await page.click( '.components-font-size-picker__select' );
await page.click(
'.components-custom-select-control__item:nth-child(3)'
);
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
// Check that the post is dirty.
await page.waitForSelector( '.editor-post-save-draft' );
@@ -388,12 +389,12 @@ describe( 'Change detection', () => {
] );
// Increase the paragraph's font size again.
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
await page.click( '.components-font-size-picker__select' );
await page.click(
'.components-custom-select-control__item:nth-child(4)'
);
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
// Check that the post is dirty.
await page.waitForSelector( '.editor-post-save-draft' );
diff --git a/packages/e2e-tests/specs/editor/various/draggable-block.test.js b/packages/e2e-tests/specs/editor/various/draggable-block.test.js
index 2d0ebc0bb8974..8e362ebc3e714 100644
--- a/packages/e2e-tests/specs/editor/various/draggable-block.test.js
+++ b/packages/e2e-tests/specs/editor/various/draggable-block.test.js
@@ -7,6 +7,7 @@ import {
deactivatePlugin,
activatePlugin,
showBlockToolbar,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Draggable block', () => {
@@ -59,37 +60,28 @@ describe( 'Draggable block', () => {
await page.mouse.move( x + 10, y + 10, { steps: 10 } );
// Confirm dragged state.
- await page.waitForSelector( '.block-editor-block-mover__drag-clone' );
-
- const paragraph = await page.$( '[data-type="core/paragraph"]' );
-
- const paragraphRect = await paragraph.boundingBox();
- const pX = paragraphRect.x + paragraphRect.width / 2;
- const pY = paragraphRect.y + paragraphRect.height / 3;
-
- // Move over upper side of the first paragraph.
- await page.mouse.move( pX, pY, { steps: 10 } );
+ await page.waitForSelector( '.components-draggable__clone' );
// Puppeteer fires the initial `dragstart` event, but no further events.
// Simulating the drop event works.
- await paragraph.evaluate(
- ( element, clientX, clientY ) => {
- const dataTransfer = new DataTransfer();
- dataTransfer.setData(
- 'text/plain',
- JSON.stringify( window._dataTransfer )
- );
- const event = new DragEvent( 'drop', {
- bubbles: true,
- clientX,
- clientY,
- dataTransfer,
- } );
- element.dispatchEvent( event );
- },
- pX,
- pY
- );
+ await canvas().evaluate( () => {
+ const paragraph = document.querySelector(
+ '[data-type="core/paragraph"]'
+ );
+ const paragraphRect = paragraph.getBoundingClientRect();
+ const dataTransfer = new DataTransfer();
+ dataTransfer.setData(
+ 'text/plain',
+ JSON.stringify( window.parent._dataTransfer )
+ );
+ const event = new DragEvent( 'drop', {
+ bubbles: true,
+ clientX: paragraphRect.x + paragraphRect.width / 2,
+ clientY: paragraphRect.y + paragraphRect.height / 3,
+ dataTransfer,
+ } );
+ paragraph.dispatchEvent( event );
+ } );
await page.mouse.up();
diff --git a/packages/e2e-tests/specs/editor/various/editor-modes.test.js b/packages/e2e-tests/specs/editor/various/editor-modes.test.js
index 82e481ead2da2..3c343ebbdebb4 100644
--- a/packages/e2e-tests/specs/editor/various/editor-modes.test.js
+++ b/packages/e2e-tests/specs/editor/various/editor-modes.test.js
@@ -10,6 +10,7 @@ import {
switchEditorModeTo,
pressKeyTimes,
pressKeyWithModifier,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Editing modes (visual/HTML)', () => {
@@ -21,7 +22,7 @@ describe( 'Editing modes (visual/HTML)', () => {
it( 'should switch between visual and HTML modes', async () => {
// This block should be in "visual" mode by default.
- let visualBlock = await page.$$(
+ let visualBlock = await canvas().$$(
'.block-editor-block-list__layout .block-editor-block-list__block.rich-text'
);
expect( visualBlock ).toHaveLength( 1 );
@@ -31,7 +32,7 @@ describe( 'Editing modes (visual/HTML)', () => {
await clickMenuItem( 'Edit as HTML' );
// Wait for the block to be converted to HTML editing mode.
- const htmlBlock = await page.$$(
+ const htmlBlock = await canvas().$$(
'.block-editor-block-list__layout .block-editor-block-list__block .block-editor-block-list__block-html-textarea'
);
expect( htmlBlock ).toHaveLength( 1 );
@@ -41,7 +42,7 @@ describe( 'Editing modes (visual/HTML)', () => {
await clickMenuItem( 'Edit visually' );
// This block should be in "visual" mode by default.
- visualBlock = await page.$$(
+ visualBlock = await canvas().$$(
'.block-editor-block-list__layout .block-editor-block-list__block.rich-text'
);
expect( visualBlock ).toHaveLength( 1 );
@@ -66,7 +67,7 @@ describe( 'Editing modes (visual/HTML)', () => {
await clickMenuItem( 'Edit as HTML' );
// Make sure the paragraph content is rendered as expected.
- let htmlBlockContent = await page.$eval(
+ let htmlBlockContent = await canvas().$eval(
'.block-editor-block-list__layout .block-editor-block-list__block .block-editor-block-list__block-html-textarea',
( node ) => node.textContent
);
@@ -82,7 +83,7 @@ describe( 'Editing modes (visual/HTML)', () => {
);
// Make sure the HTML content updated.
- htmlBlockContent = await page.$eval(
+ htmlBlockContent = await canvas().$eval(
'.block-editor-block-list__layout .block-editor-block-list__block .block-editor-block-list__block-html-textarea',
( node ) => node.textContent
);
diff --git a/packages/e2e-tests/specs/editor/various/embedding.test.js b/packages/e2e-tests/specs/editor/various/embedding.test.js
index 170965215eceb..9b3d9304c982f 100644
--- a/packages/e2e-tests/specs/editor/various/embedding.test.js
+++ b/packages/e2e-tests/specs/editor/various/embedding.test.js
@@ -12,6 +12,7 @@ import {
insertBlock,
publishPost,
setUpResponseMocking,
+ canvas,
} from '@wordpress/e2e-test-utils';
const MOCK_EMBED_WORDPRESS_SUCCESS_RESPONSE = {
@@ -171,24 +172,24 @@ describe( 'Embedding content', () => {
it( 'should render embeds in the correct state', async () => {
// Valid embed. Should render valid figure element.
await insertEmbed( 'https://twitter.com/notnownikki' );
- await page.waitForSelector( 'figure.wp-block-embed' );
+ await canvas().waitForSelector( 'figure.wp-block-embed' );
// Valid provider; invalid content. Should render failed, edit state.
await insertEmbed( 'https://twitter.com/wooyaygutenberg123454312' );
- await page.waitForSelector(
+ await canvas().waitForSelector(
'input[value="https://twitter.com/wooyaygutenberg123454312"]'
);
// WordPress invalid content. Should render failed, edit state.
await insertEmbed( 'https://wordpress.org/gutenberg/handbook/' );
- await page.waitForSelector(
+ await canvas().waitForSelector(
'input[value="https://wordpress.org/gutenberg/handbook/"]'
);
// Provider whose oembed API has gone wrong. Should render failed, edit
// state.
await insertEmbed( 'https://twitter.com/thatbunty' );
- await page.waitForSelector(
+ await canvas().waitForSelector(
'input[value="https://twitter.com/thatbunty"]'
);
@@ -197,12 +198,12 @@ describe( 'Embedding content', () => {
await insertEmbed(
'https://wordpress.org/gutenberg/handbook/block-api/attributes/'
);
- await page.waitForSelector( 'figure.wp-block-embed' );
+ await canvas().waitForSelector( 'figure.wp-block-embed' );
// Video content. Should render valid figure element, and include the
// aspect ratio class.
await insertEmbed( 'https://www.youtube.com/watch?v=lXMskKTw3Bc' );
- await page.waitForSelector(
+ await canvas().waitForSelector(
'figure.wp-block-embed.is-type-video.wp-embed-aspect-16-9'
);
@@ -219,18 +220,18 @@ describe( 'Embedding content', () => {
// has styles applied which depend on resize observer, wait for the
// expected size class to settle before clicking, since otherwise a race
// condition could occur on the placeholder layout vs. click intent.
- await page.waitForSelector(
+ await canvas().waitForSelector(
'.components-placeholder.is-large .components-placeholder__error'
);
- await clickButton( 'Convert to link' );
+ await clickButton( 'Convert to link', canvas() );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should retry embeds that could not be embedded with trailing slashes, without the trailing slashes', async () => {
await insertEmbed( 'https://twitter.com/notnownikki/' );
// The twitter block should appear correctly.
- await page.waitForSelector( 'figure.wp-block-embed' );
+ await canvas().waitForSelector( 'figure.wp-block-embed' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
@@ -242,7 +243,7 @@ describe( 'Embedding content', () => {
// has styles applied which depend on resize observer, wait for the
// expected size class to settle before clicking, since otherwise a race
// condition could occur on the placeholder layout vs. click intent.
- await page.waitForSelector(
+ await canvas().waitForSelector(
'.components-placeholder.is-large .components-placeholder__error'
);
@@ -257,8 +258,8 @@ describe( 'Embedding content', () => {
),
},
] );
- await clickButton( 'Try again' );
- await page.waitForSelector( 'figure.wp-block-embed' );
+ await clickButton( 'Try again', canvas() );
+ await canvas().waitForSelector( 'figure.wp-block-embed' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
@@ -281,6 +282,6 @@ describe( 'Embedding content', () => {
await insertEmbed( postUrl );
// Check the block has become a WordPress block.
- await page.waitForSelector( 'figure.wp-block-embed' );
+ await canvas().waitForSelector( 'figure.wp-block-embed' );
} );
} );
diff --git a/packages/e2e-tests/specs/editor/various/invalid-block.test.js b/packages/e2e-tests/specs/editor/various/invalid-block.test.js
index 3313e819d752c..4be4e49c74be8 100644
--- a/packages/e2e-tests/specs/editor/various/invalid-block.test.js
+++ b/packages/e2e-tests/specs/editor/various/invalid-block.test.js
@@ -6,6 +6,7 @@ import {
createNewPost,
clickBlockAppender,
clickBlockToolbarButton,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'invalid blocks', () => {
@@ -24,7 +25,7 @@ describe( 'invalid blocks', () => {
await clickMenuItem( 'Edit as HTML' );
// Focus on the textarea and enter an invalid paragraph
- await page.click(
+ await canvas().click(
'.block-editor-block-list__layout .block-editor-block-list__block .block-editor-block-list__block-html-textarea'
);
await page.keyboard.type( 'invalid paragraph' );
@@ -35,7 +36,7 @@ describe( 'invalid blocks', () => {
expect( console ).toHaveWarned();
// Click on the 'three-dots' menu toggle
- await page.click(
+ await canvas().click(
'.block-editor-warning__actions button[aria-label="More options"]'
);
diff --git a/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js b/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js
index 2b092c9b46690..c6758c5a7dcd8 100644
--- a/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js
+++ b/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js
@@ -8,13 +8,24 @@ import {
clickBlockAppender,
getEditedPostContent,
showBlockToolbar,
+ canvas,
+ clickButton,
} from '@wordpress/e2e-test-utils';
async function getActiveLabel() {
return await page.evaluate( () => {
+ function getActiveElement( { activeElement } ) {
+ if ( activeElement.nodeName === 'IFRAME' ) {
+ return getActiveElement( activeElement.contentDocument );
+ }
+ return activeElement;
+ }
+
+ const activeElement = getActiveElement( document );
+
return (
- document.activeElement.getAttribute( 'aria-label' ) ||
- document.activeElement.innerHTML
+ activeElement.getAttribute( 'aria-label' ) ||
+ activeElement.innerHTML
);
} );
}
@@ -23,6 +34,7 @@ const navigateToContentEditorTop = async () => {
// Use 'Ctrl+`' to return to the top of the editor
await pressKeyWithModifier( 'ctrl', '`' );
await pressKeyWithModifier( 'ctrl', '`' );
+ await expect( await getActiveLabel() ).toBe( 'Editor content' );
};
const tabThroughParagraphBlock = async ( paragraphText ) => {
@@ -34,7 +46,7 @@ const tabThroughParagraphBlock = async ( paragraphText ) => {
await page.keyboard.press( 'Tab' );
await expect( await getActiveLabel() ).toBe( 'Paragraph block' );
await expect(
- await page.evaluate( () => document.activeElement.innerHTML )
+ await canvas().evaluate( () => document.activeElement.innerHTML )
).toBe( paragraphText );
await page.keyboard.press( 'Tab' );
@@ -109,13 +121,18 @@ describe( 'Order of block keyboard navigation', () => {
}
// Clear the selected block.
- const paragraph = await page.$( '[data-type="core/paragraph"]' );
- const box = await paragraph.boundingBox();
- await page.mouse.click( box.x - 1, box.y );
+ await clickButton( 'Document' );
+
+ // Put focus in front of the block list.
+ await page.evaluate( () => {
+ document
+ .querySelector( '.interface-interface-skeleton__content' )
+ .focus();
+ } );
await page.keyboard.press( 'Tab' );
await expect(
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
return document.activeElement.placeholder;
} )
).toBe( 'Add title' );
@@ -144,9 +161,7 @@ describe( 'Order of block keyboard navigation', () => {
}
// Clear the selected block.
- const paragraph = await page.$( '[data-type="core/paragraph"]' );
- const box = await paragraph.boundingBox();
- await page.mouse.click( box.x - 1, box.y );
+ await clickButton( 'Document' );
// Put focus behind the block list.
await page.evaluate( () => {
@@ -167,10 +182,13 @@ describe( 'Order of block keyboard navigation', () => {
await pressKeyWithModifier( 'shift', 'Tab' );
await expect(
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
return document.activeElement.placeholder;
} )
).toBe( 'Add title' );
+
+ await pressKeyWithModifier( 'shift', 'Tab' );
+ await expect( await getActiveLabel() ).toBe( 'Options' );
} );
it( 'should navigate correctly with multi selection', async () => {
diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js
index 21c50094a0d1f..481e4dbecb567 100644
--- a/packages/e2e-tests/specs/editor/various/links.test.js
+++ b/packages/e2e-tests/specs/editor/various/links.test.js
@@ -8,6 +8,7 @@ import {
createNewPost,
pressKeyWithModifier,
showBlockToolbar,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Links', () => {
@@ -49,7 +50,7 @@ describe( 'Links', () => {
await page.keyboard.press( 'Enter' );
- const actualText = await page.evaluate(
+ const actualText = await canvas().evaluate(
() =>
document.querySelector( '.block-editor-rich-text__editable a' )
.textContent
@@ -182,7 +183,7 @@ describe( 'Links', () => {
await page.keyboard.type( 'https://wordpress.org/gutenberg' );
// Click somewhere else - it doesn't really matter where
- await page.click( '.editor-post-title' );
+ await canvas().click( '.editor-post-title' );
} );
const createAndReselectLink = async () => {
@@ -312,7 +313,7 @@ describe( 'Links', () => {
const createPostWithTitle = async ( titleText ) => {
await createNewPost();
- await page.type( '.editor-post-title__input', titleText );
+ await canvas().type( '.editor-post-title__input', titleText );
await page.click( '.editor-post-publish-panel__toggle' );
// Disable reason: Wait for the animation to complete, since otherwise the
@@ -510,7 +511,7 @@ describe( 'Links', () => {
await page.keyboard.press( 'Enter' );
// Wait for Gutenberg to finish the job.
- await page.waitForXPath(
+ await canvas().waitForXPath(
'//a[contains(@href,"w.org") and @target="_blank"]'
);
@@ -551,7 +552,7 @@ describe( 'Links', () => {
await page.keyboard.press( 'Space' );
// Wait for Gutenberg to finish the job.
- await page.waitForXPath(
+ await canvas().waitForXPath(
'//a[contains(@href,"wordpress.org") and not(@target)]'
);
diff --git a/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js b/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js
index bfa098f7f4240..9bb642a0cfbf0 100644
--- a/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js
+++ b/packages/e2e-tests/specs/editor/various/multi-block-selection.test.js
@@ -9,10 +9,11 @@ import {
getEditedPostContent,
clickBlockToolbarButton,
clickButton,
+ canvas,
} from '@wordpress/e2e-test-utils';
async function getSelectedFlatIndices() {
- return await page.evaluate( () => {
+ return await canvas().evaluate( () => {
const indices = [];
let single;
@@ -38,7 +39,7 @@ async function getSelectedFlatIndices() {
async function testNativeSelection() {
// Wait for the selection to update.
await page.evaluate( () => new Promise( window.requestAnimationFrame ) );
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
const selection = window.getSelection();
const elements = Array.from(
document.querySelectorAll( '.is-multi-selected' )
@@ -263,7 +264,7 @@ describe( 'Multi-block selection', () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.down( 'Shift' );
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
await page.keyboard.up( 'Shift' );
await testNativeSelection();
@@ -277,20 +278,21 @@ describe( 'Multi-block selection', () => {
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowUp' );
- const [ coord1, coord2 ] = await page.evaluate( () => {
+ const [ coord1, coord2 ] = await canvas().evaluate( () => {
const elements = Array.from(
document.querySelectorAll( '[data-type="core/paragraph"]' )
);
const rect1 = elements[ 0 ].getBoundingClientRect();
const rect2 = elements[ 1 ].getBoundingClientRect();
+ const winRect = window.frameElement.getBoundingClientRect();
return [
{
- x: rect1.x + rect1.width / 2,
- y: rect1.y + rect1.height / 2,
+ x: winRect.x + rect1.x + rect1.width / 2,
+ y: winRect.y + rect1.y + rect1.height / 2,
},
{
- x: rect2.x + rect2.width / 2,
- y: rect2.y + rect2.height / 2,
+ x: winRect.x + rect2.x + rect2.width / 2,
+ y: winRect.y + rect2.y + rect2.height / 2,
},
];
} );
@@ -314,7 +316,7 @@ describe( 'Multi-block selection', () => {
);
await page.keyboard.press( 'Enter' );
- const groupAppender = await page.waitForSelector(
+ const groupAppender = await canvas().waitForSelector(
'.block-editor-button-block-appender'
);
await groupAppender.click();
@@ -326,21 +328,22 @@ describe( 'Multi-block selection', () => {
await page.keyboard.type( '2' );
- const [ coord1, coord2 ] = await page.evaluate( () => {
+ const [ coord1, coord2 ] = await canvas().evaluate( () => {
const elements = Array.from(
document.querySelectorAll( '[data-type="core/paragraph"]' )
);
+ elements[ 0 ].scrollIntoView();
const rect1 = elements[ 0 ].getBoundingClientRect();
const rect2 = elements[ 1 ].getBoundingClientRect();
-
+ const winRect = window.frameElement.getBoundingClientRect();
return [
{
- x: rect1.x + rect1.width / 2,
- y: rect1.y + rect1.height / 2,
+ x: winRect.x + rect1.x + rect1.width / 2,
+ y: winRect.y + rect1.y + rect1.height / 2,
},
{
- x: rect2.x + rect2.width / 2,
- y: rect2.y + rect2.height / 2,
+ x: winRect.x + rect2.x + rect2.width / 2,
+ y: winRect.y + rect2.y + rect2.height / 2,
},
];
} );
@@ -396,7 +399,7 @@ describe( 'Multi-block selection', () => {
await page.keyboard.type( '2' );
await page.keyboard.press( 'ArrowLeft' );
- const [ coord1, coord2 ] = await page.evaluate( () => {
+ const [ coord1, coord2 ] = await canvas().evaluate( () => {
const selection = window.getSelection();
if ( ! selection.rangeCount ) {
@@ -409,16 +412,17 @@ describe( 'Multi-block selection', () => {
'[data-type="core/paragraph"]'
);
const rect2 = element.getBoundingClientRect();
+ const winRect = window.frameElement.getBoundingClientRect();
return [
{
- x: rect1.x,
- y: rect1.y + rect1.height / 2,
+ x: winRect.x + rect1.x,
+ y: winRect.y + rect1.y + rect1.height / 2,
},
{
// Move a bit outside the paragraph.
- x: rect2.x - 10,
- y: rect2.y + rect2.height / 2,
+ x: winRect.x + rect2.x - 10,
+ y: winRect.y + rect2.y + rect2.height / 2,
},
];
} );
@@ -447,20 +451,21 @@ describe( 'Multi-block selection', () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '3' );
- const [ coord1, coord2 ] = await page.evaluate( () => {
+ const [ coord1, coord2 ] = await canvas().evaluate( () => {
const elements = Array.from(
document.querySelectorAll( '[data-type="core/paragraph"]' )
);
const rect1 = elements[ 2 ].getBoundingClientRect();
const rect2 = elements[ 1 ].getBoundingClientRect();
+ const winRect = window.frameElement.getBoundingClientRect();
return [
{
- x: rect1.x + rect1.width / 2,
- y: rect1.y + rect1.height / 2,
+ x: winRect.x + rect1.x + rect1.width / 2,
+ y: winRect.y + rect1.y + rect1.height / 2,
},
{
- x: rect2.x + rect2.width / 2,
- y: rect2.y + rect2.height / 2,
+ x: winRect.x + rect2.x + rect2.width / 2,
+ y: winRect.y + rect2.y + rect2.height / 2,
},
];
} );
@@ -491,14 +496,15 @@ describe( 'Multi-block selection', () => {
await testNativeSelection();
expect( await getSelectedFlatIndices() ).toEqual( [ 1, 2 ] );
- const coord = await page.evaluate( () => {
+ const coord = await canvas().evaluate( () => {
const element = document.querySelector(
'[data-type="core/paragraph"]'
);
const rect = element.getBoundingClientRect();
+ const winRect = window.frameElement.getBoundingClientRect();
return {
- x: rect.x - 1,
- y: rect.y + rect.height / 2,
+ x: winRect.x + rect.x - 1,
+ y: winRect.y + rect.y + rect.height / 2,
};
} );
diff --git a/packages/e2e-tests/specs/editor/various/navigable-toolbar.test.js b/packages/e2e-tests/specs/editor/various/navigable-toolbar.test.js
index e108828c31e63..d50807177427e 100644
--- a/packages/e2e-tests/specs/editor/various/navigable-toolbar.test.js
+++ b/packages/e2e-tests/specs/editor/various/navigable-toolbar.test.js
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
-import { createNewPost, pressKeyWithModifier } from '@wordpress/e2e-test-utils';
+import {
+ createNewPost,
+ pressKeyWithModifier,
+ canvas,
+} from '@wordpress/e2e-test-utils';
describe.each( [
[ 'unified', true ],
@@ -49,32 +53,21 @@ describe.each( [
if ( ! isUnifiedToolbar ) {
it( 'should not scroll page', async () => {
- while (
- await page.evaluate( () => {
- const scrollable = wp.dom.getScrollContainer(
- document.activeElement
- );
- return ! scrollable || scrollable.scrollTop === 0;
- } )
- ) {
+ while ( await canvas().evaluate( () => window.scrollY === 0 ) ) {
await page.keyboard.press( 'Enter' );
}
await page.keyboard.type( 'a' );
- const scrollTopBefore = await page.evaluate(
- () =>
- wp.dom.getScrollContainer( document.activeElement )
- .scrollTop
+ const scrollTopBefore = await canvas().evaluate(
+ () => window.scrollY
);
await pressKeyWithModifier( 'alt', 'F10' );
expect( await isInBlockToolbar() ).toBe( true );
- const scrollTopAfter = await page.evaluate(
- () =>
- wp.dom.getScrollContainer( document.activeElement )
- .scrollTop
+ const scrollTopAfter = await canvas().evaluate(
+ () => window.scrollY
);
expect( scrollTopBefore ).toBe( scrollTopAfter );
diff --git a/packages/e2e-tests/specs/editor/various/new-post-default-content.test.js b/packages/e2e-tests/specs/editor/various/new-post-default-content.test.js
index 4c917f265eaf3..857f1b7a5dfd6 100644
--- a/packages/e2e-tests/specs/editor/various/new-post-default-content.test.js
+++ b/packages/e2e-tests/specs/editor/various/new-post-default-content.test.js
@@ -8,6 +8,8 @@ import {
findSidebarPanelToggleButtonWithTitle,
getEditedPostContent,
openDocumentSettingsSidebar,
+ canvas,
+ clickButton,
} from '@wordpress/e2e-test-utils';
describe( 'new editor filtered state', () => {
@@ -25,7 +27,7 @@ describe( 'new editor filtered state', () => {
it( 'should respect default content', async () => {
// get the values that should have their defaults changed.
- const title = await page.$eval(
+ const title = await canvas().$eval(
'.editor-post-title__input',
( element ) => element.innerHTML
);
@@ -33,6 +35,7 @@ describe( 'new editor filtered state', () => {
// open the sidebar, we want to see the excerpt.
await openDocumentSettingsSidebar();
+ await clickButton( 'Post' );
const excerptButton = await findSidebarPanelToggleButtonWithTitle(
'Excerpt'
);
diff --git a/packages/e2e-tests/specs/editor/various/new-post.test.js b/packages/e2e-tests/specs/editor/various/new-post.test.js
index e8baff2d573fb..a24fc390d21b4 100644
--- a/packages/e2e-tests/specs/editor/various/new-post.test.js
+++ b/packages/e2e-tests/specs/editor/various/new-post.test.js
@@ -5,6 +5,7 @@ import {
activatePlugin,
createNewPost,
deactivatePlugin,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'new editor state', () => {
@@ -25,7 +26,7 @@ describe( 'new editor state', () => {
expect.stringContaining( 'post-new.php' )
);
// Should display the blank title.
- const title = await page.$( '[placeholder="Add title"]' );
+ const title = await canvas().$( '[placeholder="Add title"]' );
expect( title ).not.toBeNull();
expect( title.innerHTML ).toBeFalsy();
// Should display the Preview button.
@@ -51,10 +52,10 @@ describe( 'new editor state', () => {
} );
it( 'should focus the title if the title is empty', async () => {
- const activeElementClasses = await page.evaluate( () => {
+ const activeElementClasses = await canvas().evaluate( () => {
return Object.values( document.activeElement.classList );
} );
- const activeElementTagName = await page.evaluate( () => {
+ const activeElementTagName = await canvas().evaluate( () => {
return document.activeElement.tagName.toLowerCase();
} );
@@ -64,7 +65,7 @@ describe( 'new editor state', () => {
it( 'should not focus the title if the title exists', async () => {
// Enter a title for this post.
- await page.type( '.editor-post-title__input', 'Here is the title' );
+ await canvas().type( '.editor-post-title__input', 'Here is the title' );
// Save the post as a draft.
await page.click( '.editor-post-save-draft' );
await page.waitForSelector( '.editor-post-saved-state.is-saved' );
@@ -72,10 +73,10 @@ describe( 'new editor state', () => {
await page.reload();
await page.waitForSelector( '.edit-post-layout' );
- const activeElementClasses = await page.evaluate( () => {
+ const activeElementClasses = await canvas().evaluate( () => {
return Object.values( document.activeElement.classList );
} );
- const activeElementTagName = await page.evaluate( () => {
+ const activeElementTagName = await canvas().evaluate( () => {
return document.activeElement.tagName.toLowerCase();
} );
diff --git a/packages/e2e-tests/specs/editor/various/post-visibility.test.js b/packages/e2e-tests/specs/editor/various/post-visibility.test.js
index 6844b9bd97345..84ef7ce75af32 100644
--- a/packages/e2e-tests/specs/editor/various/post-visibility.test.js
+++ b/packages/e2e-tests/specs/editor/various/post-visibility.test.js
@@ -5,6 +5,7 @@ import {
setBrowserViewport,
createNewPost,
openDocumentSettingsSidebar,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Post visibility', () => {
@@ -40,7 +41,7 @@ describe( 'Post visibility', () => {
await createNewPost();
// Enter a title for this post.
- await page.type( '.editor-post-title__input', 'Title' );
+ await canvas().type( '.editor-post-title__input', 'Title' );
await openDocumentSettingsSidebar();
@@ -61,7 +62,7 @@ describe( 'Post visibility', () => {
await privateLabel.click();
// Enter a title for this post.
- await page.type( '.editor-post-title__input', ' Changed' );
+ await canvas().type( '.editor-post-title__input', ' Changed' );
// Wait for the button to be clickable before attempting to click.
// This could cause errors when we try to click before changes are registered.
diff --git a/packages/e2e-tests/specs/editor/various/preview.test.js b/packages/e2e-tests/specs/editor/various/preview.test.js
index d0996211a512c..d2761365c30d3 100644
--- a/packages/e2e-tests/specs/editor/various/preview.test.js
+++ b/packages/e2e-tests/specs/editor/various/preview.test.js
@@ -11,6 +11,7 @@ import {
publishPost,
saveDraft,
openPreviewPage,
+ canvas,
} from '@wordpress/e2e-test-utils';
/** @typedef {import('puppeteer').Page} Page */
@@ -95,7 +96,7 @@ describe( 'Preview', () => {
);
expect( isPreviewDisabled ).toBe( true );
- await editorPage.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
const previewPage = await openPreviewPage( editorPage );
await previewPage.waitForSelector( '.entry-title' );
@@ -123,7 +124,7 @@ describe( 'Preview', () => {
// Return to editor to change title.
await editorPage.bringToFront();
- await editorPage.type( '.editor-post-title__input', '!' );
+ await canvas().type( '.editor-post-title__input', '!' );
await waitForPreviewDropdownOpen( editorPage );
await waitForPreviewNavigation( previewPage );
@@ -150,7 +151,7 @@ describe( 'Preview', () => {
// Return to editor to change title.
await editorPage.bringToFront();
- await editorPage.type( '.editor-post-title__input', ' And more.' );
+ await canvas().type( '.editor-post-title__input', ' And more.' );
await waitForPreviewDropdownOpen( editorPage );
await waitForPreviewNavigation( previewPage );
@@ -189,7 +190,7 @@ describe( 'Preview', () => {
const editorPage = page;
// Type aaaaa in the title filed.
- await editorPage.type( '.editor-post-title__input', 'aaaaa' );
+ await canvas().type( '.editor-post-title__input', 'aaaaa' );
await editorPage.keyboard.press( 'Tab' );
// Save the post as a draft.
@@ -211,7 +212,7 @@ describe( 'Preview', () => {
await editorPage.bringToFront();
// Append bbbbb to the title, and tab away from the title so blur event is triggered.
- await editorPage.type( '.editor-post-title__input', 'bbbbb' );
+ await canvas().type( '.editor-post-title__input', 'bbbbb' );
await editorPage.keyboard.press( 'Tab' );
// Save draft and open the preview page right after.
@@ -246,9 +247,9 @@ describe( 'Preview with Custom Fields enabled', () => {
const editorPage = page;
// Make sure input is mounted in editor before adding content.
- await editorPage.waitForSelector( '.editor-post-title__input' );
+ await canvas().waitForSelector( '.editor-post-title__input' );
// Add an initial title and content.
- await editorPage.type( '.editor-post-title__input', 'title 1' );
+ await canvas().type( '.editor-post-title__input', 'title 1' );
await editorPage.keyboard.press( 'Tab' );
await editorPage.keyboard.type( 'content 1' );
@@ -275,7 +276,7 @@ describe( 'Preview with Custom Fields enabled', () => {
// Return to editor and modify the title and content.
await editorPage.bringToFront();
- await editorPage.click( '.editor-post-title__input' );
+ await canvas().click( '.editor-post-title__input' );
await editorPage.keyboard.press( 'End' );
await editorPage.keyboard.press( 'Backspace' );
await editorPage.keyboard.type( '2' );
@@ -318,7 +319,7 @@ describe( 'Preview with private custom post type', () => {
await createNewPost( { postType: 'not_public' } );
// Type in the title filed.
- await page.type( '.editor-post-title__input', 'aaaaa' );
+ await canvas().type( '.editor-post-title__input', 'aaaaa' );
await page.keyboard.press( 'Tab' );
// Open the preview menu.
diff --git a/packages/e2e-tests/specs/editor/various/publish-button.test.js b/packages/e2e-tests/specs/editor/various/publish-button.test.js
index d9396b7f48c38..26e6cdb0532fc 100644
--- a/packages/e2e-tests/specs/editor/various/publish-button.test.js
+++ b/packages/e2e-tests/specs/editor/various/publish-button.test.js
@@ -6,6 +6,7 @@ import {
disablePrePublishChecks,
enablePrePublishChecks,
createNewPost,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'PostPublishButton', () => {
@@ -32,7 +33,7 @@ describe( 'PostPublishButton', () => {
} );
it( 'should be disabled when post is being saved', async () => {
- await page.type( '.editor-post-title__input', 'E2E Test Post' ); // Make it saveable
+ await canvas().type( '.editor-post-title__input', 'E2E Test Post' ); // Make it saveable
expect(
await page.$( '.editor-post-publish-button[aria-disabled="true"]' )
).toBeNull();
@@ -44,7 +45,7 @@ describe( 'PostPublishButton', () => {
} );
it( 'should be disabled when metabox is being saved', async () => {
- await page.type( '.editor-post-title__input', 'E2E Test Post' ); // Make it saveable
+ await canvas().type( '.editor-post-title__input', 'E2E Test Post' ); // Make it saveable
expect(
await page.$( '.editor-post-publish-button[aria-disabled="true"]' )
).toBeNull();
diff --git a/packages/e2e-tests/specs/editor/various/publish-panel.test.js b/packages/e2e-tests/specs/editor/various/publish-panel.test.js
index 3a6aefd8f6687..333f2f1c2a8b3 100644
--- a/packages/e2e-tests/specs/editor/various/publish-panel.test.js
+++ b/packages/e2e-tests/specs/editor/various/publish-panel.test.js
@@ -9,6 +9,7 @@ import {
openPublishPanel,
pressKeyWithModifier,
publishPost,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'PostPublishPanel', () => {
@@ -28,7 +29,7 @@ describe( 'PostPublishPanel', () => {
} );
it( 'PrePublish: publish button should have the focus', async () => {
- await page.type( '.editor-post-title__input', 'E2E Test Post' );
+ await canvas().type( '.editor-post-title__input', 'E2E Test Post' );
await openPublishPanel();
const focusedElementClassList = await page.$eval(
@@ -44,7 +45,7 @@ describe( 'PostPublishPanel', () => {
it( 'PostPublish: post link should have the focus', async () => {
const postTitle = 'E2E Test Post';
- await page.type( '.editor-post-title__input', postTitle );
+ await canvas().type( '.editor-post-title__input', postTitle );
await publishPost();
const focusedElementTag = await page.$eval(
@@ -64,7 +65,7 @@ describe( 'PostPublishPanel', () => {
} );
it( 'should retain focus within the panel', async () => {
- await page.type( '.editor-post-title__input', 'E2E Test Post' );
+ await canvas().type( '.editor-post-title__input', 'E2E Test Post' );
await openPublishPanel();
await pressKeyWithModifier( 'shift', 'Tab' );
diff --git a/packages/e2e-tests/specs/editor/various/publishing.test.js b/packages/e2e-tests/specs/editor/various/publishing.test.js
index 745008a0a15f1..b86a06c50118b 100644
--- a/packages/e2e-tests/specs/editor/various/publishing.test.js
+++ b/packages/e2e-tests/specs/editor/various/publishing.test.js
@@ -9,6 +9,7 @@ import {
disablePrePublishChecks,
arePrePublishChecksEnabled,
setBrowserViewport,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Publishing', () => {
@@ -30,7 +31,7 @@ describe( 'Publishing', () => {
} );
it( `should publish the ${ postType } and close the panel once we start editing again.`, async () => {
- await page.type( '.editor-post-title__input', 'E2E Test Post' );
+ await canvas().type( '.editor-post-title__input', 'E2E Test Post' );
await publishPost();
@@ -40,7 +41,7 @@ describe( 'Publishing', () => {
).not.toBeNull();
// Start editing again.
- await page.type( '.editor-post-title__input', ' (Updated)' );
+ await canvas().type( '.editor-post-title__input', ' (Updated)' );
// The post-publishing panel is not visible anymore.
expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull();
@@ -67,7 +68,10 @@ describe( 'Publishing', () => {
} );
it( `should publish the ${ postType } without opening the post-publish sidebar.`, async () => {
- await page.type( '.editor-post-title__input', 'E2E Test Post' );
+ await canvas().type(
+ '.editor-post-title__input',
+ 'E2E Test Post'
+ );
// The "Publish" button should be shown instead of the "Publish..." toggle
expect(
diff --git a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js
index 0d7c6d8baf236..e438a722ce71a 100644
--- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js
+++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js
@@ -12,6 +12,7 @@ import {
trashAllPosts,
visitAdminPage,
toggleGlobalBlockInserter,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'Reusable blocks', () => {
@@ -44,7 +45,7 @@ describe( 'Reusable blocks', () => {
await page.waitForXPath(
'//*[contains(@class, "components-snackbar")]/*[text()="Block created."]'
);
- await page.waitForXPath(
+ await canvas().waitForXPath(
'//*[@class="block-library-block__reusable-block-container"]'
);
@@ -55,24 +56,20 @@ describe( 'Reusable blocks', () => {
await page.keyboard.type( 'Greeting block' );
// Save the reusable block
- const [ saveButton ] = await page.$x( '//button[text()="Save"]' );
+ const [ saveButton ] = await canvas().$x( '//button[text()="Save"]' );
await saveButton.click();
// Wait for saving to finish
- await page.waitForXPath( '//button[text()="Edit"]' );
+ await canvas().waitForXPath( '//button[text()="Edit"]' );
// Check that we have a reusable block on the page
- const block = await page.$(
+ const block = await canvas().$(
'.block-editor-block-list__block[data-type="core/block"]'
);
expect( block ).not.toBeNull();
// Check that its title is displayed
- const title = await page.$eval(
- '.reusable-block-edit-panel__info',
- ( element ) => element.innerText
- );
- expect( title ).toBe( 'Greeting block' );
+ await canvas().waitForXPath( '//b[text()="Greeting block"]' );
} );
it( 'can be created with no title', async () => {
@@ -87,29 +84,25 @@ describe( 'Reusable blocks', () => {
await page.waitForXPath(
'//*[contains(@class, "components-snackbar")]/*[text()="Block created."]'
);
- await page.waitForXPath(
+ await canvas().waitForXPath(
'//*[@class="block-library-block__reusable-block-container"]'
);
// Save the reusable block
- const [ saveButton ] = await page.$x( '//button[text()="Save"]' );
+ const [ saveButton ] = await canvas().$x( '//button[text()="Save"]' );
await saveButton.click();
// Wait for saving to finish
- await page.waitForXPath( '//button[text()="Edit"]' );
+ await canvas().waitForXPath( '//button[text()="Edit"]' );
// Check that we have a reusable block on the page
- const block = await page.$(
+ const block = await canvas().$(
'.block-editor-block-list__block[data-type="core/block"]'
);
expect( block ).not.toBeNull();
// Check that it is untitled
- const title = await page.$eval(
- '.reusable-block-edit-panel__info',
- ( element ) => element.innerText
- );
- expect( title ).toBe( 'Untitled Reusable Block' );
+ await canvas().waitForXPath( '//b[text()="Untitled Reusable Block"]' );
} );
it( 'can be inserted and edited', async () => {
@@ -117,9 +110,10 @@ describe( 'Reusable blocks', () => {
await insertReusableBlock( 'Greeting block' );
// Put the reusable block in edit mode
- const editButton = await page.waitForXPath(
+ const editButton = await canvas().waitForXPath(
'//button[text()="Edit" and not(@disabled)]'
);
+
await editButton.click();
// Change the block's title
@@ -137,27 +131,23 @@ describe( 'Reusable blocks', () => {
await page.keyboard.type( 'Oh! ' );
// Save the reusable block
- const [ saveButton ] = await page.$x( '//button[text()="Save"]' );
+ const [ saveButton ] = await canvas().$x( '//button[text()="Save"]' );
await saveButton.click();
// Wait for saving to finish
- await page.waitForXPath( '//button[text()="Edit"]' );
+ await canvas().waitForXPath( '//button[text()="Edit"]' );
// Check that we have a reusable block on the page
- const block = await page.$(
+ const block = await canvas().$(
'.block-editor-block-list__block[data-type="core/block"]'
);
expect( block ).not.toBeNull();
// Check that its title is displayed
- const title = await page.$eval(
- '.reusable-block-edit-panel__info',
- ( element ) => element.innerText
- );
- expect( title ).toBe( 'Surprised greeting block' );
+ await canvas().waitForXPath( '//b[text()="Surprised greeting block"]' );
// Check that its content is up to date
- const text = await page.$eval(
+ const text = await canvas().$eval(
'.block-editor-block-list__block[data-type="core/block"] p',
( element ) => element.innerText
);
@@ -177,7 +167,7 @@ describe( 'Reusable blocks', () => {
await page.waitForXPath(
'//*[contains(@class, "components-snackbar")]/*[text()="Block created."]'
);
- await page.waitForXPath(
+ await canvas().waitForXPath(
'//*[@class="block-library-block__reusable-block-container"]'
);
@@ -188,7 +178,7 @@ describe( 'Reusable blocks', () => {
await page.keyboard.type( 'Awesome block' );
// Save the reusable block
- const [ saveButton ] = await page.$x( '//button[text()="Save"]' );
+ const [ saveButton ] = await canvas().$x( '//button[text()="Save"]' );
await saveButton.click();
// Step 2. Create new post.
@@ -200,17 +190,13 @@ describe( 'Reusable blocks', () => {
await insertReusableBlock( 'Awesome block' );
// Check that we have a reusable block on the page
- const block = await page.$(
+ const block = await canvas().$(
'.block-editor-block-list__block[data-type="core/block"]'
);
expect( block ).not.toBeNull();
// Check that its title is displayed
- const title = await page.$eval(
- '.reusable-block-edit-panel__info',
- ( element ) => element.innerText
- );
- expect( title ).toBe( 'Awesome block' );
+ await canvas().waitForXPath( '//b[text()="Awesome block"]' );
} );
it( 'can be converted to a regular block', async () => {
@@ -221,13 +207,13 @@ describe( 'Reusable blocks', () => {
await clickBlockToolbarButton( 'Convert to regular blocks', 'content' );
// Check that we have a paragraph block on the page
- const block = await page.$(
+ const block = await canvas().$(
'.block-editor-block-list__block[data-type="core/paragraph"]'
);
expect( block ).not.toBeNull();
// Check that its content is up to date
- const text = await page.$eval(
+ const text = await canvas().$eval(
'.block-editor-block-list__block[data-type="core/paragraph"]',
( element ) => element.innerText
);
@@ -255,7 +241,7 @@ describe( 'Reusable blocks', () => {
await page.waitForXPath(
'//*[contains(@class, "components-snackbar")]/*[text()="Block created."]'
);
- await page.waitForXPath(
+ await canvas().waitForXPath(
'//*[@class="block-library-block__reusable-block-container"]'
);
@@ -266,24 +252,22 @@ describe( 'Reusable blocks', () => {
await page.keyboard.type( 'Multi-selection reusable block' );
// Save the reusable block
- const [ saveButton ] = await page.$x( '//button[text()="Save"]' );
+ const [ saveButton ] = await canvas().$x( '//button[text()="Save"]' );
await saveButton.click();
// Wait for saving to finish
- await page.waitForXPath( '//button[text()="Edit"]' );
+ await canvas().waitForXPath( '//button[text()="Edit"]' );
// Check that we have a reusable block on the page
- const block = await page.$(
+ const block = await canvas().$(
'.block-editor-block-list__block[data-type="core/block"]'
);
expect( block ).not.toBeNull();
// Check that its title is displayed
- const title = await page.$eval(
- '.reusable-block-edit-panel__info',
- ( element ) => element.innerText
+ await canvas().waitForXPath(
+ '//b[text()="Multi-selection reusable block"]'
);
- expect( title ).toBe( 'Multi-selection reusable block' );
} );
it( 'multi-selection reusable block can be converted back to regular blocks', async () => {
@@ -309,10 +293,12 @@ describe( 'Reusable blocks', () => {
await page.waitForNavigation();
+ await page.waitForSelector( 'iframe[title="Editor canvas"]' );
+
// Click the block to give it focus
const blockSelector = 'p[data-title="Paragraph"]';
- await page.waitForSelector( blockSelector );
- await page.click( blockSelector );
+ await canvas().waitForSelector( blockSelector );
+ await canvas().click( blockSelector );
// Delete the block, leaving the reusable block empty
await clickBlockToolbarButton( 'More options' );
diff --git a/packages/e2e-tests/specs/editor/various/rich-text.test.js b/packages/e2e-tests/specs/editor/various/rich-text.test.js
index 17e064b7c5852..eda4c58d9b700 100644
--- a/packages/e2e-tests/specs/editor/various/rich-text.test.js
+++ b/packages/e2e-tests/specs/editor/various/rich-text.test.js
@@ -8,6 +8,7 @@ import {
clickBlockAppender,
pressKeyWithModifier,
showBlockToolbar,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'RichText', () => {
@@ -73,7 +74,7 @@ describe( 'RichText', () => {
await pressKeyWithModifier( 'shift', 'ArrowLeft' );
await pressKeyWithModifier( 'primary', 'b' );
- const count = await page.evaluate(
+ const count = await canvas().evaluate(
() =>
document.querySelectorAll( '*[data-rich-text-format-boundary]' )
.length
@@ -155,7 +156,7 @@ describe( 'RichText', () => {
await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( '3' );
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
let called;
const { body } = document;
const config = {
@@ -215,7 +216,7 @@ describe( 'RichText', () => {
await page.keyboard.type( '4' );
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
// The selection change event should be called once. If there's only
// one item in `window.unsubscribes`, it means that only one
// function is present to disconnect the `mutationObserver`.
@@ -256,7 +257,7 @@ describe( 'RichText', () => {
await page.keyboard.press( 'Enter' );
// Wait for rich text editor to load.
- await page.waitForSelector( '.block-editor-rich-text__editable' );
+ await canvas().waitForSelector( '.block-editor-rich-text__editable' );
await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( '12' );
@@ -288,7 +289,14 @@ describe( 'RichText', () => {
// Simulate moving focus to a different app, then moving focus back,
// without selection being changed.
await page.evaluate( () => {
- const activeElement = document.activeElement;
+ function getActiveElement( { activeElement } ) {
+ if ( activeElement.nodeName === 'IFRAME' ) {
+ return getActiveElement( activeElement.contentDocument );
+ }
+ return activeElement;
+ }
+
+ const activeElement = getActiveElement( document );
activeElement.blur();
activeElement.focus();
} );
diff --git a/packages/e2e-tests/specs/editor/various/rtl.test.js b/packages/e2e-tests/specs/editor/various/rtl.test.js
index 67f66ee77cc63..8667a65384127 100644
--- a/packages/e2e-tests/specs/editor/various/rtl.test.js
+++ b/packages/e2e-tests/specs/editor/various/rtl.test.js
@@ -5,6 +5,7 @@ import {
createNewPost,
getEditedPostContent,
pressKeyWithModifier,
+ canvas,
} from '@wordpress/e2e-test-utils';
// Avoid using three, as it looks too much like two with some fonts.
@@ -15,7 +16,7 @@ const ARABIC_TWO = '٢';
describe( 'RTL', () => {
beforeEach( async () => {
await createNewPost();
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
document.querySelector( '.is-root-container' ).dir = 'rtl';
} );
} );
@@ -102,7 +103,7 @@ describe( 'RTL', () => {
await page.keyboard.press( 'Enter' );
// Wait for rich text editor to load.
- await page.waitForSelector( '.block-editor-rich-text__editable' );
+ await canvas().waitForSelector( '.block-editor-rich-text__editable' );
await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( ARABIC_ONE );
diff --git a/packages/e2e-tests/specs/editor/various/sidebar-permalink-panel.test.js b/packages/e2e-tests/specs/editor/various/sidebar-permalink-panel.test.js
index 35b51001788cd..075325966bce5 100644
--- a/packages/e2e-tests/specs/editor/various/sidebar-permalink-panel.test.js
+++ b/packages/e2e-tests/specs/editor/various/sidebar-permalink-panel.test.js
@@ -7,6 +7,7 @@ import {
deactivatePlugin,
findSidebarPanelWithTitle,
publishPost,
+ canvas,
} from '@wordpress/e2e-test-utils';
const permalinkPanelXPath = `//div[contains(@class, "edit-post-sidebar")]//button[contains(@class, "components-panel__body-toggle") and contains(text(),"Permalink")]`;
@@ -38,7 +39,7 @@ describe( 'Sidebar Permalink Panel', () => {
await page.keyboard.type( 'aaaaa' );
await publishPost();
// Start editing again.
- await page.type( '.editor-post-title__input', ' (Updated)' );
+ await canvas().type( '.editor-post-title__input', ' (Updated)' );
expect( await page.$x( permalinkPanelXPath ) ).toEqual( [] );
} );
@@ -47,7 +48,7 @@ describe( 'Sidebar Permalink Panel', () => {
await page.keyboard.type( 'aaaaa' );
await publishPost();
// Start editing again.
- await page.type( '.editor-post-title__input', ' (Updated)' );
+ await canvas().type( '.editor-post-title__input', ' (Updated)' );
expect( await page.$x( permalinkPanelXPath ) ).toEqual( [] );
} );
@@ -56,7 +57,7 @@ describe( 'Sidebar Permalink Panel', () => {
await page.keyboard.type( 'aaaaa' );
await publishPost();
// Start editing again.
- await page.type( '.editor-post-title__input', ' (Updated)' );
+ await canvas().type( '.editor-post-title__input', ' (Updated)' );
expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeDefined();
} );
} );
diff --git a/packages/e2e-tests/specs/editor/various/splitting-merging.test.js b/packages/e2e-tests/specs/editor/various/splitting-merging.test.js
index 05e08db82afce..aadfb9e43efed 100644
--- a/packages/e2e-tests/specs/editor/various/splitting-merging.test.js
+++ b/packages/e2e-tests/specs/editor/various/splitting-merging.test.js
@@ -8,6 +8,7 @@ import {
getEditedPostContent,
pressKeyTimes,
pressKeyWithModifier,
+ canvas,
} from '@wordpress/e2e-test-utils';
describe( 'splitting and merging blocks', () => {
@@ -195,7 +196,7 @@ describe( 'splitting and merging blocks', () => {
// There is a default block:
expect(
- await page.$$( '.block-editor-block-list__block' )
+ await canvas().$$( '.block-editor-block-list__block' )
).toHaveLength( 1 );
// But the effective saved content is still empty:
diff --git a/packages/e2e-tests/specs/editor/various/taxonomies.test.js b/packages/e2e-tests/specs/editor/various/taxonomies.test.js
index 2ed1c18d2c361..8784ee051b26c 100644
--- a/packages/e2e-tests/specs/editor/various/taxonomies.test.js
+++ b/packages/e2e-tests/specs/editor/various/taxonomies.test.js
@@ -11,6 +11,7 @@ import {
findSidebarPanelWithTitle,
openDocumentSettingsSidebar,
publishPost,
+ canvas,
} from '@wordpress/e2e-test-utils';
/**
@@ -108,7 +109,7 @@ describe( 'Taxonomies', () => {
expect( selectedCategories[ 0 ] ).toEqual( 'z rand category 1' );
// Type something in the title so we can publish the post.
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Publish the post.
await publishPost();
@@ -166,7 +167,7 @@ describe( 'Taxonomies', () => {
expect( tags[ 0 ] ).toEqual( tagName );
// Type something in the title so we can publish the post.
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Publish the post.
await publishPost();
@@ -225,7 +226,7 @@ describe( 'Taxonomies', () => {
expect( tags[ 0 ] ).toEqual( tagName );
// Type something in the title so we can publish the post.
- await page.type( '.editor-post-title__input', 'Hello World' );
+ await canvas().type( '.editor-post-title__input', 'Hello World' );
// Publish the post.
await publishPost();
diff --git a/packages/e2e-tests/specs/editor/various/toolbar-roving-tabindex.test.js b/packages/e2e-tests/specs/editor/various/toolbar-roving-tabindex.test.js
index b31c088352a63..d490cb9c37c7b 100644
--- a/packages/e2e-tests/specs/editor/various/toolbar-roving-tabindex.test.js
+++ b/packages/e2e-tests/specs/editor/various/toolbar-roving-tabindex.test.js
@@ -6,15 +6,16 @@ import {
pressKeyWithModifier,
clickBlockToolbarButton,
insertBlock,
+ canvas,
} from '@wordpress/e2e-test-utils';
async function focusBlockToolbar() {
await pressKeyWithModifier( 'alt', 'F10' );
}
-async function expectLabelToHaveFocus( label ) {
+async function expectLabelToHaveFocus( label, p = page ) {
await expect(
- await page.evaluate( () =>
+ await p.evaluate( () =>
document.activeElement.getAttribute( 'aria-label' )
)
).toBe( label );
@@ -26,7 +27,7 @@ async function testBlockToolbarKeyboardNavigation( currentBlockLabel ) {
await page.keyboard.press( 'ArrowRight' );
await expectLabelToHaveFocus( 'Move up' );
await page.keyboard.press( 'Tab' );
- await expectLabelToHaveFocus( currentBlockLabel );
+ await expectLabelToHaveFocus( currentBlockLabel, canvas() );
await pressKeyWithModifier( 'shift', 'Tab' );
await expectLabelToHaveFocus( 'Move up' );
}
@@ -39,9 +40,9 @@ async function wrapCurrentBlockWithGroup() {
}
async function testGroupKeyboardNavigation( currentBlockLabel ) {
- await expectLabelToHaveFocus( 'Block: Group' );
+ await expectLabelToHaveFocus( 'Block: Group', canvas() );
await page.keyboard.press( 'Tab' );
- await expectLabelToHaveFocus( currentBlockLabel );
+ await expectLabelToHaveFocus( currentBlockLabel, canvas() );
await pressKeyWithModifier( 'shift', 'Tab' );
await expectLabelToHaveFocus( 'Select parent (Group)' );
await page.keyboard.press( 'ArrowRight' );
@@ -92,7 +93,7 @@ describe( 'Toolbar roving tabindex', () => {
// Move focus to the first toolbar item
await page.keyboard.press( 'Home' );
await expectLabelToHaveFocus( 'Change block type or style' );
- await page.click( '.blocks-table__placeholder-button' );
+ await canvas().click( '.blocks-table__placeholder-button' );
await testBlockToolbarKeyboardNavigation( 'Block: Table' );
await wrapCurrentBlockWithGroup();
await testGroupKeyboardNavigation( 'Block: Table' );
diff --git a/packages/e2e-tests/specs/editor/various/typewriter.test.js b/packages/e2e-tests/specs/editor/various/typewriter.test.js
index d1983e465e785..60daf820bb279 100644
--- a/packages/e2e-tests/specs/editor/various/typewriter.test.js
+++ b/packages/e2e-tests/specs/editor/various/typewriter.test.js
@@ -1,15 +1,18 @@
/**
* WordPress dependencies
*/
-import { createNewPost } from '@wordpress/e2e-test-utils';
+import { createNewPost, canvas } from '@wordpress/e2e-test-utils';
describe( 'TypeWriter', () => {
beforeEach( async () => {
await createNewPost();
} );
- const getCaretPosition = async () =>
- await page.evaluate( () => wp.dom.computeCaretRect( window ).y );
+ async function getCaretPosition() {
+ return await canvas().evaluate( () => {
+ return window.top.wp.dom.computeCaretRect( window ).top;
+ } );
+ }
// Allow the scroll position to be 1px off.
const BUFFER = 1;
@@ -21,9 +24,6 @@ describe( 'TypeWriter', () => {
// Create first block.
await page.keyboard.press( 'Enter' );
- // Create second block.
- await page.keyboard.press( 'Enter' );
-
const initialPosition = await getCaretPosition();
// The page shouldn't be scrolled when it's being filled.
@@ -32,13 +32,7 @@ describe( 'TypeWriter', () => {
expect( await getCaretPosition() ).toBeGreaterThan( initialPosition );
// Create blocks until the the typewriter effect kicks in.
- while (
- await page.evaluate(
- () =>
- wp.dom.getScrollContainer( document.activeElement )
- .scrollTop === 0
- )
- ) {
+ while ( await canvas().evaluate( () => window.scrollY === 0 ) ) {
await page.keyboard.press( 'Enter' );
}
@@ -51,7 +45,7 @@ describe( 'TypeWriter', () => {
// Type until the text wraps.
while (
- await page.evaluate(
+ await canvas().evaluate(
() =>
document.activeElement.clientHeight <=
parseInt(
@@ -91,19 +85,16 @@ describe( 'TypeWriter', () => {
await page.keyboard.press( 'Enter' );
// Create blocks until there is a scrollable container.
- while (
- await page.evaluate(
- () => ! wp.dom.getScrollContainer( document.activeElement )
- )
- ) {
+ while ( await canvas().evaluate( () => window.scrollY === 0 ) ) {
await page.keyboard.press( 'Enter' );
}
+ await page.evaluate( () => {
+ window.scrollY = 1;
+ } );
+
await page.evaluate(
- () =>
- ( wp.dom.getScrollContainer(
- document.activeElement
- ).scrollTop = 1 )
+ () => new Promise( window.requestAnimationFrame )
);
const initialPosition = await getCaretPosition();
@@ -142,11 +133,7 @@ describe( 'TypeWriter', () => {
await page.keyboard.press( 'Enter' );
// Create blocks until there is a scrollable container.
- while (
- await page.evaluate(
- () => ! wp.dom.getScrollContainer( document.activeElement )
- )
- ) {
+ while ( await canvas().evaluate( () => window.scrollY === 0 ) ) {
await page.keyboard.press( 'Enter' );
}
@@ -154,24 +141,16 @@ describe( 'TypeWriter', () => {
// Create blocks until the the typewriter effect kicks in, create at
// least 10 blocks to properly test the .
- while (
- ( await page.evaluate(
- () =>
- wp.dom.getScrollContainer( document.activeElement )
- .scrollTop === 0
- ) ) ||
- count < 10
- ) {
+ while ( count < 10 ) {
await page.keyboard.press( 'Enter' );
count++;
}
// Scroll the active element to the very bottom of the scroll container,
// then scroll up, so the caret is partially hidden.
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
document.activeElement.scrollIntoView( false );
- wp.dom.getScrollContainer( document.activeElement ).scrollTop -=
- document.activeElement.offsetHeight + 10;
+ window.scrollBy( 0, -document.activeElement.offsetHeight + 10 );
} );
const bottomPostition = await getCaretPosition();
@@ -198,10 +177,9 @@ describe( 'TypeWriter', () => {
// Scroll the active element to the very top of the scroll container,
// then scroll down, so the caret is partially hidden.
- await page.evaluate( () => {
+ await canvas().evaluate( () => {
document.activeElement.scrollIntoView();
- wp.dom.getScrollContainer( document.activeElement ).scrollTop +=
- document.activeElement.offsetHeight + 10;
+ window.scrollBy( 0, document.activeElement.offsetHeight + 10 );
} );
const topPostition = await getCaretPosition();
diff --git a/packages/e2e-tests/specs/editor/various/undo.test.js b/packages/e2e-tests/specs/editor/various/undo.test.js
index 30b3a4c80d494..b6476e703a8f9 100644
--- a/packages/e2e-tests/specs/editor/various/undo.test.js
+++ b/packages/e2e-tests/specs/editor/various/undo.test.js
@@ -10,10 +10,11 @@ import {
getAllBlocks,
saveDraft,
publishPost,
+ canvas,
} from '@wordpress/e2e-test-utils';
const getSelection = async () => {
- return await page.evaluate( () => {
+ return await canvas().evaluate( () => {
const selectedBlock = document.activeElement.closest( '.wp-block' );
const blocks = Array.from( document.querySelectorAll( '.wp-block' ) );
const blockIndex = blocks.indexOf( selectedBlock );
@@ -174,12 +175,12 @@ describe( 'undo', () => {
await saveDraft();
await page.reload();
await page.waitForSelector( '.edit-post-layout' );
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
await pressKeyWithModifier( 'primary', 'a' );
await pressKeyWithModifier( 'primary', 'b' );
await pressKeyWithModifier( 'primary', 'z' );
- const visibleResult = await page.evaluate(
+ const visibleResult = await canvas().evaluate(
() => document.activeElement.innerHTML
);
expect( visibleResult ).toBe( 'test' );
@@ -363,7 +364,7 @@ describe( 'undo', () => {
// regression present was accurate, it would produce the correct
// content. The issue had manifested in the form of what was shown to
// the user since the blocks state failed to sync to block editor.
- const visibleContent = await page.evaluate(
+ const visibleContent = await canvas().evaluate(
() => document.activeElement.textContent
);
expect( visibleContent ).toBe( 'original' );
@@ -400,7 +401,7 @@ describe( 'undo', () => {
await page.$( '.editor-history__undo[aria-disabled="true"]' )
).not.toBeNull();
- await page.click( '[data-type="core/paragraph"]' );
+ await canvas().click( '[data-type="core/paragraph"]' );
await page.keyboard.type( '2' );
diff --git a/packages/e2e-tests/specs/editor/various/writing-flow.test.js b/packages/e2e-tests/specs/editor/various/writing-flow.test.js
index f7d8b031f2911..ee65d03533780 100644
--- a/packages/e2e-tests/specs/editor/various/writing-flow.test.js
+++ b/packages/e2e-tests/specs/editor/various/writing-flow.test.js
@@ -10,6 +10,7 @@ import {
insertBlock,
clickBlockToolbarButton,
clickButton,
+ canvas,
} from '@wordpress/e2e-test-utils';
const getActiveBlockName = async () =>
@@ -27,8 +28,8 @@ const addParagraphsAndColumnsDemo = async () => {
`//*[contains(@class, "components-autocomplete__result") and contains(@class, "is-selected") and contains(text(), 'Columns')]`
);
await page.keyboard.press( 'Enter' );
- await page.click( ':focus [aria-label="Two columns; equal split"]' );
- await page.click( ':focus .block-editor-button-block-appender' );
+ await canvas().click( ':focus [aria-label="Two columns; equal split"]' );
+ await canvas().click( ':focus .block-editor-button-block-appender' );
await page.waitForSelector( ':focus.block-editor-inserter__search-input' );
await page.keyboard.type( 'Paragraph' );
await pressKeyTimes( 'Tab', 2 ); // Tab to paragraph result.
@@ -38,8 +39,8 @@ const addParagraphsAndColumnsDemo = async () => {
// TODO: ArrowDown should traverse into the second column. In slower
// CPUs, it can sometimes remain in the first column paragraph. This
// is a temporary solution.
- await page.focus( '.wp-block[data-type="core/column"]:nth-child(2)' );
- await page.click( ':focus .block-editor-button-block-appender' );
+ await canvas().focus( '.wp-block[data-type="core/column"]:nth-child(2)' );
+ await canvas().click( ':focus .block-editor-button-block-appender' );
await page.waitForSelector( ':focus.block-editor-inserter__search-input' );
await page.keyboard.type( 'Paragraph' );
await pressKeyTimes( 'Tab', 2 ); // Tab to paragraph result.
@@ -75,7 +76,7 @@ describe( 'Writing Flow', () => {
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
- activeElementText = await page.evaluate(
+ activeElementText = await canvas().evaluate(
() => document.activeElement.textContent
);
expect( activeElementText ).toBe( '2nd col' );
@@ -86,7 +87,7 @@ describe( 'Writing Flow', () => {
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/column' );
await page.keyboard.press( 'ArrowUp' );
- const activeElementBlockType = await page.evaluate( () =>
+ const activeElementBlockType = await canvas().evaluate( () =>
document.activeElement.getAttribute( 'data-type' )
);
expect( activeElementBlockType ).toBe( 'core/columns' );
@@ -98,7 +99,7 @@ describe( 'Writing Flow', () => {
await page.keyboard.press( 'ArrowUp' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );
- activeElementText = await page.evaluate(
+ activeElementText = await canvas().evaluate(
() => document.activeElement.textContent
);
expect( activeElementText ).toBe( 'First paragraph' );
@@ -290,25 +291,25 @@ describe( 'Writing Flow', () => {
// See: https://github.com/WordPress/gutenberg/issues/9626
// Title is within the editor's writing flow, and is a