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

@@ -93,7 +93,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
time.Sleep(500 * time.Millisecond)
// 切换横屏
err = driver.TapByUIDetection(
err = driver.TapByCV(
option.WithScreenShotUITypes("fullScreen"))
if err != nil {
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed

View File

@@ -95,7 +95,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
time.Sleep(500 * time.Millisecond)
// 切换横屏
err = driver.TapByUIDetection(
err = driver.TapByCV(
option.WithScreenShotUITypes("fullScreen"))
if err != nil {
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed

View File

@@ -1 +1 @@
v5.0.0+2502111735
v5.0.0+2502111749

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

View File

@@ -127,18 +127,6 @@ func (s *StepMobile) TapAbsXY(x, y float64, opts ...option.ActionOption) *StepMo
return s
}
// Tap taps on the target element
func (s *StepMobile) Tap(params string, opts ...option.ActionOption) *StepMobile {
action := uixt.MobileAction{
Method: uixt.ACTION_Tap,
Params: params,
Options: option.NewActionOptions(opts...),
}
s.obj().Actions = append(s.obj().Actions, action)
return s
}
// TapByOCR taps on the target element by OCR recognition
func (s *StepMobile) TapByOCR(ocrText string, opts ...option.ActionOption) *StepMobile {
action := uixt.MobileAction{
@@ -184,17 +172,6 @@ func (s *StepMobile) DoubleTapXY(x, y float64, opts ...option.ActionOption) *Ste
return s
}
func (s *StepMobile) DoubleTap(params string, opts ...option.ActionOption) *StepMobile {
action := uixt.MobileAction{
Method: uixt.ACTION_DoubleTap,
Params: params,
Options: option.NewActionOptions(opts...),
}
s.obj().Actions = append(s.obj().Actions, action)
return s
}
func (s *StepMobile) Back() *StepMobile {
action := uixt.MobileAction{
Method: uixt.ACTION_Back,

View File

@@ -14,7 +14,7 @@ func TestIOSSettingsAction(t *testing.T) {
SetIOS(option.WithWDAPort(8700), option.WithWDAMjpegPort(8800)),
TestSteps: []IStep{
NewStep("launch Settings").
IOS().Home().Tap("设置").
IOS().Home().TapByOCR("设置").
Validate().
AssertNameExists("飞行模式").
AssertLabelExists("蓝牙").
@@ -34,7 +34,7 @@ func TestIOSSearchApp(t *testing.T) {
Config: NewConfig("ios ui action on Search App 资源库"),
TestSteps: []IStep{
NewStep("进入 App 资源库 搜索框").
IOS().Home().SwipeLeft().SwipeLeft().Tap("dewey-search-field").
IOS().Home().SwipeLeft().SwipeLeft().TapByCV("dewey-search-field").
Validate().
AssertLabelExists("取消"),
NewStep("搜索抖音").
@@ -68,33 +68,12 @@ func TestIOSAppLaunch(t *testing.T) {
}
}
func TestIOSDouyinAction(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("ios ui action on 抖音"),
TestSteps: []IStep{
NewStep("launch douyin").
IOS().Home().Tap("//*[@label='抖音']").
Validate().
AssertLabelExists("首页", "首页 tab 不存在").
AssertLabelExists("消息", "消息 tab 不存在"),
NewStep("swipe up and down").
Loop(3).
IOS().
SwipeUp().SwipeDown(),
},
}
err := NewRunner(t).Run(testCase)
if err != nil {
t.Fatal(err)
}
}
func TestAndroidAction(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("android ui action"),
TestSteps: []IStep{
NewStep("launch douyin").
Android().Serial("xxx").Tap("抖音").
Android().Serial("xxx").TapByOCR("抖音").
Validate().
AssertNameExists("首页", "首页 tab 不存在").
AssertNameExists("消息", "消息 tab 不存在"),