diff --git a/test/e2e/specs/editor/blocks/image.spec.js b/test/e2e/specs/editor/blocks/image.spec.js index eb5d9e2780b445..82a7e1ac71cce5 100644 --- a/test/e2e/specs/editor/blocks/image.spec.js +++ b/test/e2e/specs/editor/blocks/image.spec.js @@ -552,9 +552,16 @@ test.describe( 'Image', () => { } ); async function openMediaTab() { - await page - .getByRole( 'button', { name: 'Toggle block inserter' } ) - .click(); + const blockInserter = page.getByRole( 'button', { + name: 'Toggle block inserter', + } ); + const isClosed = + ( await blockInserter.getAttribute( 'aria-pressed' ) ) === + 'false'; + + if ( isClosed ) { + await blockInserter.click(); + } await blockLibrary.getByRole( 'tab', { name: 'Media' } ).click();