From 89e209eb23095982e0c60ea01d997c811fb19aa7 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 30 Jul 2022 17:45:39 +0800 Subject: [PATCH] feat: sleep n seconds after last action --- hrp/step.go | 1 + hrp/step_ios_ui.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/hrp/step.go b/hrp/step.go index f4794a89..9b6f070a 100644 --- a/hrp/step.go +++ b/hrp/step.go @@ -34,6 +34,7 @@ const ( uiLongClick MobileMethod = "long_click" uiSwipe MobileMethod = "swipe" uiInput MobileMethod = "input" + ctlSleep MobileMethod = "sleep" ) type MobileAction struct { diff --git a/hrp/step_ios_ui.go b/hrp/step_ios_ui.go index 43c7f811..13189fc9 100644 --- a/hrp/step_ios_ui.go +++ b/hrp/step_ios_ui.go @@ -160,7 +160,7 @@ func (s *StepIOS) Input(text string) *StepIOS { return &StepIOS{step: s.step} } -// run last action with given times +// Times specify running times for run last action func (s *StepIOS) Times(n int) *StepIOS { if n <= 0 { log.Warn().Int("n", n).Msg("times should be positive, set to 1") @@ -181,6 +181,15 @@ func (s *StepIOS) Times(n int) *StepIOS { return &StepIOS{step: s.step} } +// Sleep specify sleep seconds after last action +func (s *StepIOS) Sleep(n int) *StepIOS { + s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{ + Method: ctlSleep, + Params: n, + }) + return &StepIOS{step: s.step} +} + // Validate switches to step validation. func (s *StepIOS) Validate() *StepIOSValidation { return &StepIOSValidation{ @@ -570,6 +579,12 @@ func (w *wdaClient) doAction(action MobileAction) error { // send \b\b\b to delete 3 chars param := fmt.Sprintf("%v", action.Params) return w.Driver.SendKeys(param) + case ctlSleep: + if param, ok := action.Params.(int); ok { + time.Sleep(time.Duration(param) * time.Second) + return nil + } + return fmt.Errorf("invalid sleep params: %v", action.Params) } return nil }