diff --git a/examples/uitest/demo_douyin_follow_live_test.go b/examples/uitest/demo_douyin_follow_live_test.go index 59b223ef..d87f1da9 100644 --- a/examples/uitest/demo_douyin_follow_live_test.go +++ b/examples/uitest/demo_douyin_follow_live_test.go @@ -47,9 +47,6 @@ func TestIOSDouyinFollowLive(t *testing.T) { if err := testCase.Dump2JSON("demo_douyin_follow_live.json"); err != nil { t.Fatal(err) } - if err := testCase.Dump2YAML("demo_douyin_follow_live.yaml"); err != nil { - t.Fatal(err) - } runner := hrp.NewRunner(t).SetSaveTests(true) err := runner.Run(testCase) diff --git a/hrp/pkg/uixt/action.go b/hrp/pkg/uixt/action.go index 31c11c20..d80126f2 100644 --- a/hrp/pkg/uixt/action.go +++ b/hrp/pkg/uixt/action.go @@ -64,19 +64,20 @@ type MobileAction struct { Method ActionMethod `json:"method,omitempty" yaml:"method,omitempty"` Params interface{} `json:"params,omitempty" yaml:"params,omitempty"` - 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 - 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 - Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1 - Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action - IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found - Text string `json:"text,omitempty" yaml:"text,omitempty"` - ID string `json:"id,omitempty" yaml:"id,omitempty"` - Description string `json:"description,omitempty" yaml:"description,omitempty"` + 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 + Index int `json:"index,omitempty" yaml:"index,omitempty"` // index of the target element, should start from 1 + Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"` // TODO: wait timeout in seconds for mobile action + IgnoreNotFoundError bool `json:"ignore_NotFoundError,omitempty" yaml:"ignore_NotFoundError,omitempty"` // ignore error if target element not found + Text string `json:"text,omitempty" yaml:"text,omitempty"` + ID string `json:"id,omitempty" yaml:"id,omitempty"` + Description string `json:"description,omitempty" yaml:"description,omitempty"` } type ActionOption func(o *MobileAction) @@ -114,14 +115,14 @@ func WithSteps(steps int) ActionOption { // WithDirection inputs direction (up, down, left, right) func WithDirection(direction string) ActionOption { return func(o *MobileAction) { - o.Params = direction + o.Direction = direction } } // WithCustomDirection inputs sx, sy, ex, ey func WithCustomDirection(sx, sy, ex, ey float64) ActionOption { return func(o *MobileAction) { - o.Params = []float64{sx, sy, ex, ey} + o.Direction = []float64{sx, sy, ex, ey} } } diff --git a/hrp/pkg/uixt/swipe.go b/hrp/pkg/uixt/swipe.go index 3b7ad7f3..2636f86d 100644 --- a/hrp/pkg/uixt/swipe.go +++ b/hrp/pkg/uixt/swipe.go @@ -101,26 +101,33 @@ func (dExt *DriverExt) prepareSwipeAction(action MobileAction) func(d *DriverExt dataOptions := make([]DataOption, 3) dataOptions = append(dataOptions, identifierOption, durationOption, stepsOption) + var swipeDirection interface{} + if action.Direction != nil { + swipeDirection = action.Direction + } else { + swipeDirection = "up" // default swipe up + } + return func(d *DriverExt) error { defer func() { // wait for swipe action to completed and content to load completely time.Sleep(time.Duration(1000*action.WaitTime) * time.Millisecond) }() - if d, ok := action.Params.(string); ok { + if d, ok := swipeDirection.(string); ok { // enum direction: up, down, left, right if err := dExt.SwipeTo(d, dataOptions...); err != nil { log.Error().Err(err).Msgf("swipe %s failed", d) return err } - } else if d, ok := action.Params.([]float64); ok { + } else if d, ok := swipeDirection.([]float64); ok { // custom direction: [fromX, fromY, toX, toY] if err := dExt.SwipeRelative(d[0], d[1], d[2], d[3], dataOptions...); err != nil { log.Error().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) failed", d[0], d[1], d[2], d[3]) return err } - } else if d, ok := action.Params.([]interface{}); ok { + } else if d, ok := swipeDirection.([]interface{}); ok { // loaded from json case // custom direction: [fromX, fromY, toX, toY] sx, _ := builtin.Interface2Float64(d[0]) @@ -133,7 +140,7 @@ func (dExt *DriverExt) prepareSwipeAction(action MobileAction) func(d *DriverExt return err } } else { - return fmt.Errorf("invalid swipe params %v", action.Params) + return fmt.Errorf("invalid swipe params %v", swipeDirection) } return nil } @@ -197,7 +204,7 @@ func (dExt *DriverExt) swipeToTapApp(appName string, action MobileAction) error } action.Offset = []int{0, -25} // tap app icon above the text - action.Params = "left" + action.Direction = "left" return dExt.swipeToTapTexts([]string{appName}, action) }