DoubleTap支持绝对坐标

This commit is contained in:
余泓铮
2025-02-24 11:50:36 +08:00
parent 3b509ba6c6
commit 165aab0dc8
8 changed files with 24 additions and 27 deletions

View File

@@ -312,12 +312,15 @@ func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
return nil
}
func (ad *ADBDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
var err error
if x, y, err = convertToAbsolutePoint(ad, x, y); err != nil {
return err
}
actionOptions := option.NewActionOptions(opts...)
if !actionOptions.AbsCoordinate {
x, y, err = convertToAbsolutePoint(ad, x, y)
if err != nil {
return err
}
}
x, y = actionOptions.ApplyOffset(x, y)
// adb shell input tap x y
@@ -542,12 +545,12 @@ func (ad *ADBDriver) SetRotation(rotation types.Rotation) (err error) {
}
func (ad *ADBDriver) ScreenShot(opts ...option.ActionOption) (raw *bytes.Buffer, err error) {
resp, err := ad.runShellCommand("screencap", "-p")
resp, err := ad.Device.ScreenCap()
if err != nil {
return nil, errors.Wrapf(code.DeviceScreenShotError,
"adb screencap failed %v", err)
}
raw = bytes.NewBuffer([]byte(resp))
raw = bytes.NewBuffer(resp)
actionOptions := option.NewActionOptions(opts...)
if actionOptions.ScreenShotFileName != "" {

View File

@@ -252,12 +252,15 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) {
return
}
func (ud *UIA2Driver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
var err error
if x, y, err = convertToAbsolutePoint(ud, x, y); err != nil {
return err
}
actionOptions := option.NewActionOptions(opts...)
if !actionOptions.AbsCoordinate {
x, y, err = convertToAbsolutePoint(ud, x, y)
if err != nil {
return err
}
}
x, y = actionOptions.ApplyOffset(x, y)
data := map[string]interface{}{

View File

@@ -290,15 +290,6 @@ func (wd *BrowserWebDriver) Hover(x, y float64) (err error) {
return err
}
func (wd *BrowserWebDriver) DoubleTapXY(x, y float64, option ...option.ActionOption) (err error) {
data := map[string]interface{}{
"x": x,
"y": y,
}
_, err = wd.HttpPOST(data, wd.sessionId, "ui/double_tap")
return err
}
func (wd *BrowserWebDriver) Input(text string, option ...option.ActionOption) (err error) {
data := map[string]interface{}{
"text": text,

View File

@@ -50,9 +50,9 @@ type IDriver interface {
Unlock() error
Back() error
// tap
TapXY(x, y float64, opts ...option.ActionOption) error // by percentage
TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
DoubleTapXY(x, y float64, opts ...option.ActionOption) error // by percentage
TapXY(x, y float64, opts ...option.ActionOption) error // by percentage
TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
DoubleTap(x, y float64, opts ...option.ActionOption) error // by percentage
TouchAndHold(x, y float64, opts ...option.ActionOption) error
// swipe
Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error

View File

@@ -220,7 +220,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
return fmt.Errorf("invalid tap location params: %v", params)
}
x, y := params[0], params[1]
return dExt.DoubleTapXY(x, y)
return dExt.DoubleTap(x, y)
}
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTapXY, action.Params)
case ACTION_Swipe:

View File

@@ -46,7 +46,7 @@ func NewStubAndroidDriver(dev *uixt.AndroidDevice) (*StubAndroidDriver, error) {
}
// setup driver
if err := driver.Setup(); err != nil {
if err = driver.Setup(); err != nil {
return nil, err
}

View File

@@ -161,7 +161,7 @@ func (hd *HDCDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error {
ghdc.NewGesture().Start(ghdc.Point{X: int(x), Y: int(y)}).Pause(100))
}
func (hd *HDCDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
func (hd *HDCDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error {
return types.ErrDriverNotImplemented
}