change: remove unused tap methods

This commit is contained in:
lilong.129
2025-02-11 17:49:24 +08:00
parent 30c0bd7488
commit 792d3ae9bc
10 changed files with 17 additions and 127 deletions

View File

@@ -58,9 +58,9 @@ type IDriver interface {
Unlock() error
Back() error
// tap
TapXY(x, y float64, opts ...option.ActionOption) error // tap on [x, y] percent of window size
TapAbsXY(x, y float64, opts ...option.ActionOption) error
DoubleTapXY(x, y float64, opts ...option.ActionOption) error
TapXY(x, y float64, opts ...option.ActionOption) error // by percentage
TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
DoubleTapXY(x, y float64, opts ...option.ActionOption) error // by percentage
TouchAndHold(x, y float64, opts ...option.ActionOption) error
TapByText(text string, opts ...option.ActionOption) error // TODO: remove
TapByTexts(actions ...TapTextAction) error // TODO: remove
@@ -99,12 +99,9 @@ type IDriverExt interface {
GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.OCRTexts, err error)
GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error)
// tap
TapByOCR(ocrText string, opts ...option.ActionOption) error
TapXY(x, y float64, opts ...option.ActionOption) error
TapAbsXY(x, y float64, opts ...option.ActionOption) error
TapOffset(param string, xOffset, yOffset float64, opts ...option.ActionOption) error
TapByUIDetection(opts ...option.ActionOption) error
// tap with AI
TapByOCR(text string, opts ...option.ActionOption) error
TapByCV(opts ...option.ActionOption) error
// swipe
SwipeRelative(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error

View File

@@ -41,9 +41,7 @@ const (
ACTION_TapAbsXY ActionMethod = "tap_abs_xy"
ACTION_TapByOCR ActionMethod = "tap_ocr"
ACTION_TapByCV ActionMethod = "tap_cv"
ACTION_Tap ActionMethod = "tap"
ACTION_DoubleTapXY ActionMethod = "double_tap_xy"
ACTION_DoubleTap ActionMethod = "double_tap"
ACTION_Swipe ActionMethod = "swipe"
ACTION_Input ActionMethod = "input"
ACTION_Back ActionMethod = "back"
@@ -234,11 +232,6 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
return dExt.TapAbsXY(x, y, action.GetOptions()...)
}
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
case ACTION_Tap:
if param, ok := action.Params.(string); ok {
return dExt.Tap(param, action.GetOptions()...)
}
return fmt.Errorf("invalid %s params: %v", ACTION_Tap, action.Params)
case ACTION_TapByOCR:
if ocrText, ok := action.Params.(string); ok {
return dExt.TapByOCR(ocrText, action.GetOptions()...)
@@ -247,7 +240,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
case ACTION_TapByCV:
actionOptions := option.NewActionOptions(action.GetOptions()...)
if len(actionOptions.ScreenShotWithUITypes) > 0 {
return dExt.TapByUIDetection(action.GetOptions()...)
return dExt.TapByCV(action.GetOptions()...)
}
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
case ACTION_DoubleTapXY:
@@ -260,11 +253,6 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
return dExt.DoubleTapXY(x, y)
}
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTapXY, action.Params)
case ACTION_DoubleTap:
if param, ok := action.Params.(string); ok {
return dExt.DoubleTap(param)
}
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
case ACTION_Swipe:
params := action.Params
swipeAction := prepareSwipeAction(dExt, params, action.GetOptions()...)

View File

@@ -142,16 +142,6 @@ func (dExt *XTDriver) GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.O
return screenResult.Texts, nil
}
func (dExt *XTDriver) FindUIRectInUIKit(search string, opts ...option.ActionOption) (point ai.PointF, err error) {
// find text using OCR
if !builtin.IsPathExists(search) {
return dExt.FindScreenText(search, opts...)
}
// TODO: find image using CV
err = errors.New("ocr text not found")
return
}
func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (point ai.PointF, err error) {
options := option.NewActionOptions(opts...)
if options.ScreenShotFileName == "" {

View File

@@ -9,13 +9,13 @@ import (
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
)
func (dExt *XTDriver) TapByOCR(ocrText string, opts ...option.ActionOption) error {
func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error {
actionOptions := option.NewActionOptions(opts...)
if actionOptions.ScreenShotFileName == "" {
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("tap_by_ocr_%s", ocrText)))
opts = append(opts, option.WithScreenShotFileName(fmt.Sprintf("tap_by_ocr_%s", text)))
}
point, err := dExt.FindScreenText(ocrText, opts...)
point, err := dExt.FindScreenText(text, opts...)
if err != nil {
if actionOptions.IgnoreNotFoundError {
return nil
@@ -26,7 +26,7 @@ func (dExt *XTDriver) TapByOCR(ocrText string, opts ...option.ActionOption) erro
return dExt.TapAbsXY(point.X, point.Y, opts...)
}
func (dExt *XTDriver) TapByUIDetection(opts ...option.ActionOption) error {
func (dExt *XTDriver) TapByCV(opts ...option.ActionOption) error {
options := option.NewActionOptions(opts...)
point, err := dExt.FindUIResult(opts...)
@@ -40,24 +40,6 @@ func (dExt *XTDriver) TapByUIDetection(opts ...option.ActionOption) error {
return dExt.TapAbsXY(point.X, point.Y, opts...)
}
func (dExt *XTDriver) Tap(param string, opts ...option.ActionOption) error {
return dExt.TapOffset(param, 0, 0, opts...)
}
func (dExt *XTDriver) TapOffset(param string, xOffset, yOffset float64, opts ...option.ActionOption) (err error) {
options := option.NewActionOptions(opts...)
point, err := dExt.FindUIRectInUIKit(param, opts...)
if err != nil {
if options.IgnoreNotFoundError {
return nil
}
return err
}
return dExt.TapAbsXY(point.X+xOffset, point.Y+yOffset, opts...)
}
func (dExt *XTDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
// double tap on coordinate: [x, y] should be relative
if x > 1 || y > 1 {
@@ -76,20 +58,3 @@ func (dExt *XTDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) err
}
return nil
}
func (dExt *XTDriver) DoubleTap(param string, opts ...option.ActionOption) (err error) {
return dExt.DoubleTapOffset(param, 0, 0, opts...)
}
func (dExt *XTDriver) DoubleTapOffset(param string, xOffset, yOffset float64, opts ...option.ActionOption) (err error) {
point, err := dExt.FindUIRectInUIKit(param)
if err != nil {
return err
}
err = dExt.DoubleTapXY(point.X+xOffset, point.Y+yOffset, opts...)
if err != nil {
return errors.Wrap(code.MobileUITapError, err.Error())
}
return nil
}

View File

@@ -29,9 +29,3 @@ func TestDriverExt_TapAbsXY(t *testing.T) {
err := iosDriverExt.TapAbsXY(100, 300)
checkErr(t, err)
}
func TestDriverExt_TapWithOCR(t *testing.T) {
// 需要点击文字上方的图标
err := iosDriverExt.TapOffset("抖音", 0, -20)
checkErr(t, err)
}