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

Commit

Permalink
Refactor TouchScreen.Tap to return error
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Apr 18, 2024
1 parent 2c37152 commit d97b260
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion browser/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ type keyboardAPI interface { //nolint: unused
// mapping is not tested using this interface. We use the concrete type
// without testing its exported methods.
type touchscreenAPI interface { //nolint: unused
Tap(x float64, y float64)
Tap(x float64, y float64) error
}

// mouseAPI is the interface of a mouse input device.
Expand Down
14 changes: 8 additions & 6 deletions common/touchscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package common

import (
"context"

"github.com/grafana/xk6-browser/k6ext"
"fmt"

"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/input"
Expand Down Expand Up @@ -31,19 +30,22 @@ func (t *Touchscreen) tap(x float64, y float64) error {
action := input.DispatchTouchEvent(input.TouchStart, []*input.TouchPoint{{X: x, Y: y}}).
WithModifiers(input.Modifier(t.keyboard.modifiers))
if err := action.Do(cdp.WithExecutor(t.ctx, t.session)); err != nil {
return err
return fmt.Errorf("touch start: %w", err)
}

action = input.DispatchTouchEvent(input.TouchEnd, []*input.TouchPoint{}).
WithModifiers(input.Modifier(t.keyboard.modifiers))
if err := action.Do(cdp.WithExecutor(t.ctx, t.session)); err != nil {
return err
return fmt.Errorf("touch end: %w", err)
}

return nil
}

// Tap dispatches a tap start and tap end event.
func (t *Touchscreen) Tap(x float64, y float64) {
func (t *Touchscreen) Tap(x float64, y float64) error {
if err := t.tap(x, y); err != nil {
k6ext.Panic(t.ctx, "tapping: %w", err)
return fmt.Errorf("tapping: %w", err)
}
return nil
}

0 comments on commit d97b260

Please sign in to comment.