diff --git a/internal/version/VERSION b/internal/version/VERSION index 8da30f12..341422c6 100644 --- a/internal/version/VERSION +++ b/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2503171536 +v5.0.0-beta-2503171744 diff --git a/uixt/android_driver_adb.go b/uixt/android_driver_adb.go index e812852d..dc03f183 100644 --- a/uixt/android_driver_adb.go +++ b/uixt/android_driver_adb.go @@ -300,7 +300,7 @@ func (ad *ADBDriver) TapXY(x, y float64, opts ...option.ActionOption) error { func (ad *ADBDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) // adb shell input tap x y xStr := fmt.Sprintf("%.1f", x) @@ -320,7 +320,7 @@ func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error return err } actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) // adb shell input tap x y xStr := fmt.Sprintf("%.1f", x) @@ -341,7 +341,7 @@ func (ad *ADBDriver) DoubleTap(x, y float64, opts ...option.ActionOption) error func (ad *ADBDriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) { actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) duration := 1000.0 if actionOptions.Duration > 0 { duration = actionOptions.Duration * 1000 diff --git a/uixt/android_driver_uia2.go b/uixt/android_driver_uia2.go index 938afc13..61d295f1 100644 --- a/uixt/android_driver_uia2.go +++ b/uixt/android_driver_uia2.go @@ -259,7 +259,7 @@ func (ud *UIA2Driver) DoubleTap(x, y float64, opts ...option.ActionOption) error return err } actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) data := map[string]interface{}{ "actions": []interface{}{ @@ -295,7 +295,7 @@ func (ud *UIA2Driver) TapXY(x, y float64, opts ...option.ActionOption) error { func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { // register(postHandler, new Tap("/wd/hub/session/:sessionId/appium/tap")) actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) duration := 100.0 if actionOptions.PressDuration > 0 { @@ -325,7 +325,7 @@ func (ud *UIA2Driver) TapAbsXY(x, y float64, opts ...option.ActionOption) error func (ud *UIA2Driver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) { actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) duration := actionOptions.Duration if duration == 0 { duration = 1.0 diff --git a/uixt/driver_ext_tap.go b/uixt/driver_ext_tap.go index 1388cd40..7283fd18 100644 --- a/uixt/driver_ext_tap.go +++ b/uixt/driver_ext_tap.go @@ -22,7 +22,7 @@ func (dExt *XTDriver) TapByOCR(text string, opts ...option.ActionOption) error { } var point ai.PointF - if actionOptions.TapRandom { + if actionOptions.TapRandomRect { point = textRect.RandomPoint() } else { point = textRect.Center() diff --git a/uixt/driver_ext_test.go b/uixt/driver_ext_test.go index 1ef1c3b4..e90f3de8 100644 --- a/uixt/driver_ext_test.go +++ b/uixt/driver_ext_test.go @@ -173,15 +173,19 @@ func TestDriverExt_ClosePopupsHandler(t *testing.T) { func TestDriverExt_Action_Risk(t *testing.T) { driver := setupADBDriverExt(t) - // tap point with offset + // tap point with constant offset err := driver.TapXY(0.5, 0.5, option.WithTapOffset(-10, 10)) assert.Nil(t, err) + // tap point with random offset + err = driver.TapXY(0.5, 0.5, option.WithOffsetRandomRange(-10, 10)) + assert.Nil(t, err) + // swipe direction with offset err = driver.Swipe(0.5, 0.5, 0.5, 0.9, option.WithSwipeOffset(-50, 50, -50, 50)) assert.Nil(t, err) // tap random point in ocr text rect - err = driver.TapByOCR("首页", option.WithTapRandom(true)) + err = driver.TapByOCR("首页", option.WithTapRandomRect(true)) } diff --git a/uixt/harmony_driver_hdc.go b/uixt/harmony_driver_hdc.go index fb248791..28dbf541 100644 --- a/uixt/harmony_driver_hdc.go +++ b/uixt/harmony_driver_hdc.go @@ -151,7 +151,7 @@ func (hd *HDCDriver) TapXY(x, y float64, opts ...option.ActionOption) error { func (hd *HDCDriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) if actionOptions.Identifier != "" { startTime := int(time.Now().UnixMilli()) diff --git a/uixt/ios_driver_wda.go b/uixt/ios_driver_wda.go index 8a97a19b..5c663944 100644 --- a/uixt/ios_driver_wda.go +++ b/uixt/ios_driver_wda.go @@ -587,7 +587,7 @@ func (wd *WDADriver) TapXY(x, y float64, opts ...option.ActionOption) error { func (wd *WDADriver) TapAbsXY(x, y float64, opts ...option.ActionOption) error { // [[FBRoute POST:@"/wda/tap/:uuid"] respondWithTarget:self action:@selector(handleTap:)] actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) data := map[string]interface{}{ "x": wd.toScale(x), "y": wd.toScale(y), @@ -608,7 +608,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error } actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) x = wd.toScale(x) y = wd.toScale(y) data := map[string]interface{}{ @@ -623,7 +623,7 @@ func (wd *WDADriver) DoubleTap(x, y float64, opts ...option.ActionOption) error // FIXME: hold not work func (wd *WDADriver) TouchAndHold(x, y float64, opts ...option.ActionOption) (err error) { actionOptions := option.NewActionOptions(opts...) - x, y = actionOptions.ApplyOffset(x, y) + x, y = actionOptions.ApplyTapOffset(x, y) if actionOptions.Duration == 0 { opts = append(opts, option.WithPressDuration(1)) } diff --git a/uixt/option/action.go b/uixt/option/action.go index 26d84a29..c4b6c4c7 100644 --- a/uixt/option/action.go +++ b/uixt/option/action.go @@ -99,9 +99,9 @@ func (o *ActionOptions) Options() []ActionOption { // for tap [x,y] offset options = append(options, WithTapOffset(o.TapOffset[0], o.TapOffset[1])) } - if o.TapRandom { + if o.TapRandomRect { // tap random point in OCR/CV rectangle - options = append(options, WithTapRandom(true)) + options = append(options, WithTapRandomRect(true)) } if len(o.SwipeOffset) == 4 { // for swipe [fromX, fromY, toX, toY] offset @@ -136,17 +136,17 @@ func (o *ActionOptions) Options() []ActionOption { return options } -func (o *ActionOptions) ApplyOffset(absX, absY float64) (float64, float64) { +func (o *ActionOptions) ApplyTapOffset(absX, absY float64) (float64, float64) { if len(o.TapOffset) == 2 { absX += float64(o.TapOffset[0]) absY += float64(o.TapOffset[1]) } - absX += o.GenerateRandomOffset() - absY += o.GenerateRandomOffset() + absX += o.generateRandomOffset() + absY += o.generateRandomOffset() return absX, absY } -func (o *ActionOptions) GenerateRandomOffset() float64 { +func (o *ActionOptions) generateRandomOffset() float64 { if len(o.OffsetRandomRange) != 2 { // invalid offset random range, should be [min, max] return 0 diff --git a/uixt/option/screen.go b/uixt/option/screen.go index f2243a17..feb3772f 100644 --- a/uixt/option/screen.go +++ b/uixt/option/screen.go @@ -216,8 +216,8 @@ type ScreenFilterOptions struct { AbsScope AbsScope `json:"abs_scope,omitempty" yaml:"abs_scope,omitempty"` Regex bool `json:"regex,omitempty" yaml:"regex,omitempty"` // use regex to match text - TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_offset,omitempty"` // tap with point offset - TapRandom bool `json:"tap_random,omitempty" yaml:"tap_random,omitempty"` // tap random point in text/image rectangle + TapOffset []int `json:"tap_offset,omitempty" yaml:"tap_offset,omitempty"` // tap with absolute point offset + TapRandomRect bool `json:"tap_random_rect,omitempty" yaml:"tap_random_rect,omitempty"` // tap random point in text/image rectangle SwipeOffset []int `json:"swipe_offset,omitempty" yaml:"swipe_offset,omitempty"` // swipe with direction offset OffsetRandomRange []int `json:"offset_random_range,omitempty" yaml:"offset_random_range,omitempty"` // set random range [min, max] for tap/swipe points Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element @@ -248,11 +248,11 @@ func WithTapOffset(offsetX, offsetY int) ActionOption { } } -// WithTapRandom is used with TapByOCR and TapByCV +// WithTapRandomRect is used with TapByOCR and TapByCV // when set true, tap random point in text/image rectangle -func WithTapRandom(tapRandom bool) ActionOption { +func WithTapRandomRect(tapRandom bool) ActionOption { return func(o *ActionOptions) { - o.TapRandom = tapRandom + o.TapRandomRect = tapRandom } }