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

Migrate Preferences Test to Playwright #44107

Closed
Show file tree
Hide file tree
Changes from 3 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
58 changes: 0 additions & 58 deletions packages/e2e-tests/specs/editor/various/preferences.test.js

This file was deleted.

55 changes: 55 additions & 0 deletions test/e2e/specs/editor/various/preferences.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'preferences', () => {
test( 'remembers sidebar dismissal between sessions', async ( {
page,
admin,
} ) => {
await admin.createNewPost();
// Open by default.
await expect(
page.locator(
'.components-button.edit-post-sidebar__panel-tab.is-active'
)
).toHaveText( 'Post' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test seems to be failing on this line.

The issue could be that Playwright isn't waiting for the element. You could try using expect.poll.

It'd be good to try changing the classname selector to a role selector. This is what my browser dev tools shows as the accessibility properties:
Screen Shot 2022-09-15 at 5 05 05 pm

(so role is "button", name is "Post (selected)")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @talldan, Previously also tried expect.poll but expect.poll excepts function only. I also tried to pass the async function within it but still it seems to be not working.

image

Let me know your thoughts on same.


// Change to "Block" tab.
await page.click( 'role=button[name="Block"i]' );

await expect(
page.locator(
'.components-button.edit-post-sidebar__panel-tab.is-active'
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I think a role selector can be used for this. It will be different to the one above as it's a different button:
Screen Shot 2022-09-15 at 5 09 40 pm

).toHaveText( 'Block' );

// Regression test: Reload resets to document tab.
//
// See: https://github.com/WordPress/gutenberg/issues/6377
// See: https://github.com/WordPress/gutenberg/pull/8995
await page.reload();
await page.waitForSelector( '.edit-post-layout' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line essentially waits for the block editor to load, but I think it line can be removed. The line below it could be changed to await expect.poll(, which would make the test wait for the panel tab to be present (so it would have the same result of waiting for the editor to load).

await expect(
page.locator(
'.components-button.edit-post-sidebar__panel-tab.is-active'
)
Copy link
Contributor

@talldan talldan Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same element as the locator from my first comment (role "button", name "Post (selected)").

It could be assigned to a variable at the start of the test and that variable used here.

).toHaveText( 'Post' );

// Dismiss.
await page.click(
'.edit-post-sidebar__panel-tabs [aria-label="Close settings"]'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can be a role locator too:
Screen Shot 2022-09-15 at 5 13 42 pm

( button / "Close settings" )

);
await expect(
page.locator( '.edit-post-sidebar__panel-tab.is-active' )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I think it'd be fine to use the locator from my first comment (assign it to a variable and use the variable here).

).not.toBeVisible();

// Remember after reload.
await page.reload();
await page.waitForSelector( '.edit-post-layout' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this line because it waits for something that's unrelated to the user interface being tested.

If it could be changed to a role selector for this element, that would be great:
Screen Shot 2022-09-15 at 5 20 37 pm

await expect(
page.locator( '.edit-post-sidebar__panel-tab.is-active' )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again, it'd be fine to use the locator from my first comment (assign it to a variable and use the variable here).

).not.toBeVisible();
} );
} );