feat: report MobileUITapError/MobileUISwipeError/MobileUIInputError

This commit is contained in:
lilong.129
2024-09-12 00:49:08 +08:00
parent 390bba5063
commit 9fc9e8620f
8 changed files with 44 additions and 20 deletions

View File

@@ -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,

View File

@@ -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)

View File

@@ -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))
}

View File

@@ -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())
}

View File

@@ -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

View File

@@ -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),

View File

@@ -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) {

View File

@@ -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())
}