From 85ff696f479c7c7e7a4ad85100c65b75d805556e Mon Sep 17 00:00:00 2001 From: "xucong.053" Date: Wed, 9 Nov 2022 18:19:57 +0800 Subject: [PATCH] fix: failed to set steps option of android swipe action --- hrp/pkg/uixt/android_driver.go | 1 - hrp/pkg/uixt/ext.go | 23 +++++++++++++++++++++-- hrp/step.go | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hrp/pkg/uixt/android_driver.go b/hrp/pkg/uixt/android_driver.go index 3f642c5c..eae15617 100644 --- a/hrp/pkg/uixt/android_driver.go +++ b/hrp/pkg/uixt/android_driver.go @@ -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...) } diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index ffa9a4e6..119a03f7 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -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: diff --git a/hrp/step.go b/hrp/step.go index 6c41f9d5..c9e96023 100644 --- a/hrp/step.go +++ b/hrp/step.go @@ -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