diff --git a/examples/uitest/bili/android/cli.go b/examples/uitest/bili/android/cli.go index 7d6dc9be..b844b6f0 100644 --- a/examples/uitest/bili/android/cli.go +++ b/examples/uitest/bili/android/cli.go @@ -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) diff --git a/examples/uitest/bili/ios/cli.go b/examples/uitest/bili/ios/cli.go index 8f68b046..87463130 100644 --- a/examples/uitest/bili/ios/cli.go +++ b/examples/uitest/bili/ios/cli.go @@ -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) diff --git a/internal/version/VERSION b/internal/version/VERSION index 79c1838a..ec011538 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502111735 +v5.0.0+2502111749 diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index bbf3a699..cc579d27 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -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 diff --git a/pkg/uixt/driver_action.go b/pkg/uixt/driver_action.go index b367c3e8..3e4e2b5a 100644 --- a/pkg/uixt/driver_action.go +++ b/pkg/uixt/driver_action.go @@ -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()...) diff --git a/pkg/uixt/driver_screenshot.go b/pkg/uixt/driver_screenshot.go index b4860e79..e375552f 100644 --- a/pkg/uixt/driver_screenshot.go +++ b/pkg/uixt/driver_screenshot.go @@ -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 == "" { diff --git a/pkg/uixt/driver_tap.go b/pkg/uixt/driver_tap.go index aaa7e8e3..98998024 100644 --- a/pkg/uixt/driver_tap.go +++ b/pkg/uixt/driver_tap.go @@ -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 -} diff --git a/pkg/uixt/driver_tap_test.go b/pkg/uixt/driver_tap_test.go index 4f29bc44..abca47c8 100644 --- a/pkg/uixt/driver_tap_test.go +++ b/pkg/uixt/driver_tap_test.go @@ -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) -} diff --git a/step_mobile_ui.go b/step_mobile_ui.go index 94321e69..f8c6f0fb 100644 --- a/step_mobile_ui.go +++ b/step_mobile_ui.go @@ -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, diff --git a/step_mobile_ui_test.go b/step_mobile_ui_test.go index 7591c4df..d47e4fb6 100644 --- a/step_mobile_ui_test.go +++ b/step_mobile_ui_test.go @@ -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 不存在"),