Skip to content

Commit 5e51b17

Browse files
committed
Add tests for getByLabel
1 parent 40f80dc commit 5e51b17

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

internal/js/modules/k6/browser/tests/get_by_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,74 @@ func TestGetByAltTextSuccess(t *testing.T) {
852852
})
853853
}
854854
}
855+
856+
func TestGetByLabelSuccess(t *testing.T) {
857+
t.Parallel()
858+
859+
tests := []struct {
860+
name string
861+
label string
862+
opts *common.GetByBaseOptions
863+
expected int
864+
}{
865+
{
866+
// matches on all the elements with a label.
867+
"missing_label",
868+
"",
869+
nil,
870+
3,
871+
},
872+
{
873+
// matches on all the elements with a label.
874+
"empty_string",
875+
`""`,
876+
nil,
877+
3,
878+
},
879+
{
880+
"aria_label",
881+
`"username"`,
882+
nil,
883+
1,
884+
},
885+
{
886+
"exact_match",
887+
`"Password"`,
888+
&common.GetByBaseOptions{Exact: toPtr(true)},
889+
1,
890+
},
891+
{
892+
"no_exact_match",
893+
`"password"`,
894+
&common.GetByBaseOptions{Exact: toPtr(true)},
895+
0,
896+
},
897+
{
898+
"regex_match",
899+
`/^[a-z0-9]+$/`,
900+
nil,
901+
1,
902+
},
903+
}
904+
for _, tt := range tests {
905+
t.Run(tt.name, func(t *testing.T) {
906+
t.Parallel()
907+
908+
tb := newTestBrowser(t, withFileServer())
909+
p := tb.NewPage(nil)
910+
opts := &common.FrameGotoOptions{
911+
Timeout: common.DefaultTimeout,
912+
}
913+
_, err := p.Goto(
914+
tb.staticURL("get_by_label.html"),
915+
opts,
916+
)
917+
require.NoError(t, err)
918+
919+
l := p.GetByLabel(tt.label, tt.opts)
920+
c, err := l.Count()
921+
assert.NoError(t, err)
922+
assert.Equal(t, tt.expected, c)
923+
})
924+
}
925+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<title>Label Selector Engine Test Suite</title>
4+
</head>
5+
<body>
6+
<input aria-label="Username">
7+
<label for="password-input">Password</label>
8+
<input id="password-input">
9+
<input aria-label="abc123">
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)