File tree Expand file tree Collapse file tree 2 files changed +99
-0
lines changed
internal/js/modules/k6/browser/tests Expand file tree Collapse file tree 2 files changed +99
-0
lines changed Original file line number Diff line number Diff line change @@ -1099,3 +1099,90 @@ func TestGetByTitleSuccess(t *testing.T) {
1099
1099
})
1100
1100
}
1101
1101
}
1102
+
1103
+ func TestGetByTestIDSuccess (t * testing.T ) {
1104
+ t .Parallel ()
1105
+
1106
+ tests := []struct {
1107
+ name string
1108
+ testID string
1109
+ expected int
1110
+ expectedText string
1111
+ }{
1112
+ {
1113
+ "submit_button" ,
1114
+ "'submit-button'" ,
1115
+ 1 ,
1116
+ "Submit" ,
1117
+ },
1118
+ {
1119
+ "username_input" ,
1120
+ "'username-input'" ,
1121
+ 1 ,
1122
+ "" ,
1123
+ },
1124
+ {
1125
+ "info_box" ,
1126
+ "'info-box'" ,
1127
+ 1 ,
1128
+ "Information" ,
1129
+ },
1130
+ {
1131
+ "regex_match" ,
1132
+ `/^[a-z0-9]+$/` ,
1133
+ 1 ,
1134
+ "Test span" ,
1135
+ },
1136
+ {
1137
+ "link_testid" ,
1138
+ "'my-link'" ,
1139
+ 1 ,
1140
+ "Link" ,
1141
+ },
1142
+ {
1143
+ "non_existent_testid" ,
1144
+ "'does-not-exist'" ,
1145
+ 0 ,
1146
+ "" ,
1147
+ },
1148
+ {
1149
+ "missing_testid" ,
1150
+ "" ,
1151
+ 0 ,
1152
+ "" ,
1153
+ },
1154
+ {
1155
+ "empty_string" ,
1156
+ "''" ,
1157
+ 0 ,
1158
+ "" ,
1159
+ },
1160
+ }
1161
+ for _ , tt := range tests {
1162
+ t .Run (tt .name , func (t * testing.T ) {
1163
+ t .Parallel ()
1164
+
1165
+ tb := newTestBrowser (t , withFileServer ())
1166
+ p := tb .NewPage (nil )
1167
+ opts := & common.FrameGotoOptions {
1168
+ Timeout : common .DefaultTimeout ,
1169
+ }
1170
+ _ , err := p .Goto (
1171
+ tb .staticURL ("get_by_testid.html" ),
1172
+ opts ,
1173
+ )
1174
+ require .NoError (t , err )
1175
+
1176
+ l := p .GetByTestID (tt .testID )
1177
+ c , err := l .Count ()
1178
+ assert .NoError (t , err )
1179
+ assert .Equal (t , tt .expected , c )
1180
+
1181
+ if tt .expected > 0 && tt .expectedText != "" {
1182
+ text , err := l .InnerText (sobek .Undefined ())
1183
+ assert .NoError (t , err )
1184
+ assert .Equal (t , tt .expectedText , text )
1185
+ }
1186
+ })
1187
+ }
1188
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < head >
3
+ < title > Test ID Selector Engine Test Suite</ title >
4
+ </ head >
5
+ < body >
6
+ < button data-testid ="submit-button "> Submit</ button >
7
+ < input type ="text " data-testid ="username-input " placeholder ="Username ">
8
+ < div data-testid ="info-box "> Information</ div >
9
+ < span data-testid ="abc123 "> Test span</ span >
10
+ < a href ="# " data-testid ="my-link "> Link</ a >
11
+ </ body >
12
+ </ html>
You can’t perform that action at this time.
0 commit comments