mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: sleep n seconds after last action
This commit is contained in:
@@ -34,6 +34,7 @@ const (
|
||||
uiLongClick MobileMethod = "long_click"
|
||||
uiSwipe MobileMethod = "swipe"
|
||||
uiInput MobileMethod = "input"
|
||||
ctlSleep MobileMethod = "sleep"
|
||||
)
|
||||
|
||||
type MobileAction struct {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user