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

fix(inspector): highlight xpath/css locators without engine prefix #27742

Merged
merged 3 commits into from
Oct 23, 2023

Conversation

mxschmitt
Copy link
Member

@mxschmitt mxschmitt commented Oct 22, 2023

Motivation: As of today when a user inspects a Locator which is a xpath, it won't work if the user has not prefixed it with xpath= because we internally compare the given with the generated locator.

Works: locator('xpath=//div[contains(@class, "foo")]')
Does not work: locator('//div[contains(@class, "foo")]')

Relates #27707 (comment)
Fixes microsoft/playwright-dotnet#2718 (comment)

@github-actions

This comment has been minimized.

@mxschmitt mxschmitt force-pushed the fix-inspect-xpath branch 2 times, most recently from 3f41d98 to 8d9b9f2 Compare October 22, 2023 12:02
@mxschmitt mxschmitt marked this pull request as ready for review October 22, 2023 12:02
@mxschmitt mxschmitt changed the title fix(inspect): highlight xpath locators without engine prefix fix(inspector): highlight xpath/css locators without engine prefix Oct 22, 2023
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

if (typeof selector === 'string')
return selector;
return selector.parts.map((p, i) => {
const prefix = p.name === 'css' ? '' : p.name + '=';
let hideEngine = false;
if (!forceEngineName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

While reading this, I realized that we cannot hide engine for the "capture" part.

Suggested change
if (!forceEngineName) {
if (!forceEngineName && i !== selector.capture) {

if (typeof selector === 'string')
return selector;
return selector.parts.map((p, i) => {
const prefix = p.name === 'css' ? '' : p.name + '=';
let hideEngine = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for readability, I'd recommend includeEngine instead.

@mxschmitt mxschmitt merged commit f48861d into microsoft:main Oct 23, 2023
@github-actions
Copy link
Contributor

Test results for "tests 1"

7 flaky ⚠️ [chromium] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [firefox] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [playwright-test] › ui-mode-test-ct.spec.ts:113:5 › should run component tests after editing test and component
⚠️ [webkit] › library/browsercontext-reuse.spec.ts:50:1 › should reset serviceworker
⚠️ [webkit] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [webkit] › page/page-goto.spec.ts:277:3 › should fail when navigating to bad SSL after redirects
⚠️ [webkit] › page/page-wait-for-navigation.spec.ts:85:3 › should work with clicking on links which do not commit navigation

25934 passed, 603 skipped
✔️✔️✔️

Merge workflow run.

Germandrummer92 pushed a commit to OctoMind-dev/playwright that referenced this pull request Oct 27, 2023
…icrosoft#27742)

Motivation: As of today when a user inspects a Locator which is a xpath,
it won't work if the user has not prefixed it with `xpath=` because we
internally compare the given with the generated locator.

Works: `locator('xpath=//div[contains(@Class, "foo")]')`
Does not work: `locator('//div[contains(@Class, "foo")]')`

Relates
microsoft#27707 (comment)
Fixes
microsoft/playwright-dotnet#2718 (comment)

---------

Signed-off-by: Max Schmitt <max@schmitt.mx>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better Locator exceptions for better debugging of selectors using Playwright Inspector
2 participants