mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix: Swipe params not used
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411132025
|
v5.0.0+2411132058
|
||||||
|
|||||||
@@ -718,7 +718,8 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
||||||
case ACTION_Swipe:
|
case ACTION_Swipe:
|
||||||
swipeAction := dExt.prepareSwipeAction(action.GetOptions()...)
|
params := action.Params
|
||||||
|
swipeAction := dExt.prepareSwipeAction(params, action.GetOptions()...)
|
||||||
return swipeAction(dExt)
|
return swipeAction(dExt)
|
||||||
case ACTION_Input:
|
case ACTION_Input:
|
||||||
// input text on current active element
|
// input text on current active element
|
||||||
|
|||||||
+19
-20
@@ -43,20 +43,6 @@ func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeTo(direction string, options ...ActionOption) (err error) {
|
|
||||||
switch direction {
|
|
||||||
case "up":
|
|
||||||
return dExt.SwipeUp(options...)
|
|
||||||
case "down":
|
|
||||||
return dExt.SwipeDown(options...)
|
|
||||||
case "left":
|
|
||||||
return dExt.SwipeLeft(options...)
|
|
||||||
case "right":
|
|
||||||
return dExt.SwipeRight(options...)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("unexpected direction: %s", direction)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) SwipeUp(options ...ActionOption) (err error) {
|
func (dExt *DriverExt) SwipeUp(options ...ActionOption) (err error) {
|
||||||
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, options...)
|
return dExt.SwipeRelative(0.5, 0.5, 0.5, 0.1, options...)
|
||||||
}
|
}
|
||||||
@@ -98,10 +84,14 @@ func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action,
|
|||||||
fmt.Sprintf("loop %d times, match find condition failed", maxRetryTimes))
|
fmt.Sprintf("loop %d times, match find condition failed", maxRetryTimes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) prepareSwipeAction(options ...ActionOption) func(d *DriverExt) error {
|
func (dExt *DriverExt) prepareSwipeAction(params interface{}, options ...ActionOption) func(d *DriverExt) error {
|
||||||
actionOptions := NewActionOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
|
|
||||||
var swipeDirection interface{}
|
var swipeDirection interface{}
|
||||||
if actionOptions.Direction != nil {
|
// priority: params > actionOptions.Direction, default swipe up
|
||||||
|
if params != nil {
|
||||||
|
swipeDirection = params
|
||||||
|
} else if actionOptions.Direction != nil {
|
||||||
swipeDirection = actionOptions.Direction
|
swipeDirection = actionOptions.Direction
|
||||||
} else {
|
} else {
|
||||||
swipeDirection = "up" // default swipe up
|
swipeDirection = "up" // default swipe up
|
||||||
@@ -119,9 +109,18 @@ func (dExt *DriverExt) prepareSwipeAction(options ...ActionOption) func(d *Drive
|
|||||||
|
|
||||||
if d, ok := swipeDirection.(string); ok {
|
if d, ok := swipeDirection.(string); ok {
|
||||||
// enum direction: up, down, left, right
|
// enum direction: up, down, left, right
|
||||||
if err := dExt.SwipeTo(d, options...); err != nil {
|
switch d {
|
||||||
log.Error().Err(err).Msgf("swipe %s failed", d)
|
case "up":
|
||||||
return err
|
return dExt.SwipeUp(options...)
|
||||||
|
case "down":
|
||||||
|
return dExt.SwipeDown(options...)
|
||||||
|
case "left":
|
||||||
|
return dExt.SwipeLeft(options...)
|
||||||
|
case "right":
|
||||||
|
return dExt.SwipeRight(options...)
|
||||||
|
default:
|
||||||
|
return errors.Wrap(code.InvalidParamError,
|
||||||
|
fmt.Sprintf("get unexpected swipe direction: %s", d))
|
||||||
}
|
}
|
||||||
} else if d, ok := swipeDirection.([]float64); ok && len(d) == 4 {
|
} else if d, ok := swipeDirection.([]float64); ok && len(d) == 4 {
|
||||||
// custom direction: [fromX, fromY, toX, toY]
|
// custom direction: [fromX, fromY, toX, toY]
|
||||||
@@ -180,7 +179,7 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption)
|
|||||||
return d.TapAbsXY(point.X, point.Y, options...)
|
return d.TapAbsXY(point.X, point.Y, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
findAction := dExt.prepareSwipeAction(optionsWithoutIdentifier...)
|
findAction := dExt.prepareSwipeAction(nil, optionsWithoutIdentifier...)
|
||||||
return dExt.LoopUntil(findAction, findTexts, foundTextAction, optionsWithoutIdentifier...)
|
return dExt.LoopUntil(findAction, findTexts, foundTextAction, optionsWithoutIdentifier...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
func TestAndroidSwipeAction(t *testing.T) {
|
func TestAndroidSwipeAction(t *testing.T) {
|
||||||
setupAndroidAdbDriver(t)
|
setupAndroidAdbDriver(t)
|
||||||
|
|
||||||
swipeAction := driverExt.prepareSwipeAction(WithDirection("up"))
|
swipeAction := driverExt.prepareSwipeAction("up", WithDirection("down"))
|
||||||
err := swipeAction(driverExt)
|
err := swipeAction(driverExt)
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
|
|
||||||
swipeAction = driverExt.prepareSwipeAction(WithCustomDirection(0.5, 0.5, 0.5, 0.9))
|
swipeAction = driverExt.prepareSwipeAction("up", WithCustomDirection(0.5, 0.5, 0.5, 0.9))
|
||||||
err = swipeAction(driverExt)
|
err = swipeAction(driverExt)
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ func (s *StepMobile) Back(options ...uixt.ActionOption) *StepMobile {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Swipe drags from [sx, sy] to [ex, ey]
|
||||||
func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
|
|||||||
Reference in New Issue
Block a user