diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 722a7126..3da4d513 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,6 +25,7 @@ UI related: - fix: add default options for `swipe_to_tap_app` action - refactor: ui validation methods, support parsing expect value - fix: reuse the same request body during `GetImage` retry +- fix: iOS `tap_xy` scale adaption error others: diff --git a/hrp/internal/builtin/utils.go b/hrp/internal/builtin/utils.go index b88f7902..dd50d61c 100644 --- a/hrp/internal/builtin/utils.go +++ b/hrp/internal/builtin/utils.go @@ -450,3 +450,8 @@ func GenNameWithTimestamp(tmpl string) string { } return fmt.Sprintf(tmpl, time.Now().Unix()) } + +func IsZeroFloat64(f float64) bool { + threshold := 1e-3 + return math.Abs(f) < threshold +} diff --git a/hrp/pkg/uixt/android_device.go b/hrp/pkg/uixt/android_device.go index f2b25839..c1793880 100644 --- a/hrp/pkg/uixt/android_device.go +++ b/hrp/pkg/uixt/android_device.go @@ -161,7 +161,7 @@ func (dev *AndroidDevice) NewDriver(options ...DriverOption) (driverExt *DriverE } var driver WebDriver - if dev.UIA2 { + if dev.UIA2 || dev.LogOn { driver, err = dev.NewUSBDriver(driverOptions.capabilities) } else { driver, err = dev.NewAdbDriver() diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index ca444f2f..8bfee256 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -15,6 +15,7 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog/log" + "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/code" "github.com/httprunner/httprunner/v4/hrp/internal/json" "github.com/httprunner/httprunner/v4/hrp/pkg/gidevice" @@ -223,6 +224,9 @@ func (wd *wdaDriver) GetTimestamp() (timestamp int64, err error) { } func (wd *wdaDriver) Scale() (float64, error) { + if !builtin.IsZeroFloat64(wd.scale) { + return wd.scale, nil + } screen, err := wd.Screen() if err != nil { return 0, errors.Wrap(code.MobileUIDriverError, diff --git a/hrp/pkg/uixt/tap.go b/hrp/pkg/uixt/tap.go index b685b7bc..df200117 100644 --- a/hrp/pkg/uixt/tap.go +++ b/hrp/pkg/uixt/tap.go @@ -12,11 +12,15 @@ func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error { func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error { // tap on [x, y] percent of window size if x > 1 || y > 1 { - return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y) + return fmt.Errorf("x, y percentage should be <= 1, got x=%v, y=%v", x, y) } - x = x * float64(dExt.windowSize.Width) - y = y * float64(dExt.windowSize.Height) + scale, err := dExt.Driver.Scale() + if err != nil { + return fmt.Errorf("failed to get scale: %v", err) + } + x = x * float64(dExt.windowSize.Width) * scale + y = y * float64(dExt.windowSize.Height) * scale return dExt.TapAbsXY(x, y, options...) }