From 165aab0dc8562916652503f78ca18b2f504ab07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B3=93=E9=93=AE?= Date: Mon, 24 Feb 2025 11:50:36 +0800 Subject: [PATCH] =?UTF-8?q?DoubleTap=E6=94=AF=E6=8C=81=E7=BB=9D=E5=AF=B9?= =?UTF-8?q?=E5=9D=90=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/uixt/android_driver_adb.go | 15 +++++++++------ pkg/uixt/android_driver_uia2.go | 11 +++++++---- pkg/uixt/browser_web_driver.go | 9 --------- pkg/uixt/driver.go | 6 +++--- pkg/uixt/driver_action.go | 2 +- pkg/uixt/driver_ext/android_stub_driver.go | 2 +- pkg/uixt/harmony_driver_hdc.go | 2 +- server/ui.go | 4 ++-- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index 7bb66216..9e689f47 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -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 != "" { diff --git a/pkg/uixt/android_driver_uia2.go b/pkg/uixt/android_driver_uia2.go index e58e12a0..3f9a42d4 100644 --- a/pkg/uixt/android_driver_uia2.go +++ b/pkg/uixt/android_driver_uia2.go @@ -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{}{ diff --git a/pkg/uixt/browser_web_driver.go b/pkg/uixt/browser_web_driver.go index d1b33864..7a803216 100644 --- a/pkg/uixt/browser_web_driver.go +++ b/pkg/uixt/browser_web_driver.go @@ -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, diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index 25e5b903..dd39f3e4 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -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 diff --git a/pkg/uixt/driver_action.go b/pkg/uixt/driver_action.go index 67d4fa84..ebb67875 100644 --- a/pkg/uixt/driver_action.go +++ b/pkg/uixt/driver_action.go @@ -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: diff --git a/pkg/uixt/driver_ext/android_stub_driver.go b/pkg/uixt/driver_ext/android_stub_driver.go index 22d2e8a4..a2e0de76 100644 --- a/pkg/uixt/driver_ext/android_stub_driver.go +++ b/pkg/uixt/driver_ext/android_stub_driver.go @@ -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 } diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 6be1fa98..4644e91b 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -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 } diff --git a/server/ui.go b/server/ui.go index 77cb48de..962ddbcd 100644 --- a/server/ui.go +++ b/server/ui.go @@ -105,9 +105,9 @@ func (r *Router) doubleTapHandler(c *gin.Context) { } if tapReq.X < 1 && tapReq.Y < 1 { - err = driver.DoubleTapXY(tapReq.X, tapReq.Y) + err = driver.DoubleTap(tapReq.X, tapReq.Y) } else { - err = driver.DoubleTapXY(tapReq.X, tapReq.Y, + err = driver.DoubleTap(tapReq.X, tapReq.Y, option.WithAbsoluteCoordinate(true)) }