Skip to content

Commit d3b81df

Browse files
committed
Add waitForURL in page mapping
1 parent 1cf64e5 commit d3b81df

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ type pageAPI interface { //nolint:interfacebloat
365365
WaitForNavigation(opts sobek.Value) (*common.Response, error)
366366
WaitForSelector(selector string, opts sobek.Value) (*common.ElementHandle, error)
367367
WaitForTimeout(timeout int64)
368+
WaitForURL(url string, opts sobek.Value) (*sobek.Promise, error)
368369
Workers() []*common.Worker
369370
}
370371

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,23 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop
535535
return nil, nil
536536
})
537537
},
538+
"waitForURL": func(url string, opts sobek.Value) (*sobek.Promise, error) {
539+
popts := common.NewFrameWaitForURLOptions(p.Timeout())
540+
if err := popts.Parse(vu.Context(), opts); err != nil {
541+
return nil, fmt.Errorf("parsing waitForURL options: %w", err)
542+
}
543+
544+
// Inject JS regex checker for URL pattern matching
545+
ctx := vu.Context()
546+
jsRegexChecker, err := injectURLMatcherScript(ctx, vu, p.TargetID())
547+
if err != nil {
548+
return nil, err
549+
}
550+
551+
return k6ext.Promise(ctx, func() (result any, reason error) {
552+
return nil, p.WaitForURL(url, popts, jsRegexChecker)
553+
}), nil
554+
},
538555
"workers": func() *sobek.Object {
539556
var mws []mapping
540557
for _, w := range p.Workers() {

0 commit comments

Comments
 (0)