diff --git a/src/blocks/test/e2e/blocks/block-conditions.spec.js b/src/blocks/test/e2e/blocks/block-conditions.spec.js index 00709ad0e..57826676b 100644 --- a/src/blocks/test/e2e/blocks/block-conditions.spec.js +++ b/src/blocks/test/e2e/blocks/block-conditions.spec.js @@ -5,20 +5,21 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright'; import { tryLoginIn } from '../utils'; test.describe( 'Block Conditions', () => { - test.beforeEach( async({ admin, requestUtils, page }) => { - await tryLoginIn( page, 'admin', 'password' ); + test.beforeEach( async({ admin, page }) => { + await tryLoginIn( page ); await admin.createNewPost(); }); test.afterEach( async({ page }) => { /** - * Because some conditions require an user to be logged in, we need to log in the user after each test so that we do not break the next test. + * Because some conditions require a user to be logged in, + * we need to log in the user after each test so that we do not break the next test. */ - await tryLoginIn( page, 'admin', 'password' ); + await tryLoginIn( page ); }); - test( 'check logged out users', async({ editor, page, admin, requestUtils }) => { + test( 'check logged out users', async({ editor, page }) => { await editor.insertBlock({ name: 'core/image', attributes: { @@ -35,14 +36,15 @@ test.describe( 'Block Conditions', () => { const postId = await editor.publishPost(); - // Check the block for logged in users. + // Check the block for logged-in users. await page.goto( `/?p=${postId}` ); await expect( page.locator( '#wp--skip-link--target img' ) ).toBeVisible(); - // Check the block for logged out users. + // // Check the block for logged out users. await page.getByRole( 'menuitem', { name: 'Howdy, admin' }).hover(); await page.waitForTimeout( 200 ); await page.getByRole( 'menuitem', { name: 'Log Out' }).click(); + await page.goto( `/?p=${postId}` ); await expect( page.locator( '#wp--skip-link--target img' ) ).toBeHidden(); }); diff --git a/src/blocks/test/e2e/blocks/button-group.spec.js b/src/blocks/test/e2e/blocks/button-group.spec.js index 27a118337..f2b35d0c2 100644 --- a/src/blocks/test/e2e/blocks/button-group.spec.js +++ b/src/blocks/test/e2e/blocks/button-group.spec.js @@ -4,7 +4,7 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright'; test.describe( 'Button Group', () => { - test.beforeEach( async({ admin }) => { + test.beforeEach( async({ admin, page }) => { await admin.createNewPost(); }); diff --git a/src/blocks/test/e2e/utils.js b/src/blocks/test/e2e/utils.js index a45223741..369141d9b 100644 --- a/src/blocks/test/e2e/utils.js +++ b/src/blocks/test/e2e/utils.js @@ -69,9 +69,14 @@ export function deleteFile( filePath ) { } } -export async function tryLoginIn( page, username, password ) { - await page.goto( '/wp-login.php' ); - await page.fill( 'input[name="log"]', username ); - await page.fill( 'input[name="pwd"]', password ); - await page.click( 'input[name="wp-submit"]' ); +export async function tryLoginIn( page, username = 'admin', password = 'password' ) { + await page.goto('/wp-login.php'); + await page.fill('input[name="log"]', username); + await page.fill('input[name="pwd"]', password); + await page.check('input[name="rememberme"]'); + await page.click('input[name="wp-submit"]'); + + // Save the context since tests are isolated. + // So we need to save the auth state to keep the user logged in so that they can be used in the next test. + await page.context().storageState({ path: 'artifacts/storage-states/admin.json' }); }