From 9fc9e8620fa14637144f0e380dc316b65c31e08b Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 12 Sep 2024 00:49:08 +0800 Subject: [PATCH] feat: report MobileUITapError/MobileUISwipeError/MobileUIInputError --- hrp/code/code.go | 13 +++++++++++-- hrp/pkg/uixt/android_adb_driver.go | 6 +++--- hrp/pkg/uixt/android_uia2_driver.go | 2 +- hrp/pkg/uixt/input.go | 9 ++++++++- hrp/pkg/uixt/interface.go | 4 ++-- hrp/pkg/uixt/ios_driver.go | 6 +++--- hrp/pkg/uixt/swipe.go | 3 ++- hrp/pkg/uixt/tap.go | 21 ++++++++++++++------- 8 files changed, 44 insertions(+), 20 deletions(-) diff --git a/hrp/code/code.go b/hrp/code/code.go index ce831d9a..7cb72b0c 100644 --- a/hrp/code/code.go +++ b/hrp/code/code.go @@ -81,6 +81,9 @@ var ( var ( MobileUIDriverError = errors.New("mobile UI driver error") // 70 MobileUILaunchAppError = errors.New("mobile UI launch app error") // 71 + MobileUITapError = errors.New("mobile UI tap error") // 72 + MobileUISwipeError = errors.New("mobile UI swipe error") // 73 + MobileUIInputError = errors.New("mobile UI input error") // 74 MobileUIValidationError = errors.New("mobile UI validation error") // 75 MobileUIAssertForegroundAppError = errors.New("mobile UI assert foreground app error") // 76 MobileUIAssertForegroundActivityError = errors.New("mobile UI assert foreground activity error") // 77 @@ -88,13 +91,15 @@ var ( LoopActionNotFoundError = errors.New("loop action not found error") // 79 ) -// CV related: [80, 90) +// AI related: [80, 90) var ( CVEnvMissedError = errors.New("CV env missed error") // 80 CVRequestError = errors.New("CV prepare request error") // 81 CVServiceConnectionError = errors.New("CV service connect error") // 82 CVResponseError = errors.New("CV parse response error") // 83 CVResultNotFoundError = errors.New("CV result not found") // 84 + + ContextUnknowError = errors.New("detect context failed") // 85 ) // trackings related: [90, 100) @@ -160,18 +165,22 @@ var errorsMap = map[error]int{ // UI automation related MobileUIDriverError: 70, MobileUILaunchAppError: 71, + MobileUITapError: 72, + MobileUISwipeError: 73, + MobileUIInputError: 74, MobileUIValidationError: 75, MobileUIAssertForegroundAppError: 76, MobileUIAssertForegroundActivityError: 77, MobileUIPopupError: 78, LoopActionNotFoundError: 79, - // OCR related + // AI related CVEnvMissedError: 80, CVRequestError: 81, CVServiceConnectionError: 82, CVResponseError: 83, CVResultNotFoundError: 84, + ContextUnknowError: 85, // trackings related TrackingGetError: 90, diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index 25babd71..f93af368 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -307,11 +307,11 @@ func (ad *adbDriver) TapFloat(x, y float64, options ...ActionOption) (err error) return nil } -func (ad *adbDriver) DoubleTap(x, y int) error { - return ad.DoubleTapFloat(float64(x), float64(y)) +func (ad *adbDriver) DoubleTap(x, y int, options ...ActionOption) error { + return ad.DoubleTapFloat(float64(x), float64(y), options...) } -func (ad *adbDriver) DoubleTapFloat(x, y float64) (err error) { +func (ad *adbDriver) DoubleTapFloat(x, y float64, options ...ActionOption) (err error) { // adb shell input tap x y xStr := fmt.Sprintf("%.1f", x) yStr := fmt.Sprintf("%.1f", y) diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index 01ab463f..db04063c 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -294,7 +294,7 @@ func (ud *uiaDriver) Orientation() (orientation Orientation, err error) { return } -func (ud *uiaDriver) DoubleTap(x, y int) error { +func (ud *uiaDriver) DoubleTap(x, y int, options ...ActionOption) error { return ud.DoubleFloatTap(float64(x), float64(y)) } diff --git a/hrp/pkg/uixt/input.go b/hrp/pkg/uixt/input.go index f23df857..c9d36607 100644 --- a/hrp/pkg/uixt/input.go +++ b/hrp/pkg/uixt/input.go @@ -1,5 +1,12 @@ package uixt +import ( + "github.com/pkg/errors" + + "github.com/httprunner/httprunner/v4/hrp/code" +) + func (dExt *DriverExt) Input(text string) (err error) { - return dExt.Driver.Input(text) + err = dExt.Driver.Input(text) + return errors.Wrap(code.MobileUIInputError, err.Error()) } diff --git a/hrp/pkg/uixt/interface.go b/hrp/pkg/uixt/interface.go index c9440fca..b6f30995 100644 --- a/hrp/pkg/uixt/interface.go +++ b/hrp/pkg/uixt/interface.go @@ -566,8 +566,8 @@ type IWebDriver interface { TapFloat(x, y float64, options ...ActionOption) error // DoubleTap Sends a double tap event at the coordinate. - DoubleTap(x, y int) error - DoubleTapFloat(x, y float64) error + DoubleTap(x, y int, options ...ActionOption) error + DoubleTapFloat(x, y float64, options ...ActionOption) error // TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration. // second: The default value is 1 diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index e8e23d0d..1e8e036a 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -499,11 +499,11 @@ func (wd *wdaDriver) TapFloat(x, y float64, options ...ActionOption) (err error) return } -func (wd *wdaDriver) DoubleTap(x, y int) error { - return wd.DoubleTapFloat(float64(x), float64(y)) +func (wd *wdaDriver) DoubleTap(x, y int, options ...ActionOption) error { + return wd.DoubleTapFloat(float64(x), float64(y), options...) } -func (wd *wdaDriver) DoubleTapFloat(x, y float64) (err error) { +func (wd *wdaDriver) DoubleTapFloat(x, y float64, options ...ActionOption) (err error) { // [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)] data := map[string]interface{}{ "x": wd.toScale(x), diff --git a/hrp/pkg/uixt/swipe.go b/hrp/pkg/uixt/swipe.go index 2b190381..f30b92c4 100644 --- a/hrp/pkg/uixt/swipe.go +++ b/hrp/pkg/uixt/swipe.go @@ -34,7 +34,8 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ... fromY = float64(height) * fromY toX = float64(width) * toX toY = float64(height) * toY - return dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...) + err = dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...) + return errors.Wrap(code.MobileUISwipeError, err.Error()) } func (dExt *DriverExt) SwipeTo(direction string, options ...ActionOption) (err error) { diff --git a/hrp/pkg/uixt/tap.go b/hrp/pkg/uixt/tap.go index 345ca8bd..4893c414 100644 --- a/hrp/pkg/uixt/tap.go +++ b/hrp/pkg/uixt/tap.go @@ -2,11 +2,16 @@ package uixt import ( "fmt" + + "github.com/pkg/errors" + + "github.com/httprunner/httprunner/v4/hrp/code" ) func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error { // tap on absolute coordinate [x, y] - return dExt.Driver.TapFloat(x, y, options...) + err := dExt.Driver.TapFloat(x, y, options...) + return errors.Wrap(code.MobileUITapError, err.Error()) } func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error { @@ -70,7 +75,7 @@ func (dExt *DriverExt) TapOffset(param string, xOffset, yOffset float64, options return dExt.TapAbsXY(point.X+xOffset, point.Y+yOffset, options...) } -func (dExt *DriverExt) DoubleTapXY(x, y float64) error { +func (dExt *DriverExt) DoubleTapXY(x, y float64, options ...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) @@ -82,18 +87,20 @@ func (dExt *DriverExt) DoubleTapXY(x, y float64) error { } x = x * float64(windowSize.Width) y = y * float64(windowSize.Height) - return dExt.Driver.DoubleTapFloat(x, y) + err = dExt.Driver.DoubleTapFloat(x, y, options...) + return errors.Wrap(code.MobileUITapError, err.Error()) } -func (dExt *DriverExt) DoubleTap(param string) (err error) { - return dExt.DoubleTapOffset(param, 0, 0) +func (dExt *DriverExt) DoubleTap(param string, options ...ActionOption) (err error) { + return dExt.DoubleTapOffset(param, 0, 0, options...) } -func (dExt *DriverExt) DoubleTapOffset(param string, xOffset, yOffset float64) (err error) { +func (dExt *DriverExt) DoubleTapOffset(param string, xOffset, yOffset float64, options ...ActionOption) (err error) { point, err := dExt.FindUIRectInUIKit(param) if err != nil { return err } - return dExt.Driver.DoubleTapFloat(point.X+xOffset, point.Y+yOffset) + err = dExt.Driver.DoubleTapFloat(point.X+xOffset, point.Y+yOffset, options...) + return errors.Wrap(code.MobileUITapError, err.Error()) }