diff --git a/browser/mapping.go b/browser/mapping.go index c58dc564c..aa1a2e102 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -82,12 +82,14 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { "press": lo.Press, "type": lo.Type, "hover": lo.Hover, - "tap": func(opts goja.Value) error { + "tap": func(opts goja.Value) (*goja.Promise, error) { copts := common.NewFrameTapOptions(lo.DefaultTimeout()) if err := copts.Parse(vu.Context(), opts); err != nil { - return fmt.Errorf("parsing locator tap options: %w", err) + return nil, fmt.Errorf("parsing locator tap options: %w", err) } - return lo.Tap(copts) //nolint:wrapcheck + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, lo.Tap(copts) //nolint:wrapcheck + }), nil }, "dispatchEvent": func(typ string, eventInit, opts goja.Value) error { popts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout()) @@ -304,12 +306,14 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { "selectOption": eh.SelectOption, "selectText": eh.SelectText, "setInputFiles": eh.SetInputFiles, - "tap": func(opts goja.Value) error { + "tap": func(opts goja.Value) (*goja.Promise, error) { popts := common.NewElementHandleTapOptions(eh.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { - return fmt.Errorf("parsing element tap options: %w", err) + return nil, fmt.Errorf("parsing element tap options: %w", err) } - return eh.Tap(popts) //nolint:wrapcheck + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, eh.Tap(popts) //nolint:wrapcheck + }), nil }, "textContent": eh.TextContent, "type": eh.Type, @@ -462,12 +466,14 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { "selectOption": f.SelectOption, "setContent": f.SetContent, "setInputFiles": f.SetInputFiles, - "tap": func(selector string, opts goja.Value) error { + "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameTapOptions(f.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { - return fmt.Errorf("parsing frame tap options: %w", err) + return nil, fmt.Errorf("parsing frame tap options: %w", err) } - return f.Tap(selector, popts) //nolint:wrapcheck + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, f.Tap(selector, popts) //nolint:wrapcheck + }), nil }, "textContent": f.TextContent, "title": f.Title, @@ -721,12 +727,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping { "setExtraHTTPHeaders": p.SetExtraHTTPHeaders, "setInputFiles": p.SetInputFiles, "setViewportSize": p.SetViewportSize, - "tap": func(selector string, opts goja.Value) error { + "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameTapOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { - return fmt.Errorf("parsing page tap options: %w", err) + return nil, fmt.Errorf("parsing page tap options: %w", err) } - return p.Tap(selector, popts) //nolint:wrapcheck + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Tap(selector, popts) //nolint:wrapcheck + }), nil }, "textContent": p.TextContent, "throttleCPU": p.ThrottleCPU, diff --git a/browser/mapping_test.go b/browser/mapping_test.go index 7c8951b0a..b17b4ef81 100644 --- a/browser/mapping_test.go +++ b/browser/mapping_test.go @@ -341,7 +341,7 @@ type pageAPI interface { SetExtraHTTPHeaders(headers map[string]string) SetInputFiles(selector string, files goja.Value, opts goja.Value) SetViewportSize(viewportSize goja.Value) - Tap(selector string, opts goja.Value) error + Tap(selector string, opts goja.Value) (*goja.Promise, error) TextContent(selector string, opts goja.Value) string ThrottleCPU(common.CPUProfile) error ThrottleNetwork(common.NetworkProfile) error @@ -413,7 +413,7 @@ type frameAPI interface { SelectOption(selector string, values goja.Value, opts goja.Value) []string SetContent(html string, opts goja.Value) SetInputFiles(selector string, files goja.Value, opts goja.Value) - Tap(selector string, opts goja.Value) error + Tap(selector string, opts goja.Value) (*goja.Promise, error) TextContent(selector string, opts goja.Value) string Title() string Type(selector string, text string, opts goja.Value) @@ -458,7 +458,7 @@ type elementHandleAPI interface { SelectOption(values goja.Value, opts goja.Value) []string SelectText(opts goja.Value) SetInputFiles(files goja.Value, opts goja.Value) - Tap(opts goja.Value) error + Tap(opts goja.Value) (*goja.Promise, error) TextContent() string Type(text string, opts goja.Value) Uncheck(opts goja.Value) @@ -533,7 +533,7 @@ type locatorAPI interface { Press(key string, opts goja.Value) Type(text string, opts goja.Value) Hover(opts goja.Value) - Tap(opts goja.Value) error + Tap(opts goja.Value) (*goja.Promise, error) DispatchEvent(typ string, eventInit, opts goja.Value) WaitFor(opts goja.Value) }