Skip to content

Commit 1cf64e5

Browse files
committed
Add waitForURL in frame mapping
1 parent 8ecfd32 commit 1cf64e5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

internal/js/modules/k6/browser/browser/frame_mapping.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,23 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping {
422422
return nil, nil
423423
})
424424
},
425+
"waitForURL": func(url string, opts sobek.Value) (*sobek.Promise, error) {
426+
popts := common.NewFrameWaitForURLOptions(f.Timeout())
427+
if err := popts.Parse(vu.Context(), opts); err != nil {
428+
return nil, fmt.Errorf("parsing waitForURL options: %w", err)
429+
}
430+
431+
// Inject JS regex checker for URL pattern matching
432+
ctx := vu.Context()
433+
jsRegexChecker, err := injectURLMatcherScript(ctx, vu, f.Page().TargetID())
434+
if err != nil {
435+
return nil, err
436+
}
437+
438+
return k6ext.Promise(ctx, func() (result any, reason error) {
439+
return nil, f.WaitForURL(url, popts, jsRegexChecker)
440+
}), nil
441+
},
425442
}
426443
maps["$"] = func(selector string) *sobek.Promise {
427444
return k6ext.Promise(vu.Context(), func() (any, error) {

internal/js/modules/k6/browser/browser/mapping_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ type frameAPI interface { //nolint:interfacebloat
433433
WaitForNavigation(opts sobek.Value) (*common.Response, error)
434434
WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error)
435435
WaitForTimeout(timeout int64)
436+
WaitForURL(url string, opts sobek.Value) (*sobek.Promise, error)
436437
}
437438

438439
// elementHandleAPI is the interface of an in-page DOM element.

0 commit comments

Comments
 (0)