fix: panic by nil pointer

This commit is contained in:
lilong.129
2024-09-12 11:12:05 +08:00
parent 6f6cefe4bc
commit a87a4ea680
4 changed files with 20 additions and 6 deletions
+3
View File
@@ -8,5 +8,8 @@ import (
func (dExt *DriverExt) Input(text string) (err error) {
err = dExt.Driver.Input(text)
if err != nil {
return errors.Wrap(code.MobileUIInputError, err.Error())
}
return nil
}
-1
View File
@@ -172,7 +172,6 @@ func (dExt *DriverExt) GetScreenShot(fileName string) (raw *bytes.Buffer, path s
return nil, "", errors.Wrap(code.DeviceScreenShotError,
fmt.Sprintf("save screenshot file failed: %s", err.Error()))
}
log.Debug().Str("path", path).Msg("save screenshot file success")
return compressed, path, nil
}
+3
View File
@@ -35,8 +35,11 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...
toX = float64(width) * toX
toY = float64(height) * toY
err = dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...)
if err != nil {
return errors.Wrap(code.MobileUISwipeError, err.Error())
}
return nil
}
func (dExt *DriverExt) SwipeTo(direction string, options ...ActionOption) (err error) {
switch direction {
+9
View File
@@ -11,8 +11,11 @@ import (
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
// tap on absolute coordinate [x, y]
err := dExt.Driver.TapFloat(x, y, options...)
if err != nil {
return errors.Wrap(code.MobileUITapError, err.Error())
}
return nil
}
func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error {
// tap on [x, y] percent of window size
@@ -88,8 +91,11 @@ func (dExt *DriverExt) DoubleTapXY(x, y float64, options ...ActionOption) error
x = x * float64(windowSize.Width)
y = y * float64(windowSize.Height)
err = dExt.Driver.DoubleTapFloat(x, y, options...)
if err != nil {
return errors.Wrap(code.MobileUITapError, err.Error())
}
return nil
}
func (dExt *DriverExt) DoubleTap(param string, options ...ActionOption) (err error) {
return dExt.DoubleTapOffset(param, 0, 0, options...)
@@ -102,5 +108,8 @@ func (dExt *DriverExt) DoubleTapOffset(param string, xOffset, yOffset float64, o
}
err = dExt.Driver.DoubleTapFloat(point.X+xOffset, point.Y+yOffset, options...)
if err != nil {
return errors.Wrap(code.MobileUITapError, err.Error())
}
return nil
}