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 format API test for playwright #42035

Merged

Conversation

pavanpatil1
Copy link
Contributor

What?

Part of #38851.
Migrate format-api.test.js to its Playwright version.

Why?

Part of #38851.

How?

See MIGRATION.md for migration steps.

Testing Instructions

Run npm run test-e2e:playwright test/e2e/specs/editor/plugins/format-api.spec.js

@pavanpatil1
Copy link
Contributor Author

Hello @kevin940726, Could you review this PR. ?.

@pavanpatil1
Copy link
Contributor Author

pavanpatil1 commented Jul 7, 2022

Hi @kevin940726, Hope you are doing well.
Could you please help me in reviewing this PR ?.

Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

Hi! Sorry I missed the pings! Thank you as always 💯

Comment on lines 28 to 31
const button = await page.locator(
`//button[contains(text(), '${ 'Custom Link' }')]`
);
await button.click();
Copy link
Member

Choose a reason for hiding this comment

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

Have you read the best practice guide? I think we can refactor this into role selector instead:

Suggested change
const button = await page.locator(
`//button[contains(text(), '${ 'Custom Link' }')]`
);
await button.click();
await page.click( 'role=button[name="Custom Link"i]' );

@pavanpatil1
Copy link
Contributor Author

Hi @kevin940726, Yes, I tried that, but because the button doesn't have the name attribute available, it is failing.

image

screenshot-nimbusweb me-2022 07 08-07_43_41

@kevin940726
Copy link
Member

@pavanpatil1 It's not a DOM attribute but a computed accessible attribute interpreted by the browsers and screen readers. You can view what accessible attributes browsers see via devtools, take Chrome as an example:

image

You can see that the element has a role of menuitem and a name of  Custom Link. The part is likely caused by a bug and should probably be fixed by a different PR. For now, I think we can just use the selector role=menuitem[name=/Custom Link/i] to target the element (and add a comment above explaining why we want to use regex here).

@pavanpatil1
Copy link
Contributor Author

Hi @kevin940726, Thank you so much 💯

I addressed the above feedback. Could you check again ?.

Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

Looks good! Remember to also delete the snapshot of the original test though (format-api.test.js.snap).

Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks! 💯

@kevin940726 kevin940726 merged commit 9af41b1 into WordPress:trunk Jul 11, 2022
@github-actions github-actions bot added this to the Gutenberg 13.7 milestone Jul 11, 2022
@pavanpatil1 pavanpatil1 deleted the add/playwright-format-api-test branch July 11, 2022 04:56
@bph bph added the [Tool] E2E Test Utils /packages/e2e-test-utils label Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] E2E Test Utils /packages/e2e-test-utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants