diff --git a/internal/version/VERSION b/internal/version/VERSION index 81d96d83..f4a635b3 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2502192152 +v5.0.0+2503032009 diff --git a/pkg/uixt/1234.jpeg b/pkg/uixt/1234.jpeg new file mode 100644 index 00000000..72e634a8 Binary files /dev/null and b/pkg/uixt/1234.jpeg differ diff --git a/pkg/uixt/android_driver_adb.go b/pkg/uixt/android_driver_adb.go index 9e689f47..123ade4f 100644 --- a/pkg/uixt/android_driver_adb.go +++ b/pkg/uixt/android_driver_adb.go @@ -315,7 +315,7 @@ func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error { var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { x, y, err = convertToAbsolutePoint(ad, x, y) if err != nil { return err @@ -362,7 +362,7 @@ func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (er func (ad *ADBDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) (err error) { actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ad, fromX, fromY, toX, toY) if err != nil { return err @@ -393,7 +393,7 @@ func (ad *ADBDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO func (ad *ADBDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ad, fromX, fromY, toX, toY) if err != nil { return err diff --git a/pkg/uixt/android_driver_uia2.go b/pkg/uixt/android_driver_uia2.go index 3f9a42d4..833592e3 100644 --- a/pkg/uixt/android_driver_uia2.go +++ b/pkg/uixt/android_driver_uia2.go @@ -255,7 +255,7 @@ func (ud *UIA2Driver) Orientation() (orientation types.Orientation, err error) { func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error { var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { x, y, err = convertToAbsolutePoint(ud, x, y) if err != nil { return err @@ -352,7 +352,7 @@ func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (e func (ud *UIA2Driver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ud, fromX, fromY, toX, toY) if err != nil { return err @@ -381,7 +381,7 @@ func (ud *UIA2Driver) Swipe(fromX, fromY, toX, toY float64, opts ...option.Actio // register(postHandler, new Swipe("/wd/hub/session/:sessionId/touch/perform")) var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(ud, fromX, fromY, toX, toY) if err != nil { return err diff --git a/pkg/uixt/driver.go b/pkg/uixt/driver.go index bfb165c8..ad63ca04 100644 --- a/pkg/uixt/driver.go +++ b/pkg/uixt/driver.go @@ -52,7 +52,7 @@ type IDriver interface { // tap TapXY(x, y float64, opts ...option.ActionOption) error // by percentage TapAbsXY(x, y float64, opts ...option.ActionOption) error // by absolute coordinate - DoubleTap(x, y float64, opts ...option.ActionOption) error // by percentage + DoubleTap(x, y float64, opts ...option.ActionOption) error // by absolute coordinate TouchAndHold(x, y float64, opts ...option.ActionOption) error // swipe Drag(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error diff --git a/pkg/uixt/driver_ext_test.go b/pkg/uixt/driver_ext_test.go index 3857cde6..d6041fe1 100644 --- a/pkg/uixt/driver_ext_test.go +++ b/pkg/uixt/driver_ext_test.go @@ -4,6 +4,7 @@ package uixt import ( "testing" + "time" "github.com/httprunner/httprunner/v5/pkg/uixt/ai" "github.com/httprunner/httprunner/v5/pkg/uixt/option" @@ -82,6 +83,34 @@ func setupDriverExt(t *testing.T) *XTDriver { } } +func TestDriverExt_FindScreenText(t *testing.T) { + driver := setupDriverExt(t) + point, err := driver.FindScreenText("首页") + assert.Nil(t, err) + t.Log(point) +} + +func TestDriverExt_Seek(t *testing.T) { + driver := setupDriverExt(t) + + point, err := driver.FindScreenText("首页") + assert.Nil(t, err) + + size, err := driver.WindowSize() + assert.Nil(t, err) + width := size.Width + + y := point.Y - 40 + for i := 0; i < 5; i++ { + err := driver.Swipe(0.5, 0.8, 0.5, 0.2) + assert.Nil(t, err) + time.Sleep(1 * time.Second) + err = driver.Drag(20, y, float64(width)*0.75, y) + assert.Nil(t, err) + time.Sleep(1 * time.Second) + } +} + func TestDriverExt_TapByOCR(t *testing.T) { driver := setupDriverExt(t) err := driver.TapByOCR("天气") diff --git a/pkg/uixt/harmony_driver_hdc.go b/pkg/uixt/harmony_driver_hdc.go index 4644e91b..9aed5876 100644 --- a/pkg/uixt/harmony_driver_hdc.go +++ b/pkg/uixt/harmony_driver_hdc.go @@ -177,7 +177,7 @@ func (hd *HDCDriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO func (hd *HDCDriver) Swipe(fromX, fromY, toX, toY float64, opts ...option.ActionOption) error { var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(hd, fromX, fromY, toX, toY) if err != nil { return err diff --git a/pkg/uixt/ios_driver_wda.go b/pkg/uixt/ios_driver_wda.go index 2dd771b5..14696c51 100644 --- a/pkg/uixt/ios_driver_wda.go +++ b/pkg/uixt/ios_driver_wda.go @@ -615,7 +615,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error // [[FBRoute POST:@"/wda/doubleTap"] respondWithTarget:self action:@selector(handleDoubleTapCoordinate:)] var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { x, y, err = convertToAbsolutePoint(wd, x, y) if err != nil { return err @@ -648,7 +648,7 @@ func (wd *WDADriver) Drag(fromX, fromY, toX, toY float64, opts ...option.ActionO // [[FBRoute POST:@"/wda/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDragCoordinate:)] var err error actionOptions := option.NewActionOptions(opts...) - if !actionOptions.AbsCoordinate { + if actionOptions.Relative { fromX, fromY, toX, toY, err = convertToAbsoluteCoordinates(wd, fromX, fromY, toX, toY) if err != nil { return err diff --git a/pkg/uixt/option/action.go b/pkg/uixt/option/action.go index abd767f1..cccfcd85 100644 --- a/pkg/uixt/option/action.go +++ b/pkg/uixt/option/action.go @@ -19,7 +19,7 @@ type ActionOptions struct { Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action Frequency int `json:"frequency,omitempty" yaml:"frequency,omitempty"` - AbsCoordinate bool `json:"abs,omitempty" yaml:"abs,omitempty"` // use absolute coordinate + Relative bool `json:"relative,omitempty" yaml:"relative,omitempty"` // use relative coordinate ScreenOptions @@ -56,8 +56,8 @@ func (o *ActionOptions) Options() []ActionOption { if o.Steps != 0 { options = append(options, WithSteps(o.Steps)) } - if o.AbsCoordinate { - options = append(options, WithAbsoluteCoordinate(true)) + if o.Relative { + options = append(options, WithRelative(true)) } switch v := o.Direction.(type) { @@ -260,9 +260,10 @@ func WithDirection(direction string) ActionOption { } } -func WithAbsoluteCoordinate(abs bool) ActionOption { +// WithRelative set relative coordinate, (0, 0) is the top-left corner of the screen +func WithRelative(relative bool) ActionOption { return func(o *ActionOptions) { - o.AbsCoordinate = abs + o.Relative = relative } } diff --git a/server/ui.go b/server/ui.go index 9a6a7fb5..d7cf5693 100644 --- a/server/ui.go +++ b/server/ui.go @@ -17,8 +17,7 @@ func (r *Router) tapHandler(c *gin.Context) { } if tapReq.Duration > 0 { err = driver.Drag(tapReq.X, tapReq.Y, tapReq.X, tapReq.Y, - option.WithDuration(tapReq.Duration), - option.WithAbsoluteCoordinate(true)) + option.WithDuration(tapReq.Duration)) } else { err = driver.TapAbsXY(tapReq.X, tapReq.Y) } @@ -66,6 +65,7 @@ func (r *Router) uploadHandler(c *gin.Context) { } RenderSuccess(c, true) } + func (r *Router) hoverHandler(c *gin.Context) { var hoverReq HoverRequest if err := c.ShouldBindJSON(&hoverReq); err != nil { @@ -125,8 +125,7 @@ func (r *Router) doubleTapHandler(c *gin.Context) { if tapReq.X < 1 && tapReq.Y < 1 { err = driver.DoubleTap(tapReq.X, tapReq.Y) } else { - err = driver.DoubleTap(tapReq.X, tapReq.Y, - option.WithAbsoluteCoordinate(true)) + err = driver.DoubleTap(tapReq.X, tapReq.Y) } if err != nil { @@ -151,8 +150,8 @@ func (r *Router) dragHandler(c *gin.Context) { } err = driver.Drag(dragReq.FromX, dragReq.FromY, dragReq.ToX, dragReq.ToY, - option.WithDuration(dragReq.Duration), option.WithPressDuration(dragReq.PressDuration), - option.WithAbsoluteCoordinate(true)) + option.WithDuration(dragReq.Duration), + option.WithPressDuration(dragReq.PressDuration)) if err != nil { RenderError(c, err) return