diff --git a/browser/mapping.go b/browser/mapping.go index 480cf6726..a110e69af 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -327,11 +327,16 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping { } return rt.ToValue(mcfs).ToObject(rt) }, - "click": func(selector string, opts goja.Value) *goja.Promise { + "click": func(selector string, opts goja.Value) (*goja.Promise, error) { + popts, err := parseFrameClickOptions(vu.Context(), opts, f.Timeout()) + if err != nil { + return nil, err + } + return k6ext.Promise(vu.Context(), func() (any, error) { - err := f.Click(selector, opts) + err := f.Click(selector, popts) return nil, err //nolint:wrapcheck - }) + }), nil }, "content": f.Content, "dblclick": f.Dblclick, diff --git a/common/frame.go b/common/frame.go index 90bb53557..c0e6a8d8f 100644 --- a/common/frame.go +++ b/common/frame.go @@ -545,14 +545,10 @@ func (f *Frame) ChildFrames() []*Frame { } // Click clicks the first element found that matches selector. -func (f *Frame) Click(selector string, opts goja.Value) error { +func (f *Frame) Click(selector string, opts *FrameClickOptions) error { f.log.Debugf("Frame:Click", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) - popts := NewFrameClickOptions(f.defaultTimeout()) - if err := popts.Parse(f.ctx, opts); err != nil { - k6ext.Panic(f.ctx, "parsing click options %q: %w", selector, err) - } - if err := f.click(selector, popts); err != nil { + if err := f.click(selector, opts); err != nil { return fmt.Errorf("clicking on %q: %w", selector, err) } diff --git a/common/page.go b/common/page.go index 12f270bc3..3b5be5c40 100644 --- a/common/page.go +++ b/common/page.go @@ -652,7 +652,12 @@ func (p *Page) IsChecked(selector string, opts goja.Value) bool { func (p *Page) Click(selector string, opts goja.Value) error { p.logger.Debugf("Page:Click", "sid:%v selector:%s", p.sessionID(), selector) - return p.MainFrame().Click(selector, opts) //nolint:wrapcheck + popts := NewFrameClickOptions(p.defaultTimeout()) + if err := popts.Parse(p.ctx, opts); err != nil { + k6ext.Panic(p.ctx, "parsing click options %q: %w", selector, err) + } + + return p.MainFrame().Click(selector, popts) } // Close closes the page. diff --git a/tests/launch_options_slowmo_test.go b/tests/launch_options_slowmo_test.go index c79a29870..48e344c28 100644 --- a/tests/launch_options_slowmo_test.go +++ b/tests/launch_options_slowmo_test.go @@ -172,7 +172,7 @@ func TestBrowserOptionsSlowMo(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withFileServer()) testFrameSlowMoImpl(t, tb, func(_ *testBrowser, f *common.Frame) { - err := f.Click("button", nil) + err := f.Click("button", common.NewFrameClickOptions(f.Timeout())) assert.NoError(t, err) }) })