Skip to content

Commit

Permalink
Degojaify Locator.Tap
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Apr 17, 2024
1 parent e09c4a8 commit 61a9f20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 7 additions & 1 deletion browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 3 additions & 7 deletions common/locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 4 additions & 3 deletions tests/locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 61a9f20

Please sign in to comment.