-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[@wordpress/e2e-test-utils-playwright] Add switchBlockInspectorTab utility
#52479
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
[@wordpress/e2e-test-utils-playwright] Add switchBlockInspectorTab utility
#52479
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Raluca, congrats on the PR!
I took a look and it's working as described, however, what do you think about using the locator helper functions, instead of using CSS selectors to get the page elements?
Something like this:
export async function switchBlockInspectorTab(
this: Editor,
ariaLabel: string
) {
const tabButton = this.page.getByRole( 'tab', { name: ariaLabel } );
await tabButton.click();
this.page.getByRole( 'tabpanel', { name: ariaLabel } );
}by the way, I'm not sure if this is necessary, but you could be extra specific and add .getByLabel( 'Editor settings' ) to the locator, to isolate it to the sidebar.
export async function switchBlockInspectorTab(
this: Editor,
ariaLabel: string
) {
const sidebar = this.page.getByLabel( 'Editor settings' );
const tabButton = sidebar.getByRole( 'tab', { name: ariaLabel } );
await tabButton.click();
sidebar.getByRole( 'tabpanel', { name: ariaLabel } );
}|
@opr thank you for the improvements. I went ahead and used your suggestion to search just in the sidebar. I noticed that other tests did the same. Ideally, this element should be saved in a reusable constant to make sure people select it the same. Happy to do this myself if @kevin940726 can recommend the best way to do this |
Nice idea. Maybe there can be a new function added on |
kevin940726
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! From this section of the best practice guide, I'm more leaning towards inlining these simple utils, especially when they are short and readable.
This util can be inlined like:
await page.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'tab', { name: 'Styles' } )
.click();The last waitFor isn't normally needed since Playwright will auto-wait for anything afterwards anyway.
I'm also not opposed to the idea of creating this util if people find it useful though! @Mamaduka WDYT?
|
I think actions that we've to repeat often make sense to be extracted as utils, just like |
|
Closing, I don't think this change is needed after all |
What?
This PR is migrating the Puppeteer utility
switchBlockInspectorTabto the new@wordpress/e2e-test-utils-playwrightpackageWhy?
This utility is needed by people migrating E2E tests to Playwright who use this utility from
@wordpress/e2e-test-utilsHow?
The utility keeps the old logic of getting the button by label, clicking it and confirming the appropriate inspector tab is visible.
Testing Instructions
Set up
wp-env.Add a new test file,
test/e2e/specs/editor/various/switch-block-inspector-tab.test.jsand add the following code:Run
npm run test:e2e:playwright -- test/e2e/specs/editor/various/switch-block-inspector-tab.test.jsand ensure the test passes.Testing Instructions for Keyboard
N/A
Screenshots or screencast