refactor: merge Swipe and SwipeFloat

This commit is contained in:
lilong.129
2024-11-23 22:07:24 +08:00
parent 0b598fa590
commit 89a08f61ec
10 changed files with 11 additions and 43 deletions

View File

@@ -1 +1 @@
v5.0.0+2411232206
v5.0.0+2411232207

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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])

View File

@@ -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

View File

@@ -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
}

View File

@@ -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...)
}

View File

@@ -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()

View File

@@ -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())
}