mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-22 00:32:11 +08:00
change: remove unused tap methods
This commit is contained in:
@@ -93,7 +93,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// 切换横屏
|
// 切换横屏
|
||||||
err = driver.TapByUIDetection(
|
err = driver.TapByCV(
|
||||||
option.WithScreenShotUITypes("fullScreen"))
|
option.WithScreenShotUITypes("fullScreen"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func watchVideo(driver *uixt.XTDriver) (err error) {
|
|||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// 切换横屏
|
// 切换横屏
|
||||||
err = driver.TapByUIDetection(
|
err = driver.TapByCV(
|
||||||
option.WithScreenShotUITypes("fullScreen"))
|
option.WithScreenShotUITypes("fullScreen"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0+2502111735
|
v5.0.0+2502111749
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ type IDriver interface {
|
|||||||
Unlock() error
|
Unlock() error
|
||||||
Back() error
|
Back() error
|
||||||
// tap
|
// tap
|
||||||
TapXY(x, y float64, opts ...option.ActionOption) error // tap on [x, y] percent of window size
|
TapXY(x, y float64, opts ...option.ActionOption) error // by percentage
|
||||||
TapAbsXY(x, y float64, opts ...option.ActionOption) error
|
TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate
|
||||||
DoubleTapXY(x, y float64, opts ...option.ActionOption) error
|
DoubleTapXY(x, y float64, opts ...option.ActionOption) error // by percentage
|
||||||
TouchAndHold(x, y float64, opts ...option.ActionOption) error
|
TouchAndHold(x, y float64, opts ...option.ActionOption) error
|
||||||
TapByText(text string, opts ...option.ActionOption) error // TODO: remove
|
TapByText(text string, opts ...option.ActionOption) error // TODO: remove
|
||||||
TapByTexts(actions ...TapTextAction) 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)
|
GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.OCRTexts, err error)
|
||||||
GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error)
|
GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error)
|
||||||
|
|
||||||
// tap
|
// tap with AI
|
||||||
TapByOCR(ocrText string, opts ...option.ActionOption) error
|
TapByOCR(text string, opts ...option.ActionOption) error
|
||||||
TapXY(x, y float64, opts ...option.ActionOption) error
|
TapByCV(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
|
|
||||||
|
|
||||||
// swipe
|
// swipe
|
||||||
SwipeRelative(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error
|
SwipeRelative(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error
|
||||||
|
|||||||
@@ -41,9 +41,7 @@ const (
|
|||||||
ACTION_TapAbsXY ActionMethod = "tap_abs_xy"
|
ACTION_TapAbsXY ActionMethod = "tap_abs_xy"
|
||||||
ACTION_TapByOCR ActionMethod = "tap_ocr"
|
ACTION_TapByOCR ActionMethod = "tap_ocr"
|
||||||
ACTION_TapByCV ActionMethod = "tap_cv"
|
ACTION_TapByCV ActionMethod = "tap_cv"
|
||||||
ACTION_Tap ActionMethod = "tap"
|
|
||||||
ACTION_DoubleTapXY ActionMethod = "double_tap_xy"
|
ACTION_DoubleTapXY ActionMethod = "double_tap_xy"
|
||||||
ACTION_DoubleTap ActionMethod = "double_tap"
|
|
||||||
ACTION_Swipe ActionMethod = "swipe"
|
ACTION_Swipe ActionMethod = "swipe"
|
||||||
ACTION_Input ActionMethod = "input"
|
ACTION_Input ActionMethod = "input"
|
||||||
ACTION_Back ActionMethod = "back"
|
ACTION_Back ActionMethod = "back"
|
||||||
@@ -234,11 +232,6 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
return dExt.TapAbsXY(x, y, action.GetOptions()...)
|
return dExt.TapAbsXY(x, y, action.GetOptions()...)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_TapAbsXY, action.Params)
|
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:
|
case ACTION_TapByOCR:
|
||||||
if ocrText, ok := action.Params.(string); ok {
|
if ocrText, ok := action.Params.(string); ok {
|
||||||
return dExt.TapByOCR(ocrText, action.GetOptions()...)
|
return dExt.TapByOCR(ocrText, action.GetOptions()...)
|
||||||
@@ -247,7 +240,7 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
case ACTION_TapByCV:
|
case ACTION_TapByCV:
|
||||||
actionOptions := option.NewActionOptions(action.GetOptions()...)
|
actionOptions := option.NewActionOptions(action.GetOptions()...)
|
||||||
if len(actionOptions.ScreenShotWithUITypes) > 0 {
|
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)
|
return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params)
|
||||||
case ACTION_DoubleTapXY:
|
case ACTION_DoubleTapXY:
|
||||||
@@ -260,11 +253,6 @@ func (dExt *XTDriver) DoAction(action MobileAction) (err error) {
|
|||||||
return dExt.DoubleTapXY(x, y)
|
return dExt.DoubleTapXY(x, y)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTapXY, action.Params)
|
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:
|
case ACTION_Swipe:
|
||||||
params := action.Params
|
params := action.Params
|
||||||
swipeAction := prepareSwipeAction(dExt, params, action.GetOptions()...)
|
swipeAction := prepareSwipeAction(dExt, params, action.GetOptions()...)
|
||||||
|
|||||||
@@ -142,16 +142,6 @@ func (dExt *XTDriver) GetScreenTexts(opts ...option.ActionOption) (ocrTexts ai.O
|
|||||||
return screenResult.Texts, nil
|
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) {
|
func (dExt *XTDriver) FindScreenText(text string, opts ...option.ActionOption) (point ai.PointF, err error) {
|
||||||
options := option.NewActionOptions(opts...)
|
options := option.NewActionOptions(opts...)
|
||||||
if options.ScreenShotFileName == "" {
|
if options.ScreenShotFileName == "" {
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
|
"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...)
|
actionOptions := option.NewActionOptions(opts...)
|
||||||
if actionOptions.ScreenShotFileName == "" {
|
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 err != nil {
|
||||||
if actionOptions.IgnoreNotFoundError {
|
if actionOptions.IgnoreNotFoundError {
|
||||||
return nil
|
return nil
|
||||||
@@ -26,7 +26,7 @@ func (dExt *XTDriver) TapByOCR(ocrText string, opts ...option.ActionOption) erro
|
|||||||
return dExt.TapAbsXY(point.X, point.Y, opts...)
|
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...)
|
options := option.NewActionOptions(opts...)
|
||||||
|
|
||||||
point, err := dExt.FindUIResult(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...)
|
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 {
|
func (dExt *XTDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) error {
|
||||||
// double tap on coordinate: [x, y] should be relative
|
// double tap on coordinate: [x, y] should be relative
|
||||||
if x > 1 || y > 1 {
|
if x > 1 || y > 1 {
|
||||||
@@ -76,20 +58,3 @@ func (dExt *XTDriver) DoubleTapXY(x, y float64, opts ...option.ActionOption) err
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -29,9 +29,3 @@ func TestDriverExt_TapAbsXY(t *testing.T) {
|
|||||||
err := iosDriverExt.TapAbsXY(100, 300)
|
err := iosDriverExt.TapAbsXY(100, 300)
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDriverExt_TapWithOCR(t *testing.T) {
|
|
||||||
// 需要点击文字上方的图标
|
|
||||||
err := iosDriverExt.TapOffset("抖音", 0, -20)
|
|
||||||
checkErr(t, err)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -127,18 +127,6 @@ func (s *StepMobile) TapAbsXY(x, y float64, opts ...option.ActionOption) *StepMo
|
|||||||
return s
|
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
|
// TapByOCR taps on the target element by OCR recognition
|
||||||
func (s *StepMobile) TapByOCR(ocrText string, opts ...option.ActionOption) *StepMobile {
|
func (s *StepMobile) TapByOCR(ocrText string, opts ...option.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
@@ -184,17 +172,6 @@ func (s *StepMobile) DoubleTapXY(x, y float64, opts ...option.ActionOption) *Ste
|
|||||||
return s
|
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 {
|
func (s *StepMobile) Back() *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Back,
|
Method: uixt.ACTION_Back,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func TestIOSSettingsAction(t *testing.T) {
|
|||||||
SetIOS(option.WithWDAPort(8700), option.WithWDAMjpegPort(8800)),
|
SetIOS(option.WithWDAPort(8700), option.WithWDAMjpegPort(8800)),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("launch Settings").
|
NewStep("launch Settings").
|
||||||
IOS().Home().Tap("设置").
|
IOS().Home().TapByOCR("设置").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("飞行模式").
|
AssertNameExists("飞行模式").
|
||||||
AssertLabelExists("蓝牙").
|
AssertLabelExists("蓝牙").
|
||||||
@@ -34,7 +34,7 @@ func TestIOSSearchApp(t *testing.T) {
|
|||||||
Config: NewConfig("ios ui action on Search App 资源库"),
|
Config: NewConfig("ios ui action on Search App 资源库"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("进入 App 资源库 搜索框").
|
NewStep("进入 App 资源库 搜索框").
|
||||||
IOS().Home().SwipeLeft().SwipeLeft().Tap("dewey-search-field").
|
IOS().Home().SwipeLeft().SwipeLeft().TapByCV("dewey-search-field").
|
||||||
Validate().
|
Validate().
|
||||||
AssertLabelExists("取消"),
|
AssertLabelExists("取消"),
|
||||||
NewStep("搜索抖音").
|
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) {
|
func TestAndroidAction(t *testing.T) {
|
||||||
testCase := &TestCase{
|
testCase := &TestCase{
|
||||||
Config: NewConfig("android ui action"),
|
Config: NewConfig("android ui action"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("launch douyin").
|
NewStep("launch douyin").
|
||||||
Android().Serial("xxx").Tap("抖音").
|
Android().Serial("xxx").TapByOCR("抖音").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("首页", "首页 tab 不存在").
|
AssertNameExists("首页", "首页 tab 不存在").
|
||||||
AssertNameExists("消息", "消息 tab 不存在"),
|
AssertNameExists("消息", "消息 tab 不存在"),
|
||||||
|
|||||||
Reference in New Issue
Block a user