From ba00e9590bde62be9d1b910793cbf8c352d987d0 Mon Sep 17 00:00:00 2001 From: "xucong.053" Date: Tue, 11 Oct 2022 15:55:20 +0800 Subject: [PATCH] fix: unittext --- examples/uitest/demo_douyin_follow_live_test.go | 2 +- hrp/pkg/uixt/ext.go | 13 ++++++++++--- hrp/step.go | 1 + hrp/step_android_ui.go | 2 +- hrp/step_ios_ui.go | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/uitest/demo_douyin_follow_live_test.go b/examples/uitest/demo_douyin_follow_live_test.go index a20dd363..ad8fc608 100644 --- a/examples/uitest/demo_douyin_follow_live_test.go +++ b/examples/uitest/demo_douyin_follow_live_test.go @@ -37,7 +37,7 @@ func TestIOSDouyinFollowLive(t *testing.T) { IOS(). TapByOCR("关注", hrp.WithIndex(1)).Sleep(10), hrp.NewStep("向上滑动 2 次"). - IOS().SwipeToTapFromTexts([]string{"理肤泉", "婉宝"}, hrp.WithDirection([]float64{0.6, 0.2, 0.2, 0.2}), hrp.WithIdentifier("click_live")).Sleep(10). + IOS().SwipeToTapTexts([]string{"理肤泉", "婉宝"}, hrp.WithCustomDirection(0.6, 0.2, 0.2, 0.2), hrp.WithIdentifier("click_live")).Sleep(10). Swipe(0.9, 0.7, 0.9, 0.3, hrp.WithIdentifier("slide_in_live")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存 Swipe(0.9, 0.7, 0.9, 0.3, hrp.WithIdentifier("slide_in_live")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存 }, diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index 14cbd0e3..5bd6306e 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -88,13 +88,20 @@ func WithIndex(index int) ActionOption { } } -// WithDirection inputs direction (up, down, left, right, []float64{sx, sy, ex, ey}) -func WithDirection(direction interface{}) ActionOption { +// WithDirection inputs direction (up, down, left, right) +func WithDirection(direction string) ActionOption { return func(o *MobileAction) { o.Direction = direction } } +// WithCustomDirection inputs sx, sy, ex, ey +func WithCustomDirection(sx, sy, ex, ey float64) ActionOption { + return func(o *MobileAction) { + o.Direction = []float64{sx, sy, ex, ey} + } +} + func WithText(text string) ActionOption { return func(o *MobileAction) { o.Text = text @@ -438,7 +445,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error { if action.Direction != nil { return dExt.SwipeUntil(action.Direction, findText, foundTextAction, action.MaxRetryTimes) } - // swipe until live room found + // swipe until found return dExt.SwipeUntil("up", findText, foundTextAction, action.MaxRetryTimes) case AppTerminate: if bundleId, ok := action.Params.(string); ok { diff --git a/hrp/step.go b/hrp/step.go index 244903bd..98bccab7 100644 --- a/hrp/step.go +++ b/hrp/step.go @@ -30,6 +30,7 @@ var ( WithID = uixt.WithID WithDescription = uixt.WithDescription WithDirection = uixt.WithDirection + WithCustomDirection = uixt.WithCustomDirection ) var ( diff --git a/hrp/step_android_ui.go b/hrp/step_android_ui.go index 6bb8b33d..e16840e1 100644 --- a/hrp/step_android_ui.go +++ b/hrp/step_android_ui.go @@ -324,7 +324,7 @@ func (s *StepAndroid) SwipeToTapText(text string, options ...uixt.ActionOption) return &StepAndroid{step: s.step} } -func (s *StepAndroid) SwipeToTapFromTexts(texts []string, options ...uixt.ActionOption) *StepAndroid { +func (s *StepAndroid) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepAndroid { action := uixt.MobileAction{ Method: uixt.ACTION_SwipeToTapText, Params: texts, diff --git a/hrp/step_ios_ui.go b/hrp/step_ios_ui.go index 5f54c28a..7d6d8df9 100644 --- a/hrp/step_ios_ui.go +++ b/hrp/step_ios_ui.go @@ -244,7 +244,7 @@ func (s *StepIOS) SwipeToTapText(text string, options ...uixt.ActionOption) *Ste return &StepIOS{step: s.step} } -func (s *StepIOS) SwipeToTapFromTexts(texts []string, options ...uixt.ActionOption) *StepIOS { +func (s *StepIOS) SwipeToTapTexts(texts []string, options ...uixt.ActionOption) *StepIOS { action := uixt.MobileAction{ Method: uixt.ACTION_SwipeToTapText, Params: texts,