mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 17:29:56 +08:00
fix: failed to set steps option of android swipe action
This commit is contained in:
@@ -581,7 +581,6 @@ func (ud *uiaDriver) _swipe(startX, startY, endX, endY interface{}, options ...D
|
||||
// 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 ...DataOption) error {
|
||||
options = append(options, WithDataSteps(12))
|
||||
return ud.SwipeFloat(float64(fromX), float64(fromY), float64(toX), float64(toY), options...)
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ type MobileAction struct {
|
||||
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"` // used to identify the action in log
|
||||
MaxRetryTimes int `json:"max_retry_times,omitempty" yaml:"max_retry_times,omitempty"` // max retry times
|
||||
WaitTime float64 `json:"wait_time,omitempty" yaml:"wait_time,omitempty"` // wait time between swipe and ocr, unit: second
|
||||
Duration float64 `json:"duration,omitempty" yaml:"duration,omitempty"` // used to set duration of ios swipe action
|
||||
Steps int `json:"steps,omitempty" yaml:"steps,omitempty"` // used to set steps of android swipe action
|
||||
Direction interface{} `json:"direction,omitempty" yaml:"direction,omitempty"` // used by swipe to tap text or app
|
||||
Scope []float64 `json:"scope,omitempty" yaml:"scope,omitempty"` // used by ocr to get text position in the scope
|
||||
Offset []int `json:"offset,omitempty" yaml:"offset,omitempty"` // used to tap offset of point
|
||||
@@ -99,6 +101,18 @@ func WithWaitTime(sec float64) ActionOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithDuration(duration float64) ActionOption {
|
||||
return func(o *MobileAction) {
|
||||
o.Duration = duration
|
||||
}
|
||||
}
|
||||
|
||||
func WithSteps(steps int) ActionOption {
|
||||
return func(o *MobileAction) {
|
||||
o.Steps = steps
|
||||
}
|
||||
}
|
||||
|
||||
// WithDirection inputs direction (up, down, left, right)
|
||||
func WithDirection(direction string) ActionOption {
|
||||
return func(o *MobileAction) {
|
||||
@@ -585,6 +599,11 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
return fmt.Errorf("invalid %s params: %v", ACTION_DoubleTap, action.Params)
|
||||
case ACTION_Swipe:
|
||||
identifierOption := WithDataIdentifier(action.Identifier)
|
||||
durationOption := WithDataPressDuration(action.Duration)
|
||||
if action.Steps == 0 {
|
||||
action.Steps = 10
|
||||
}
|
||||
stepsOption := WithDataSteps(action.Steps)
|
||||
if positions, ok := action.Params.([]interface{}); ok {
|
||||
// relative fromX, fromY, toX, toY of window size: [0.5, 0.9, 0.5, 0.1]
|
||||
if len(positions) != 4 {
|
||||
@@ -594,10 +613,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
||||
fromY, _ := positions[1].(float64)
|
||||
toX, _ := positions[2].(float64)
|
||||
toY, _ := positions[3].(float64)
|
||||
return dExt.SwipeRelative(fromX, fromY, toX, toY, identifierOption)
|
||||
return dExt.SwipeRelative(fromX, fromY, toX, toY, identifierOption, durationOption, stepsOption)
|
||||
}
|
||||
if direction, ok := action.Params.(string); ok {
|
||||
return dExt.SwipeTo(direction, identifierOption)
|
||||
return dExt.SwipeTo(direction, identifierOption, durationOption, stepsOption)
|
||||
}
|
||||
return fmt.Errorf("invalid %s params: %v", ACTION_Swipe, action.Params)
|
||||
case ACTION_Input:
|
||||
|
||||
@@ -29,6 +29,8 @@ var (
|
||||
WithText = uixt.WithText
|
||||
WithID = uixt.WithID
|
||||
WithDescription = uixt.WithDescription
|
||||
WithDuration = uixt.WithDuration
|
||||
WIthSteps = uixt.WithSteps
|
||||
WithDirection = uixt.WithDirection
|
||||
WithCustomDirection = uixt.WithCustomDirection
|
||||
WithScope = uixt.WithScope
|
||||
|
||||
Reference in New Issue
Block a user