From e55a4ba59830ddea25a6e80be596a8b6ecfa841e Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 29 Jul 2022 16:02:17 +0800 Subject: [PATCH] feat: run last action with given times --- hrp/step_ios_ui.go | 21 +++++++++++++++++++++ hrp/step_ui_test.go | 27 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/hrp/step_ios_ui.go b/hrp/step_ios_ui.go index 4f43846f..1f0e307d 100644 --- a/hrp/step_ios_ui.go +++ b/hrp/step_ios_ui.go @@ -121,6 +121,27 @@ func (s *StepIOS) StartAppByClick(name string) *StepIOS { return &StepIOS{step: s.step} } +// run last action with given times +func (s *StepIOS) Times(n int) *StepIOS { + if n <= 0 { + log.Warn().Int("n", n).Msg("times should be positive, set to 1") + n = 1 + } + + actionsTotal := len(s.step.IOS.Actions) + if actionsTotal == 0 { + return s + } + + // actionsTotal >=1 && n >= 1 + lastAction := s.step.IOS.Actions[actionsTotal-1 : actionsTotal][0] + for i := 0; i < n-1; i++ { + // duplicate last action n-1 times + s.step.IOS.Actions = append(s.step.IOS.Actions, lastAction) + } + return &StepIOS{step: s.step} +} + // Validate switches to step validation. func (s *StepIOS) Validate() *StepIOSValidation { return &StepIOSValidation{ diff --git a/hrp/step_ui_test.go b/hrp/step_ui_test.go index 6022c73f..388128a7 100644 --- a/hrp/step_ui_test.go +++ b/hrp/step_ui_test.go @@ -52,7 +52,7 @@ func TestIOSSearchApp(t *testing.T) { Config: NewConfig("ios ui action on Search App 资源库"), TestSteps: []IStep{ NewStep("进入 App 资源库 搜索框"). - IOS().Home().SwipeLeft().SwipeLeft().Click("dewey-search-field"). + IOS().Home().SwipeLeft().Times(2).Click("dewey-search-field"). Validate(). AssertNameExists("取消", "「取消」不存在"), NewStep("搜索抖音"). @@ -66,6 +66,29 @@ func TestIOSSearchApp(t *testing.T) { } } +func TestIOSWeixin(t *testing.T) { + testCase := &TestCase{ + Config: NewConfig("ios ui action on 微信"), + TestSteps: []IStep{ + NewStep("启动微信"). + IOS().Home().Click("微信"). + Validate(). + AssertNameExists("通讯录", "微信启动失败,「通讯录」不存在"), + NewStep("进入直播页"). + IOS().Click("发现").Click([]float64{0.5, 0.3}). + Validate(). + AssertNameExists("直播", "「直播」不存在"), + NewStep("向上滑动 5 次"). + IOS().SwipeUp().Times(5), + }, + } + + err := NewRunner(t).Run(testCase) + if err != nil { + t.Fatal(err) + } +} + func TestIOSDouyinAction(t *testing.T) { testCase := &TestCase{ Config: NewConfig("ios ui action on 抖音"), @@ -76,7 +99,7 @@ func TestIOSDouyinAction(t *testing.T) { AssertNameExists("首页", "首页 tab 不存在"). AssertNameExists("消息", "消息 tab 不存在"), NewStep("swipe up and down"). - IOS().SwipeUp().SwipeUp().SwipeDown(), + IOS().SwipeUp().Times(3).SwipeDown(), }, }