fix: DoubleTapXY

This commit is contained in:
lilong.129
2025-02-12 15:25:20 +08:00
parent 17292cb112
commit db23459250
7 changed files with 22 additions and 39 deletions

View File

@@ -303,10 +303,14 @@ func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
}
func (ad *ADBDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
var err error
if x, y, err = convertToAbsolutePoint(ad, x, y); err != nil {
return err
}
// adb shell input tap x y
xStr := fmt.Sprintf("%.1f", x)
yStr := fmt.Sprintf("%.1f", y)
_, err := ad.runShellCommand(
_, err = ad.runShellCommand(
"input", "tap", xStr, yStr)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("tap <%s, %s> failed", xStr, yStr))

View File

@@ -237,10 +237,10 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
}
func (ud *UIA2Driver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
return ud.DoubleFloatTap(x, y)
}
func (ud *UIA2Driver) DoubleFloatTap(x, y float64) error {
var err error
if x, y, err = convertToAbsolutePoint(ud, x, y); err != nil {
return err
}
data := map[string]interface{}{
"actions": []interface{}{
map[string]interface{}{
@@ -258,7 +258,7 @@ func (ud *UIA2Driver) DoubleFloatTap(x, y float64) error {
},
}
_, err := ud.httpPOST(data, "/session", ud.Session.ID, "actions/tap")
_, err = ud.httpPOST(data, "/session", ud.Session.ID, "actions/tap")
return err
}

View File

@@ -1,3 +1,5 @@
//go:build localtest
package uixt
import (

View File

@@ -3,9 +3,6 @@ package uixt
import (
"fmt"
"github.com/pkg/errors"
"github.com/httprunner/httprunner/v5/code"
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
)
@@ -39,22 +36,3 @@ func (dExt *XTDriver) TapByCV(opts ...option.ActionOption) error {
return dExt.TapAbsXY(point.X, point.Y, opts...)
}
func (dExt *XTDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
// double tap on coordinate: [x, y] should be relative
if x > 1 || y > 1 {
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
}
windowSize, err := dExt.WindowSize()
if err != nil {
return err
}
x = x * float64(windowSize.Width)
y = y * float64(windowSize.Height)
err = dExt.DoubleTapXY(x, y, opts...)
if err != nil {
return errors.Wrap(code.MobileUITapError, err.Error())
}
return nil
}

View File

@@ -1,3 +1,5 @@
//go:build localtest
package uixt
import (

View File

@@ -545,24 +545,21 @@ func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
return err
}
func (wd *WDADriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) (err error) {
func (wd *WDADriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
// [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
actionOptions := option.NewActionOptions(opts...)
var err error
if x, y, err = convertToAbsolutePoint(wd, x, y); err != nil {
return err
}
x = wd.toScale(x)
y = wd.toScale(y)
if len(actionOptions.Offset) == 2 {
x += float64(actionOptions.Offset[0])
y += float64(actionOptions.Offset[1])
}
x += actionOptions.GetRandomOffset()
y += actionOptions.GetRandomOffset()
data := map[string]interface{}{
"x": x,
"y": y,
}
_, err = wd.httpPOST(data, "/session", wd.Session.ID, "/wda/doubleTap")
return
return err
}
func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) {