Skip to content

Commit

Permalink
Add Playwright e2e test for edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
jayson31 committed Dec 12, 2024
1 parent 27c566f commit cfea8a9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/e2e/specs/pages/edit-page.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Edit a wp page', () => {
// Create a new page before updating it
test.beforeEach( async ( { admin, requestUtils, editor } ) => {
await requestUtils.deleteAllPages();

//Create a new page
await admin.createNewPost( { postType: 'page', title: 'Test page' } );

Check failure on line 12 in tests/e2e/specs/pages/edit-page.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/edit-page.test.js:18:2 › Edit a wp page › should be able to edit page

2) [chromium] › pages/edit-page.test.js:18:2 › Edit a wp page › should be able to edit page ────── Error: Not logged in 10 | 11 | //Create a new page > 12 | await admin.createNewPost( { postType: 'page', title: 'Test page' } ); | ^ 13 | 14 | // publish page 15 | await editor.publishPost(); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/pages/edit-page.test.js:12:3

Check failure on line 12 in tests/e2e/specs/pages/edit-page.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/edit-page.test.js:18:2 › Edit a wp page › should be able to edit page

2) [chromium] › pages/edit-page.test.js:18:2 › Edit a wp page › should be able to edit page ────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 10 | 11 | //Create a new page > 12 | await admin.createNewPost( { postType: 'page', title: 'Test page' } ); | ^ 13 | 14 | // publish page 15 | await editor.publishPost(); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at Admin.createNewPost (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/create-new-post.ts:41:2) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/pages/edit-page.test.js:12:3

// publish page
await editor.publishPost();
} );

test( 'should be able to edit page', async ( { page, admin } ) => {
// navigate to all pages
await admin.visitAdminPage( '/edit.php?post_type=page' );

// Click on the edit link
await page.hover( 'role=link[name="“Test page” (Edit)"i]' );
await page
.getByRole( 'link', { name: 'Edit “Test page”' } )
.first()
.click();

// Update the exiting page title
await page
.frameLocator( 'iframe[name="editor-canvas"]' )
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'Test Page - Edited' );

// Click on save button
await page.getByRole( 'button', { name: 'Save', exact: true } ).click();

// A success notice should show up
await expect( page.getByTestId( 'snackbar' ) ).toBeVisible();
await admin.visitAdminPage( '/edit.php?post_type=page' );
expect(
page.getByRole( 'link', { name: 'Test Page – Edited” (Edit)' } )
).toBeVisible();
} );
} );

0 comments on commit cfea8a9

Please sign in to comment.