mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 23:09:36 +08:00
refactor: move ios options to pkg/uixt/options
This commit is contained in:
118
pkg/uixt/ui_tap.go
Normal file
118
pkg/uixt/ui_tap.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package uixt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
)
|
||||
|
||||
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
|
||||
// tap on absolute coordinate [x, y]
|
||||
err := dExt.Driver.Tap(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
|
||||
if x > 1 || y > 1 {
|
||||
return fmt.Errorf("x, y percentage should be <= 1, got x=%v, y=%v", x, y)
|
||||
}
|
||||
|
||||
windowSize, err := dExt.Driver.WindowSize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x = x * float64(windowSize.Width)
|
||||
y = y * float64(windowSize.Height)
|
||||
return dExt.TapAbsXY(x, y, options...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) TapByOCR(ocrText string, options ...ActionOption) error {
|
||||
actionOptions := NewActionOptions(options...)
|
||||
if actionOptions.ScreenShotFileName == "" {
|
||||
options = append(options, WithScreenShotFileName(fmt.Sprintf("tap_by_ocr_%s", ocrText)))
|
||||
}
|
||||
|
||||
point, err := dExt.FindScreenText(ocrText, options...)
|
||||
if err != nil {
|
||||
if actionOptions.IgnoreNotFoundError {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return dExt.TapAbsXY(point.X, point.Y, options...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) TapByUIDetection(options ...ActionOption) error {
|
||||
actionOptions := NewActionOptions(options...)
|
||||
|
||||
point, err := dExt.FindUIResult(options...)
|
||||
if err != nil {
|
||||
if actionOptions.IgnoreNotFoundError {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return dExt.TapAbsXY(point.X, point.Y, options...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) Tap(param string, options ...ActionOption) error {
|
||||
return dExt.TapOffset(param, 0, 0, options...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) TapOffset(param string, xOffset, yOffset float64, options ...ActionOption) (err error) {
|
||||
actionOptions := NewActionOptions(options...)
|
||||
|
||||
point, err := dExt.FindUIRectInUIKit(param, options...)
|
||||
if err != nil {
|
||||
if actionOptions.IgnoreNotFoundError {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return dExt.TapAbsXY(point.X+xOffset, point.Y+yOffset, options...)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
windowSize, err := dExt.Driver.WindowSize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x = x * float64(windowSize.Width)
|
||||
y = y * float64(windowSize.Height)
|
||||
err = dExt.Driver.DoubleTap(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...)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) DoubleTapOffset(param string, xOffset, yOffset float64, options ...ActionOption) (err error) {
|
||||
point, err := dExt.FindUIRectInUIKit(param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = dExt.Driver.DoubleTap(point.X+xOffset, point.Y+yOffset, options...)
|
||||
if err != nil {
|
||||
return errors.Wrap(code.MobileUITapError, err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user