diff --git a/browser/mapping.go b/browser/mapping.go index b8b8b1944..4813f5230 100644 --- a/browser/mapping.go +++ b/browser/mapping.go @@ -82,7 +82,13 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping { "press": lo.Press, "type": lo.Type, "hover": lo.Hover, - "tap": lo.Tap, + "tap": func(opts goja.Value) error { + copts := common.NewFrameTapOptions(lo.DefaultTimeout()) + if err := copts.Parse(vu.Context(), opts); err != nil { + return fmt.Errorf("parsing tap options: %w", err) + } + return lo.Tap(copts) //nolint:wrapcheck + }, "dispatchEvent": func(typ string, eventInit, opts goja.Value) error { popts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout()) if err := popts.Parse(vu.Context(), opts); err != nil { diff --git a/common/locator.go b/common/locator.go index a8aeed2f1..6f859cb67 100644 --- a/common/locator.go +++ b/common/locator.go @@ -561,15 +561,11 @@ func (l *Locator) hover(opts *FrameHoverOptions) error { } // Tap the element found that matches the locator's selector with strict mode on. -func (l *Locator) Tap(opts goja.Value) error { +func (l *Locator) Tap(opts *FrameTapOptions) error { l.log.Debugf("Locator:Tap", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) - copts := NewFrameTapOptions(l.frame.defaultTimeout()) - if err := copts.Parse(l.ctx, opts); err != nil { - return fmt.Errorf("parsing tap options: %w", err) - } - copts.Strict = true - if err := l.frame.tap(l.selector, copts); err != nil { + opts.Strict = true + if err := l.frame.tap(l.selector, opts); err != nil { return fmt.Errorf("tapping on %q: %w", l.selector, err) } diff --git a/tests/locator_test.go b/tests/locator_test.go index 2da9467f9..65b44c76b 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -196,7 +196,8 @@ func TestLocator(t *testing.T) { return asBool(t, v) } require.False(t, result(), "should not be tapped first") - err := p.Locator("#inputText", nil).Tap(nil) + opts := common.NewFrameTapOptions(common.DefaultTimeout) + err := p.Locator("#inputText", nil).Tap(opts) require.NoError(t, err) require.True(t, result(), "should be tapped") }, @@ -333,8 +334,8 @@ func TestLocator(t *testing.T) { "SelectOption", func(l *common.Locator, tb *testBrowser) { l.SelectOption(tb.toGojaValue(""), timeout(tb)) }, }, { - "Tap", func(l *common.Locator, tb *testBrowser) { - if err := l.Tap(timeout(tb)); err != nil { + "Tap", func(l *common.Locator, _ *testBrowser) { + if err := l.Tap(common.NewFrameTapOptions(100 * time.Millisecond)); err != nil { // TODO: remove panic and update tests when all locator methods return error. panic(err) }