Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playwright E2E test to save page as draft #8051

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions tests/e2e/specs/pages/save-page-to-draft.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Save Page', () => {
test.beforeEach( async ( { admin, editor } ) => {
// create Page to use in test
const pageTitle = 'Test Page for draft';

await admin.createNewPost( { title: pageTitle, postType: 'page' } );

Check failure on line 11 in tests/e2e/specs/pages/save-page-to-draft.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/save-page-to-draft.test.js:18:2 › Save Page › saves the page as drafts

1) [chromium] › pages/save-page-to-draft.test.js:18:2 › Save Page › saves the page as drafts ───── Error: Not logged in 9 | const pageTitle = 'Test Page for draft'; 10 | > 11 | await admin.createNewPost( { title: pageTitle, postType: 'page' } ); | ^ 12 | } ); 13 | 14 | test.afterAll( async ( { requestUtils } ) => { 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/save-page-to-draft.test.js:11:3

Check failure on line 11 in tests/e2e/specs/pages/save-page-to-draft.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › pages/save-page-to-draft.test.js:18:2 › Save Page › saves the page as drafts

1) [chromium] › pages/save-page-to-draft.test.js:18:2 › Save Page › saves the page as drafts ───── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 9 | const pageTitle = 'Test Page for draft'; 10 | > 11 | await admin.createNewPost( { title: pageTitle, postType: 'page' } ); | ^ 12 | } ); 13 | 14 | test.afterAll( async ( { requestUtils } ) => { 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/save-page-to-draft.test.js:11:3

Check failure on line 11 in tests/e2e/specs/pages/save-page-to-draft.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › pages/save-page-to-draft.test.js:18:2 › Save Page › saves the page as drafts

2) [chromium] › pages/save-page-to-draft.test.js:18:2 › Save Page › saves the page as drafts ───── Error: Not logged in 9 | const pageTitle = 'Test Page for draft'; 10 | > 11 | await admin.createNewPost( { title: pageTitle, postType: 'page' } ); | ^ 12 | } ); 13 | 14 | test.afterAll( async ( { requestUtils } ) => { 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/save-page-to-draft.test.js:11:3
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllPages();
} );

test( 'saves the page as drafts', async ( { page, admin } ) => {

// Focus editor and type description
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.type( 'Test page description' );

// Save the page as a draft
await page.click( 'role=button[name="Save draft"i]' );

// Wait for snackbar notification
const snackbar = page.locator( '.components-snackbar__content' );
await snackbar.waitFor( { state: 'visible', timeout: 10000 } );

// Verify snackbar displays correct message
await expect( snackbar ).toHaveText( /Draft saved./ );

// Verify save button text changes to "Saved"
const saveButton = page.locator( "button[aria-label='Saved']" );
console.log('\x1b[32m%s\x1b[0m', '✅ Checking: Draft button label is changed to "Saved"');
await expect(saveButton).toHaveText('Saved');

console.log('\x1b[32m%s\x1b[0m', '✅ Checking: Saved button is disabled');
await expect(saveButton).toBeDisabled();
} );
} );
Loading