From 6e94230ad6c30943d35507a1e54c83c2294995da Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 18 Sep 2022 10:42:31 +0800 Subject: [PATCH] fix: sleep specified seconds --- hrp/internal/uixt/ext.go | 2 ++ hrp/step_ios_ui.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hrp/internal/uixt/ext.go b/hrp/internal/uixt/ext.go index 5855491e..82d9c394 100644 --- a/hrp/internal/uixt/ext.go +++ b/hrp/internal/uixt/ext.go @@ -17,6 +17,7 @@ import ( "github.com/electricbubble/gwda" cvHelper "github.com/electricbubble/opencv-helper" "github.com/pkg/errors" + "github.com/rs/zerolog/log" ) // TemplateMatchMode is the type of the template matching operation. @@ -170,6 +171,7 @@ func (dExt *DriverExt) takeScreenShot() (raw *bytes.Buffer, err error) { return dExt.frame, nil } if raw, err = dExt.WebDriver.Screenshot(); err != nil { + log.Error().Err(err).Msgf("screenshot failed: %v", err) return nil, err } return diff --git a/hrp/step_ios_ui.go b/hrp/step_ios_ui.go index ca5013e9..312da3d7 100644 --- a/hrp/step_ios_ui.go +++ b/hrp/step_ios_ui.go @@ -1,6 +1,7 @@ package hrp import ( + "encoding/json" "fmt" "strings" "time" @@ -241,7 +242,7 @@ func (s *StepIOS) Times(n int) *StepIOS { } // Sleep specify sleep seconds after last action -func (s *StepIOS) Sleep(n int) *StepIOS { +func (s *StepIOS) Sleep(n float64) *StepIOS { s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{ Method: ctlSleep, Params: n, @@ -707,11 +708,15 @@ func (ud *uiDriver) doAction(action MobileAction) error { param := fmt.Sprintf("%v", action.Params) return ud.SendKeys(param) case ctlSleep: - if param, ok := action.Params.(int); ok { - time.Sleep(time.Duration(param) * time.Second) + if param, ok := action.Params.(json.Number); ok { + seconds, _ := param.Float64() + time.Sleep(time.Duration(seconds*1000) * time.Millisecond) + return nil + } else if param, ok := action.Params.(float64); ok { + time.Sleep(time.Duration(param*1000) * time.Millisecond) return nil } - return fmt.Errorf("invalid sleep params: %v", action.Params) + return fmt.Errorf("invalid sleep params: %v(%T)", action.Params, action.Params) case ctlScreenShot: // take snapshot log.Info().Msg("take snapshot for current screen")