Fix failing tests in Gutenberg stable and nightly tests (#49548)

This commit is contained in:
Veljko V. 2024-07-22 14:52:21 +02:00 committed by GitHub
parent f6035610a6
commit 406a6c07f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 81 additions and 25 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
E2E tests: Fix flaky Gutenberg tests

View File

@ -2,6 +2,7 @@ const { test: base, expect, request } = require( '@playwright/test' );
const { AssemblerPage } = require( './assembler.page' );
const { activateTheme, DEFAULT_THEME } = require( '../../../utils/themes' );
const { setOption } = require( '../../../utils/options' );
const { encodeCredentials } = require( '../../../utils/plugin-utils' );
const test = base.extend( {
pageObject: async ( { page }, use ) => {
@ -163,6 +164,32 @@ test.skip( 'Assembler -> Homepage', { tag: '@gutenberg' }, () => {
await waitResponse;
await page.goto( baseURL );
// Check if Gutenberg is installed
const apiContext = await request.newContext( {
baseURL,
extraHTTPHeaders: {
Authorization: `Basic ${ encodeCredentials(
'admin',
'password'
) }`,
cookie: '',
},
} );
const listPluginsResponse = await apiContext.get(
`/wp-json/wp/v2/plugins`,
{
failOnStatusCode: true,
}
);
const pluginsList = await listPluginsResponse.json();
const withGutenbergPlugin = pluginsList.find(
( { textdomain } ) => textdomain === 'gutenberg'
);
// if testing with Gutenberg, perform Gutenberg-specific testing
// eslint-disable-next-line playwright/no-conditional-in-test
if ( withGutenbergPlugin ) {
// Get all the content between the header and the footer.
const homepageHTML = await page
.locator(
@ -175,10 +202,13 @@ test.skip( 'Assembler -> Homepage', { tag: '@gutenberg' }, () => {
await expect(
await element.getAttribute( 'class' )
).toMatchSnapshot( {
name: `selected-homepage-blocks-class-frontend-${ index }`,
name: `${
withGutenbergPlugin ? 'gutenberg' : ''
}-selected-homepage-blocks-class-frontend-${ index }`,
} );
index++;
}
}
} );
test.describe( 'Homepage tracking banner', () => {

View File

@ -0,0 +1 @@
wp-block-group alignfull has-global-padding is-content-justification-center is-layout-constrained wp-container-core-group-is-layout-5 wp-block-group-is-layout-constrained

View File

@ -0,0 +1 @@
wp-block-group alignfull has-global-padding is-content-justification-center is-layout-constrained wp-container-core-group-is-layout-7 wp-block-group-is-layout-constrained

View File

@ -0,0 +1 @@
wp-block-group alignfull has-global-padding is-content-justification-center is-layout-constrained wp-container-core-group-is-layout-8 wp-block-group-is-layout-constrained

View File

@ -0,0 +1 @@
wp-block-group alignfull has-global-padding is-content-justification-center is-layout-constrained wp-container-core-group-is-layout-9 wp-block-group-is-layout-constrained

View File

@ -4,6 +4,7 @@ const {
fillPageTitle,
getCanvas,
publishPage,
closeChoosePatternModal,
} = require( '../../utils/editor' );
const test = baseTest.extend( {
@ -18,6 +19,8 @@ test.describe(
test( 'can create new page', async ( { page, testPage } ) => {
await goToPageEditor( { page } );
await closeChoosePatternModal( { page } );
await fillPageTitle( page, testPage.title );
const canvas = await getCanvas( page );

View File

@ -14,7 +14,6 @@ test.describe(
'Can create a new post',
{ tag: [ '@gutenberg', '@services' ] },
() => {
// eslint-disable-next-line playwright/expect-expect
test( 'can create new post', async ( { page, testPost } ) => {
await goToPostEditor( { page } );

View File

@ -5,6 +5,7 @@ const {
insertBlock,
getCanvas,
publishPage,
closeChoosePatternModal,
} = require( '../../utils/editor' );
const { getInstalledWordPressVersion } = require( '../../utils/wordpress' );
@ -146,6 +147,9 @@ test.describe(
testPage,
} ) => {
await goToPageEditor( { page } );
await closeChoosePatternModal( { page } );
await fillPageTitle( page, testPage.title );
const wordPressVersion = await getInstalledWordPressVersion();

View File

@ -5,6 +5,7 @@ const {
insertBlock,
getCanvas,
publishPage,
closeChoosePatternModal,
} = require( '../../utils/editor' );
const { getInstalledWordPressVersion } = require( '../../utils/wordpress' );
@ -34,6 +35,9 @@ test.describe(
testPage,
} ) => {
await goToPageEditor( { page } );
await closeChoosePatternModal( { page } );
await fillPageTitle( page, testPage.title );
const wordPressVersion = await getInstalledWordPressVersion();

View File

@ -1,14 +1,13 @@
const { expect } = require( '@playwright/test' );
const closeWelcomeModal = async ( { page } ) => {
// Close welcome popup if prompted
try {
await page
.getByLabel( 'Close', { exact: true } )
.click( { timeout: 5000 } );
} catch ( error ) {
// Welcome modal wasn't present, skipping action.
}
const closeChoosePatternModal = async ( { page } ) => {
const closeModal = page.getByRole( 'button', {
name: 'Close',
exact: true,
} );
await page.addLocatorHandler( closeModal, async () => {
await closeModal.click();
} );
};
const disableWelcomeModal = async ( { page } ) => {
@ -42,14 +41,23 @@ const getCanvas = async ( page ) => {
const goToPageEditor = async ( { page } ) => {
await page.goto( 'wp-admin/post-new.php?post_type=page' );
await disableWelcomeModal( { page } );
await page.waitForResponse(
( response ) =>
response.url().includes( '//page' ) && response.status() === 200
);
};
const goToPostEditor = async ( { page } ) => {
await page.goto( 'wp-admin/post-new.php' );
await disableWelcomeModal( { page } );
await page.waitForResponse(
( response ) =>
response.url().includes( '//single' ) && response.status() === 200
);
};
const fillPageTitle = async ( page, title ) => {
await ( await getCanvas( page ) ).getByLabel( 'Add title' ).click();
await ( await getCanvas( page ) ).getByLabel( 'Add title' ).fill( title );
};
@ -132,7 +140,7 @@ const publishPage = async ( page, pageTitle ) => {
};
module.exports = {
closeWelcomeModal,
closeChoosePatternModal,
goToPageEditor,
goToPostEditor,
disableWelcomeModal,