Skip to content

fix(locator generator): handle frameLocator() and locator().contentFrame()#33208

Merged
Skn0tt merged 14 commits into
microsoft:mainfrom
Skn0tt:fix-iframe-locator-generator
Oct 24, 2024
Merged

fix(locator generator): handle frameLocator() and locator().contentFrame()#33208
Skn0tt merged 14 commits into
microsoft:mainfrom
Skn0tt:fix-iframe-locator-generator

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented Oct 21, 2024

Came out of #33146. frameLocator('iframe') is synonymous to locator('iframe').contentFrame(), but our locator <-> selector processing can't handle frameLocator('iframe') well. This PR fixes that by adding a special case and respecting both syntaxes the same.

@Skn0tt Skn0tt requested a review from dgozman October 21, 2024 15:28
@Skn0tt Skn0tt self-assigned this Oct 21, 2024
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@dgozman dgozman left a comment

Choose a reason for hiding this comment

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

Left a couple comments.

Btw, here is the previous implementation that was removed: https://github.com/microsoft/playwright/pull/32697/files#diff-ffdc452be25f5c91f4cb081974256b611978f6bde6aff0ee018ea511312e33b0, just in case you'd like to see how it was.

Comment thread packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts Outdated
Comment thread packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts Outdated
@Skn0tt
Copy link
Copy Markdown
Member Author

Skn0tt commented Oct 22, 2024

Btw, here is the previous implementation that was removed: https://github.com/microsoft/playwright/pull/32697/files#diff-ffdc452be25f5c91f4cb081974256b611978f6bde6aff0ee018ea511312e33b0, just in case you'd like to see how it was.

Interesting! So it looks like we used to only handle one of the two options. Then we swapped it around to handle the other option. And with this PR, we now handle both options. Is that right?

@dgozman
Copy link
Copy Markdown
Collaborator

dgozman commented Oct 22, 2024

Btw, here is the previous implementation that was removed: https://github.com/microsoft/playwright/pull/32697/files#diff-ffdc452be25f5c91f4cb081974256b611978f6bde6aff0ee018ea511312e33b0, just in case you'd like to see how it was.

Interesting! So it looks like we used to only handle one of the two options. Then we swapped it around to handle the other option. And with this PR, we now handle both options. Is that right?

Yep.

@Skn0tt
Copy link
Copy Markdown
Member Author

Skn0tt commented Oct 22, 2024

addressed your feedback

@Skn0tt Skn0tt changed the title Fix iframe locator generator fix(locator generator): handle frameLocator() and locator().contentFrame() Oct 22, 2024
locatorPartWithEngine = factory.generateLocator(base, 'default', selectorPart);
}

if (nextPart && nextPart.name === 'internal:control' && (nextPart.body as string) === 'enter-frame') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

After looking again, I see that we might be missing some cases. For example, page.getByTitle('iframe title').contentFrame() - does it correctly handle this case?

Copy link
Copy Markdown
Member Author

@Skn0tt Skn0tt Oct 22, 2024

Choose a reason for hiding this comment

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

Great catch, it does not. I've revised the approach in e1e9b66 to go back one produced token and update that in retrospect. This makes the change much smaller as well, really liking it. Makes the code a little more hairy though because it mutates across iterations.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts Outdated
Comment thread packages/playwright-core/src/utils/isomorphic/locatorGenerators.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

Test results for "tests 1"

2 flaky ⚠️ [playwright-test] › ui-mode-test-output.spec.ts:80:5 › should show console messages for test @macos-latest-node18-1
⚠️ [installation tests] › playwright-electron-should-work.spec.ts:44:5 › should work when wrapped inside @playwright/test and trace is enabled @package-installations-macos-latest @playwright/test

36570 passed, 626 skipped
✔️✔️✔️

Merge workflow run.

@Skn0tt Skn0tt merged commit 69f56b9 into microsoft:main Oct 24, 2024
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.

2 participants