diff --git a/browser/mapping.go b/browser/mapping.go index fbfcb70e6..39bd91a43 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -53,8 +53,14 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { return lo.Clear(copts) //nolint:wrapcheck }, "click": func(opts goja.Value) *goja.Promise { + popts, err := parseFrameClickOptions(vu.Context(), opts, lo.Timeout()) + return k6ext.Promise(vu.Context(), func() (any, error) { - err := lo.Click(opts) + if err != nil { + return nil, err + } + + err = lo.Click(popts) return nil, err //nolint:wrapcheck }) }, diff --git a/common/locator.go b/common/locator.go index 04bb19533..c5a5ab7af 100644 --- a/common/locator.go +++ b/common/locator.go @@ -58,16 +58,12 @@ func (l *Locator) Timeout() time.Duration { } // Click on an element using locator's selector with strict mode on. -func (l *Locator) Click(opts goja.Value) error { +func (l *Locator) Click(opts *FrameClickOptions) error { l.log.Debugf("Locator:Click", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) _, span := TraceAPICall(l.ctx, l.frame.page.targetID.String(), "locator.click") defer span.End() - copts := NewFrameClickOptions(l.frame.defaultTimeout()) - if err := copts.Parse(l.ctx, opts); err != nil { - return fmt.Errorf("parsing click options: %w", err) - } - if err := l.click(copts); err != nil { + if err := l.click(opts); err != nil { return fmt.Errorf("clicking on %q: %w", l.selector, err) } diff --git a/tests/locator_test.go b/tests/locator_test.go index 0b9353e4d..4344ddd43 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -69,7 +69,8 @@ func TestLocator(t *testing.T) { }, { "Click", func(tb *testBrowser, p *common.Page) { - err := p.Locator("#link", nil).Click(nil) + l := p.Locator("#link", nil) + err := l.Click(common.NewFrameClickOptions(l.Timeout())) require.NoError(t, err) v := p.Evaluate(tb.toGojaValue(`() => window.result`)) require.True(t, tb.asGojaBool(v), "cannot not click the link") @@ -260,7 +261,7 @@ func TestLocator(t *testing.T) { }, { "Click", func(l *common.Locator, tb *testBrowser) { - err := l.Click(timeout(tb)) + err := l.Click(common.NewFrameClickOptions(100 * time.Millisecond)) if err != nil { // TODO: remove panic and update tests when all locator methods return error. panic(err)