fix(getByRole): name and exact#18719
Merged
Merged
Conversation
Member
pavelfeldman
left a comment
There was a problem hiding this comment.
Could you add locator-generator tests?
Following the `getByText()` and other methods: - By default, matching is substring and case-insensitive. Before, it was only case-insensitive, but not substring. - With new option `exact: true`, matching is full string and case-sensitive. - Matching always normalizes whitespace. - Codegen generates `exact: false` by default. - `internal:role` treats `[name="foo"i]` as non-exact match. Various fixes: - Updated `getByRole` docs to match the reality. - Locator generator edge cases.
64f22ef to
a75c6ec
Compare
pavelfeldman
approved these changes
Nov 11, 2022
| const accessibleName = getElementAccessibleName(element, includeHidden, hiddenCache).trim().replace(/\s+/g, ' '); | ||
| if (typeof nameAttr.value === 'string') | ||
| nameAttr.value = nameAttr.value.trim().replace(/\s+/g, ' '); | ||
| // internal:role assumes that [name="foo"i] also means substring. |
Member
There was a problem hiding this comment.
We can follow up and rename all 'i' to 'lax'
| export type LocatorType = 'default' | 'role' | 'text' | 'label' | 'placeholder' | 'alt' | 'title' | 'test-id' | 'nth' | 'first' | 'last' | 'has-text' | 'has' | 'frame'; | ||
| export type LocatorBase = 'page' | 'locator' | 'frame-locator'; | ||
|
|
||
| type LocatorOptions = { attrs?: { name: string, value: string | boolean | number}[], exact?: boolean, name?: string | RegExp }; |
Member
There was a problem hiding this comment.
attrs.name and name are clashing for me.
aslushnikov
pushed a commit
that referenced
this pull request
Nov 14, 2022
Following the `getByText()` and other methods: - By default, matching is substring and case-insensitive. Before, it was only case-insensitive, but not substring. - With new option `exact: true`, matching is full string and case-sensitive. - Matching always normalizes whitespace. - Codegen generates `exact: false` by default. - `internal:role` treats `[name="foo"i]` as non-exact match. Various fixes: - Updated `getByRole` docs to match the reality. - Locator generator edge cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following the
getByText()and other methods:exact: true, matching is full string and case-sensitive.exact: falseby default.internal:roletreats[name="foo"i]as non-exact match.Various fixes:
getByRoledocs to match the reality.