From 89a08f61ec2e024d07e256d9824856579a9b610e Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Sat, 23 Nov 2024 22:07:24 +0800 Subject: [PATCH] refactor: merge Swipe and SwipeFloat --- hrp/internal/version/VERSION | 2 +- hrp/pkg/server/ui.go | 2 +- hrp/pkg/uixt/android_adb_driver.go | 6 +----- hrp/pkg/uixt/android_uia2_driver.go | 6 +----- hrp/pkg/uixt/harmony_hdc_driver.go | 6 +----- hrp/pkg/uixt/interface.go | 3 +-- hrp/pkg/uixt/ios_device.go | 4 +++- hrp/pkg/uixt/ios_driver.go | 6 +----- hrp/pkg/uixt/ios_stub_driver.go | 17 ----------------- hrp/pkg/uixt/swipe.go | 2 +- 10 files changed, 11 insertions(+), 43 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index ceda170e..868f9c57 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2411232206 +v5.0.0+2411232207 diff --git a/hrp/pkg/server/ui.go b/hrp/pkg/server/ui.go index cf71cf29..f0dd28ab 100644 --- a/hrp/pkg/server/ui.go +++ b/hrp/pkg/server/ui.go @@ -106,7 +106,7 @@ func dragHandler(c *gin.Context) { return } } else { - err := dExt.Driver.SwipeFloat( + err := dExt.Driver.Swipe( dragReq.FromX, dragReq.FromY, dragReq.ToX, dragReq.ToY, actionOptions...) if err != nil { diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index ec8e42c2..dbc06324 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -418,11 +418,7 @@ func (ad *adbDriver) Drag(fromX, fromY, toX, toY float64, options ...ActionOptio return nil } -func (ad *adbDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error { - return ad.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...) -} - -func (ad *adbDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error { +func (ad *adbDriver) Swipe(fromX, fromY, toX, toY float64, options ...ActionOption) error { actionOptions := NewActionOptions(options...) if len(actionOptions.Offset) == 4 { diff --git a/hrp/pkg/uixt/android_uia2_driver.go b/hrp/pkg/uixt/android_uia2_driver.go index 2a2cb9c0..a8396852 100644 --- a/hrp/pkg/uixt/android_uia2_driver.go +++ b/hrp/pkg/uixt/android_uia2_driver.go @@ -417,11 +417,7 @@ func (ud *uiaDriver) Drag(fromX, fromY, toX, toY float64, options ...ActionOptio // per step. So for a 100 steps, the swipe will take about 1/2 second to complete. // // `steps` is the number of move steps sent to the system -func (ud *uiaDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error { - return ud.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...) -} - -func (ud *uiaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error { +func (ud *uiaDriver) Swipe(fromX, fromY, toX, toY float64, options ...ActionOption) error { // register(postHandler, new Swipe("/wd/hub/session/:sessionId/touch/perform")) actionOptions := NewActionOptions(options...) if len(actionOptions.Offset) == 4 { diff --git a/hrp/pkg/uixt/harmony_hdc_driver.go b/hrp/pkg/uixt/harmony_hdc_driver.go index e6251408..b72b0eaa 100644 --- a/hrp/pkg/uixt/harmony_hdc_driver.go +++ b/hrp/pkg/uixt/harmony_hdc_driver.go @@ -188,11 +188,7 @@ func (hd *hdcDriver) Drag(fromX, fromY, toX, toY float64, options ...ActionOptio } // Swipe works like Drag, but `pressForDuration` value is 0 -func (hd *hdcDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error { - return hd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...) -} - -func (hd *hdcDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error { +func (hd *hdcDriver) Swipe(fromX, fromY, toX, toY float64, options ...ActionOption) error { actionOptions := NewActionOptions(options...) if len(actionOptions.Offset) == 4 { fromX += float64(actionOptions.Offset[0]) diff --git a/hrp/pkg/uixt/interface.go b/hrp/pkg/uixt/interface.go index 03083cb1..8d62ab16 100644 --- a/hrp/pkg/uixt/interface.go +++ b/hrp/pkg/uixt/interface.go @@ -592,8 +592,7 @@ type IWebDriver interface { Drag(fromX, fromY, toX, toY float64, options ...ActionOption) error // Swipe works like Drag, but `pressForDuration` value is 0 - Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error - SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error + Swipe(fromX, fromY, toX, toY float64, options ...ActionOption) error // SetPasteboard Sets data to the general pasteboard SetPasteboard(contentType PasteboardType, content string) error diff --git a/hrp/pkg/uixt/ios_device.go b/hrp/pkg/uixt/ios_device.go index eeecbae8..c6dcd0d7 100644 --- a/hrp/pkg/uixt/ios_device.go +++ b/hrp/pkg/uixt/ios_device.go @@ -818,7 +818,9 @@ func (dev *IOSDevice) NewStubDriver() (driver IWebDriver, err error) { fmt.Sprintf("forward tcp port failed: %v", err)) } host := "localhost" - stubDriver, err := newStubIOSDriver(fmt.Sprintf("http://%s:%d", host, localStubPort), fmt.Sprintf("http://%s:%d", host, localServerPort), dev) + stubDriver, err := newStubIOSDriver( + fmt.Sprintf("http://%s:%d", host, localStubPort), + fmt.Sprintf("http://%s:%d", host, localServerPort), dev) if err != nil { return nil, err } diff --git a/hrp/pkg/uixt/ios_driver.go b/hrp/pkg/uixt/ios_driver.go index e8856903..97c8dccd 100644 --- a/hrp/pkg/uixt/ios_driver.go +++ b/hrp/pkg/uixt/ios_driver.go @@ -588,11 +588,7 @@ func (wd *wdaDriver) Drag(fromX, fromY, toX, toY float64, options ...ActionOptio return } -func (wd *wdaDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error { - return wd.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...) -} - -func (wd *wdaDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error { +func (wd *wdaDriver) Swipe(fromX, fromY, toX, toY float64, options ...ActionOption) error { return wd.Drag(fromX, fromY, toX, toY, options...) } diff --git a/hrp/pkg/uixt/ios_stub_driver.go b/hrp/pkg/uixt/ios_stub_driver.go index 026b17eb..359383bf 100644 --- a/hrp/pkg/uixt/ios_stub_driver.go +++ b/hrp/pkg/uixt/ios_stub_driver.go @@ -265,23 +265,6 @@ func (s *stubIOSDriver) Drag(fromX, fromY, toX, toY float64, options ...ActionOp return s.wdaDriver.Drag(fromX, fromY, toX, toY, options...) } -// Swipe works like Drag, but `pressForDuration` value is 0 -func (s *stubIOSDriver) Swipe(fromX, fromY, toX, toY int, options ...ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.wdaDriver.Swipe(fromX, fromY, toX, toY, options...) -} - -func (s *stubIOSDriver) SwipeFloat(fromX, fromY, toX, toY float64, options ...ActionOption) error { - err := s.setUpWda() - if err != nil { - return err - } - return s.wdaDriver.SwipeFloat(fromX, fromY, toX, toY, options...) -} - // SetPasteboard Sets data to the general pasteboard func (s *stubIOSDriver) SetPasteboard(contentType PasteboardType, content string) error { err := s.setUpWda() diff --git a/hrp/pkg/uixt/swipe.go b/hrp/pkg/uixt/swipe.go index 6794d97d..61c00ef6 100644 --- a/hrp/pkg/uixt/swipe.go +++ b/hrp/pkg/uixt/swipe.go @@ -36,7 +36,7 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ... fromY = float64(height) * fromY toX = float64(width) * toX toY = float64(height) * toY - err = dExt.Driver.SwipeFloat(fromX, fromY, toX, toY, options...) + err = dExt.Driver.Swipe(fromX, fromY, toX, toY, options...) if err != nil { return errors.Wrap(code.MobileUISwipeError, err.Error()) }