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

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