Skip to content

Commit

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

test.describe( 'Add New wp page', () => {
test.beforeEach( async ( { admin, requestUtils } ) => {
// delete all pages
await requestUtils.deleteAllPages();
// Open the new page editor
await admin.createNewPost( { postType: 'page' } );

Check failure on line 11 in tests/e2e/specs/pages/add-new-page.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › pages/add-new-page.test.js:14:2 › Add New wp page › Should create new page

2) [chromium] › pages/add-new-page.test.js:14:2 › Add New wp page › Should create new page ─────── Error: Not logged in 9 | await requestUtils.deleteAllPages(); 10 | // Open the new page editor > 11 | await admin.createNewPost( { postType: 'page' } ); | ^ 12 | } ); 13 | 14 | test( 'Should create new page', async ( { page, admin } ) => { 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/add-new-page.test.js:11:3

Check failure on line 11 in tests/e2e/specs/pages/add-new-page.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › pages/add-new-page.test.js:14:2 › Add New wp page › Should create new page

2) [chromium] › pages/add-new-page.test.js:14:2 › Add New wp page › Should create new page ─────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 9 | await requestUtils.deleteAllPages(); 10 | // Open the new page editor > 11 | await admin.createNewPost( { postType: 'page' } ); | ^ 12 | } ); 13 | 14 | test( 'Should create new page', async ( { page, admin } ) => { 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/add-new-page.test.js:11:3
} );

test( 'Should create new page', async ( { page, admin } ) => {
// Check if the template modal is visible and close it
/* if ( page.locator( '.components-modal__content' ).isVisible() ) {
await page.getByLabel( 'Close', { exact: true } ).click();
} */

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

// Move to the next field means the description field
await page.keyboard.press( 'ArrowDown' );

// Add the description for the page
await page.keyboard.type( 'Test page description' );

//Click on publish button
await page.click( '.editor-post-publish-panel__toggle' );

//Double check, click again on publish button
await page.click( '.editor-post-publish-button' );

// A success notice should show up
await expect( page.locator( '.components-snackbar' ) ).toBeVisible();

// visit all pages page
await admin.visitAdminPage( '/edit.php?post_type=page' );

// validate that the created page is present
await expect(
page.getByRole( 'link', { name: '“Test Page” (Edit)' } )
).toBeVisible();
} );
} );

0 comments on commit ca2ee0f

Please sign in to comment.