-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add getByLabel in the browser module #4890
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
Conversation
84c6eb3
to
db24587
Compare
964ff70
to
d9df382
Compare
e6bd37b
to
9447147
Compare
9447147
to
39f4b94
Compare
452dedb
to
5e51b17
Compare
<input aria-label="Username"> | ||
<label for="password-input">Password</label> | ||
<input id="password-input"> | ||
<input aria-label="abc123"> |
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.
<input aria-label="abc123"> | |
<input aria-label="abc123"> | |
<span | |
role="checkbox" | |
aria-checked="false" | |
tabindex="0" | |
aria-labelledby="tac"></span> | |
<span id="tac">I agree to the Terms and Conditions.</span> |
They mention the aria-labelledby
attribute in Playwright doc so here's an example from the mdn doc to add a test for it. I've tested it and it's working fine so I'm OK if you prefer to add it in a following PR.
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.
I'll add this to a new PR, thanks for spotting this!
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.
Added an issue to track this: #4956
var a string | ||
switch v.ExportType() { | ||
case reflect.TypeOf(string("")): | ||
a = fmt.Sprintf("'%s'", v.String()) // Strings require quotes | ||
case reflect.TypeOf(string("")): // text values require quotes |
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.
Should we have a constant here? Or do we expect the compiler to optimize?
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.
I didn't think about that tbh. I would expect the compiler to optimize it. I can make it a const though. I've added it to the catch all issue which I will work on after all the getBy*
PRs have been merged.
a = fmt.Sprintf("'%s'", v.String()) // Strings require quotes | ||
case reflect.TypeOf(string("")): // text values require quotes | ||
if doubleQuote { | ||
a = fmt.Sprintf(`"%s"`, v.String()) |
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.
a = fmt.Sprintf(`"%s"`, v.String()) | |
a = `"`+ v.String())+`"` |
This should be more efficient
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.
I've added it to the catch all issue which I will work on after all the getBy* PRs have been merged.
func isQuotedText(s string) bool { | ||
return len(s) > 1 && s[0] == '\'' && s[len(s)-1] == '\'' | ||
switch { |
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.
It seems you could simplify by removing len(s) > 0 and have a if
statement in line outside with len(s) < return false
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.
You mean like:
if len(s) < 1 {
return false
}
switch {
case s[0] == '\'' && s[len(s)-1] == '\'':
return true
case s[0] == '"' && s[len(s)-1] == '"':
return true
}
return false
If so, i've added it to the catch all issue to work on later 👍
The base branch was changed.
More than one getBy* API will use the same option.
This is to get the getByLabel API to work.
This interfaces with the code that was copied from Playwright. This is also copied from Playwright.
Some getBy* APIs work with single quotes and some are better at working with double quotes. getByLabel should work with double quotes. This inconsistency seems to stem from the code copied from Playwright itself. I would prefer not to change the copied injected script from Playwright so that it is easier to copy over updates/fixes.
The quoted string could be either single quoted ("'") or double quoted ('"'). isQuotedText needs to be able to handle both.
Co-authored-by: Agnès Toulet
What?
This adds a convenience method on
page
to be able to select onlabel
elements or elements with thearia-label
attribute.Why?
This is part of the story of adding
getBy*
, which makes working with selectors a little easier. We used to have to work with thepage.locator
API providing either aCSS
selector (when thearia-label
attribute was used) or aXPath
selector if we wanted to get the element by thelabel
:Now we can use:
Working with
getBy*
in general is an industry standard in the frontend testing world.Checklist
make check
) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)
Updates: #4789, #4248