diff --git a/hrp/pkg/uixt/action.go b/hrp/pkg/uixt/action.go index 242b59ea..cd3d7c4a 100644 --- a/hrp/pkg/uixt/action.go +++ b/hrp/pkg/uixt/action.go @@ -668,7 +668,19 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) { } return dExt.VideoCrawler(configs) case ACTION_ClosePopups: - return dExt.ClosePopups(action.GetOptions()...) + options := action.GetOptions() + actionOptions := NewActionOptions(options...) + + // default to retry 3 times + if actionOptions.MaxRetryTimes == 0 { + options = append(options, WithMaxRetryTimes(3)) + } + // set default swipe interval to 1 second + if builtin.IsZeroFloat64(actionOptions.Interval) { + options = append(options, WithInterval(1)) + } + + return dExt.ClosePopupsHandler(options...) } return nil } diff --git a/hrp/pkg/uixt/popups.go b/hrp/pkg/uixt/popups.go index 7b197e8b..2fd032d8 100644 --- a/hrp/pkg/uixt/popups.go +++ b/hrp/pkg/uixt/popups.go @@ -6,7 +6,6 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog/log" - "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/code" ) @@ -112,24 +111,6 @@ func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool { return true } -func (p *PopupInfo) exists() bool { - return !p.CloseBox.IsEmpty() -} - -func (dExt *DriverExt) ClosePopups(options ...ActionOption) error { - actionOptions := NewActionOptions(options...) - - // default to retry 5 times - if actionOptions.MaxRetryTimes == 0 { - options = append(options, WithMaxRetryTimes(5)) - } - // set default swipe interval to 1 second - if builtin.IsZeroFloat64(actionOptions.Interval) { - options = append(options, WithInterval(1)) - } - return dExt.ClosePopupsHandler(options...) -} - func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { actionOptions := NewActionOptions(options...) log.Info().Interface("actionOptions", actionOptions).Msg("try to find and close popups") @@ -149,7 +130,7 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { } popup := screenResult.Popup - if popup == nil || !popup.exists() { + if popup == nil || popup.CloseBox.IsEmpty() { log.Debug().Interface("popup", popup).Msg("no popup found") break } @@ -173,8 +154,8 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { } func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error { - if popup == nil || !popup.exists() { - log.Debug().Msg("no popup found") + if popup == nil || popup.CloseBox.IsEmpty() { + log.Debug().Interface("popup", popup).Msg("no popup found") return nil } popup.CloseStatus = CloseStatusFound diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index faf31c76..1f6a2905 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -186,7 +186,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Warn().Msg("get current feed video failed") // check and handle popups - if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(3)); err != nil { + if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(1)); err != nil { return err } diff --git a/hrp/step_mobile_ui.go b/hrp/step_mobile_ui.go index 66014878..85b8dfa4 100644 --- a/hrp/step_mobile_ui.go +++ b/hrp/step_mobile_ui.go @@ -624,7 +624,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err } // automatic handling of pop-up windows on each step finished - if err2 := uiDriver.ClosePopups(); err2 != nil { + if err2 := uiDriver.ClosePopupsHandler(uixt.WithMaxRetryTimes(3), uixt.WithInterval(1)); err2 != nil { log.Error().Err(err2).Str("step", step.Name).Msg("handle popup failed on step finished") }