feat: sleep n seconds after last action

This commit is contained in:
debugtalk
2022-07-30 17:45:39 +08:00
parent a591f8193e
commit a2b79a7194
2 changed files with 17 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ const (
uiLongClick MobileMethod = "long_click" uiLongClick MobileMethod = "long_click"
uiSwipe MobileMethod = "swipe" uiSwipe MobileMethod = "swipe"
uiInput MobileMethod = "input" uiInput MobileMethod = "input"
ctlSleep MobileMethod = "sleep"
) )
type MobileAction struct { type MobileAction struct {

View File

@@ -160,7 +160,7 @@ func (s *StepIOS) Input(text string) *StepIOS {
return &StepIOS{step: s.step} 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 { func (s *StepIOS) Times(n int) *StepIOS {
if n <= 0 { if n <= 0 {
log.Warn().Int("n", n).Msg("times should be positive, set to 1") 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} 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. // Validate switches to step validation.
func (s *StepIOS) Validate() *StepIOSValidation { func (s *StepIOS) Validate() *StepIOSValidation {
return &StepIOSValidation{ return &StepIOSValidation{
@@ -570,6 +579,12 @@ func (w *wdaClient) doAction(action MobileAction) error {
// send \b\b\b to delete 3 chars // send \b\b\b to delete 3 chars
param := fmt.Sprintf("%v", action.Params) param := fmt.Sprintf("%v", action.Params)
return w.Driver.SendKeys(param) 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 return nil
} }