feat: report MobileUITapError/MobileUISwipeError/MobileUIInputError

This commit is contained in:
lilong.129
2024-09-12 00:55:01 +08:00
parent 390bba5063
commit 9fc9e8620f
8 changed files with 44 additions and 20 deletions
+11 -2
View File
@@ -81,6 +81,9 @@ var (
var ( var (
MobileUIDriverError = errors.New("mobile UI driver error") // 70 MobileUIDriverError = errors.New("mobile UI driver error") // 70
MobileUILaunchAppError = errors.New("mobile UI launch app error") // 71 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 MobileUIValidationError = errors.New("mobile UI validation error") // 75
MobileUIAssertForegroundAppError = errors.New("mobile UI assert foreground app error") // 76 MobileUIAssertForegroundAppError = errors.New("mobile UI assert foreground app error") // 76
MobileUIAssertForegroundActivityError = errors.New("mobile UI assert foreground activity error") // 77 MobileUIAssertForegroundActivityError = errors.New("mobile UI assert foreground activity error") // 77
@@ -88,13 +91,15 @@ var (
LoopActionNotFoundError = errors.New("loop action not found error") // 79 LoopActionNotFoundError = errors.New("loop action not found error") // 79
) )
// CV related: [80, 90) // AI related: [80, 90)
var ( var (
CVEnvMissedError = errors.New("CV env missed error") // 80 CVEnvMissedError = errors.New("CV env missed error") // 80
CVRequestError = errors.New("CV prepare request error") // 81 CVRequestError = errors.New("CV prepare request error") // 81
CVServiceConnectionError = errors.New("CV service connect error") // 82 CVServiceConnectionError = errors.New("CV service connect error") // 82
CVResponseError = errors.New("CV parse response error") // 83 CVResponseError = errors.New("CV parse response error") // 83
CVResultNotFoundError = errors.New("CV result not found") // 84 CVResultNotFoundError = errors.New("CV result not found") // 84
ContextUnknowError = errors.New("detect context failed") // 85
) )
// trackings related: [90, 100) // trackings related: [90, 100)
@@ -160,18 +165,22 @@ var errorsMap = map[error]int{
// UI automation related // UI automation related
MobileUIDriverError: 70, MobileUIDriverError: 70,
MobileUILaunchAppError: 71, MobileUILaunchAppError: 71,
MobileUITapError: 72,
MobileUISwipeError: 73,
MobileUIInputError: 74,
MobileUIValidationError: 75, MobileUIValidationError: 75,
MobileUIAssertForegroundAppError: 76, MobileUIAssertForegroundAppError: 76,
MobileUIAssertForegroundActivityError: 77, MobileUIAssertForegroundActivityError: 77,
MobileUIPopupError: 78, MobileUIPopupError: 78,
LoopActionNotFoundError: 79, LoopActionNotFoundError: 79,
// OCR related // AI related
CVEnvMissedError: 80, CVEnvMissedError: 80,
CVRequestError: 81, CVRequestError: 81,
CVServiceConnectionError: 82, CVServiceConnectionError: 82,
CVResponseError: 83, CVResponseError: 83,
CVResultNotFoundError: 84, CVResultNotFoundError: 84,
ContextUnknowError: 85,
// trackings related // trackings related
TrackingGetError: 90, TrackingGetError: 90,
+3 -3
View File
@@ -307,11 +307,11 @@ func (ad *adbDriver) TapFloat(x, y float64, options ...ActionOption) (err error)
return nil return nil
} }
func (ad *adbDriver) DoubleTap(x, y int) error { func (ad *adbDriver) DoubleTap(x, y int, options ...ActionOption) error {
return ad.DoubleTapFloat(float64(x), float64(y)) 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 // adb shell input tap x y
xStr := fmt.Sprintf("%.1f", x) xStr := fmt.Sprintf("%.1f", x)
yStr := fmt.Sprintf("%.1f", y) yStr := fmt.Sprintf("%.1f", y)
+1 -1
View File
@@ -294,7 +294,7 @@ func (ud *uiaDriver) Orientation() (orientation Orientation, err error) {
return 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)) return ud.DoubleFloatTap(float64(x), float64(y))
} }
+8 -1
View File
@@ -1,5 +1,12 @@
package uixt package uixt
import (
"github.com/pkg/errors"
"github.com/httprunner/httprunner/v4/hrp/code"
)
func (dExt *DriverExt) Input(text string) (err error) { 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())
} }
+2 -2
View File
@@ -566,8 +566,8 @@ type IWebDriver interface {
TapFloat(x, y float64, options ...ActionOption) error TapFloat(x, y float64, options ...ActionOption) error
// DoubleTap Sends a double tap event at the coordinate. // DoubleTap Sends a double tap event at the coordinate.
DoubleTap(x, y int) error DoubleTap(x, y int, options ...ActionOption) error
DoubleTapFloat(x, y float64) error DoubleTapFloat(x, y float64, options ...ActionOption) error
// TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration. // TouchAndHold Initiates a long-press gesture at the coordinate, holding for the specified duration.
// second: The default value is 1 // second: The default value is 1
+3 -3
View File
@@ -499,11 +499,11 @@ func (wd *wdaDriver) TapFloat(x, y float64, options ...ActionOption) (err error)
return return
} }
func (wd *wdaDriver) DoubleTap(x, y int) error { func (wd *wdaDriver) DoubleTap(x, y int, options ...ActionOption) error {
return wd.DoubleTapFloat(float64(x), float64(y)) 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:)] // [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)]
data := map[string]interface{}{ data := map[string]interface{}{
"x": wd.toScale(x), "x": wd.toScale(x),
+2 -1
View File
@@ -34,7 +34,8 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...
fromY = float64(height) * fromY fromY = float64(height) * fromY
toX = float64(width) * toX toX = float64(width) * toX
toY = float64(height) * toY 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) { func (dExt *DriverExt) SwipeTo(direction string, options ...ActionOption) (err error) {
+14 -7
View File
@@ -2,11 +2,16 @@ package uixt
import ( import (
"fmt" "fmt"
"github.com/pkg/errors"
"github.com/httprunner/httprunner/v4/hrp/code"
) )
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error { func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
// tap on absolute coordinate [x, y] // 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 { 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...) 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 // double tap on coordinate: [x, y] should be relative
if x > 1 || y > 1 { if x > 1 || y > 1 {
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y) 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) x = x * float64(windowSize.Width)
y = y * float64(windowSize.Height) 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) { func (dExt *DriverExt) DoubleTap(param string, options ...ActionOption) (err error) {
return dExt.DoubleTapOffset(param, 0, 0) 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) point, err := dExt.FindUIRectInUIKit(param)
if err != nil { if err != nil {
return err 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())
} }