Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Degojaify Page|Frame.Tap
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Apr 18, 2024
1 parent 95ec07c commit 446ffc0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
50 changes: 31 additions & 19 deletions browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,18 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping {
"selectOption": f.SelectOption,
"setContent": f.SetContent,
"setInputFiles": f.SetInputFiles,
"tap": f.Tap,
"textContent": f.TextContent,
"title": f.Title,
"type": f.Type,
"uncheck": f.Uncheck,
"url": f.URL,
"tap": func(selector string, opts goja.Value) 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 f.Tap(selector, popts) //nolint:wrapcheck
},
"textContent": f.TextContent,
"title": f.Title,
"type": f.Type,
"uncheck": f.Uncheck,
"url": f.URL,
"waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) {
js, popts, pargs, err := parseWaitForFunctionArgs(
vu.Context(), f.Timeout(), pageFunc, opts, args...,
Expand Down Expand Up @@ -709,19 +715,25 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
"setExtraHTTPHeaders": p.SetExtraHTTPHeaders,
"setInputFiles": p.SetInputFiles,
"setViewportSize": p.SetViewportSize,
"tap": p.Tap,
"textContent": p.TextContent,
"throttleCPU": p.ThrottleCPU,
"throttleNetwork": p.ThrottleNetwork,
"title": p.Title,
"touchscreen": rt.ToValue(p.GetTouchscreen()).ToObject(rt),
"type": p.Type,
"uncheck": p.Uncheck,
"unroute": p.Unroute,
"url": p.URL,
"video": p.Video,
"viewportSize": p.ViewportSize,
"waitForEvent": p.WaitForEvent,
"tap": func(selector string, opts goja.Value) 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 p.Tap(selector, popts) //nolint:wrapcheck
},
"textContent": p.TextContent,
"throttleCPU": p.ThrottleCPU,
"throttleNetwork": p.ThrottleNetwork,
"title": p.Title,
"touchscreen": rt.ToValue(p.GetTouchscreen()).ToObject(rt),
"type": p.Type,
"uncheck": p.Uncheck,
"unroute": p.Unroute,
"url": p.URL,
"video": p.Video,
"viewportSize": p.ViewportSize,
"waitForEvent": p.WaitForEvent,
"waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) {
js, popts, pargs, err := parseWaitForFunctionArgs(
vu.Context(), p.Timeout(), pageFunc, opts, args...,
Expand Down
8 changes: 2 additions & 6 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1549,14 +1549,10 @@ func (f *Frame) SetInputFiles(selector string, files goja.Value, opts goja.Value
}

// Tap the first element that matches the selector.
func (f *Frame) Tap(selector string, opts goja.Value) error {
func (f *Frame) Tap(selector string, opts *FrameTapOptions) error {
f.log.Debugf("Frame:Tap", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

popts := NewFrameTapOptions(f.defaultTimeout())
if err := popts.Parse(f.ctx, opts); err != nil {
return fmt.Errorf("parsing tap options: %w", err)
}
if err := f.tap(selector, popts); err != nil {
if err := f.tap(selector, opts); err != nil {
return fmt.Errorf("tapping on %q: %w", selector, err)
}

Expand Down
2 changes: 1 addition & 1 deletion common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ func (p *Page) SetViewportSize(viewportSize goja.Value) {
}

// Tap will tap the element matching the provided selector.
func (p *Page) Tap(selector string, opts goja.Value) error {
func (p *Page) Tap(selector string, opts *FrameTapOptions) error {
p.logger.Debugf("Page:SetViewportSize", "sid:%v selector:%s", p.sessionID(), selector)

return p.MainFrame().Tap(selector, opts)
Expand Down

0 comments on commit 446ffc0

Please sign in to comment.