From f477d8ae9b6dc4bd389542091bfa6a726d564e83 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 21 Sep 2023 16:42:58 +0800 Subject: [PATCH] change: update logs for popup handler --- hrp/pkg/uixt/popups.go | 8 +++++--- hrp/pkg/uixt/swipe.go | 2 +- hrp/pkg/uixt/video_crawler.go | 13 ++++--------- hrp/step_mobile_ui.go | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/hrp/pkg/uixt/popups.go b/hrp/pkg/uixt/popups.go index 0821cc12..d0e9f608 100644 --- a/hrp/pkg/uixt/popups.go +++ b/hrp/pkg/uixt/popups.go @@ -128,7 +128,7 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { } popup := screenResult.Popup - if popup == nil { + if popup == nil || popup.PopupArea.IsEmpty() { log.Debug().Msg("no popup found") break } @@ -145,7 +145,8 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { } func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error { - if popup == nil { + if popup == nil || popup.PopupArea.IsEmpty() { + log.Debug().Msg("no popup found") return nil } popup.CloseStatus = CloseStatusFound @@ -155,7 +156,8 @@ func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error { log.Error(). Interface("popup", popup). Msg("popup close area not found") - return errors.New("popup close area not found") + return errors.Wrap(code.MobileUIPopupError, + "popup close area not found") } closePoint := popupClose.Center() diff --git a/hrp/pkg/uixt/swipe.go b/hrp/pkg/uixt/swipe.go index 92c52f28..4ad1141f 100644 --- a/hrp/pkg/uixt/swipe.go +++ b/hrp/pkg/uixt/swipe.go @@ -154,7 +154,7 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption) log.Error().Err(err).Strs("texts", texts).Msg("find texts failed") // target texts not found, try to auto handle popup if e := dExt.tapPopupHandler(screenResult.Popup); e != nil { - log.Error().Err(e).Msg("auto handle popup failed") + log.Error().Err(e).Msg("tap popup handler failed") } return err } diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index f50ec0c3..faf31c76 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(1)); err != nil { + if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(3)); err != nil { return err } @@ -234,9 +234,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { case VideoType_Live: // 直播 - log.Info(). - Interface("video", currentVideo). - Msg(FOUND_LIVE_SUCCESS) + crawler.LiveCount++ + log.Info().Interface("video", currentVideo).Msg(FOUND_LIVE_SUCCESS) // take screenshot and get screen texts by OCR screenResult, err := crawler.driverExt.GetScreenResult( @@ -262,7 +261,6 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { currentVideo.LiveType = screenResult.imageResult.LiveType } - crawler.LiveCount++ // simulation watch feed video sleepStrict(swipeFinishTime, currentVideo.PlayDuration) @@ -295,6 +293,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { default: // 点播 || 图文 || 广告 || etc. crawler.FeedCount++ + log.Info().Interface("video", currentVideo).Msg(FOUND_FEED_SUCCESS) screenResult := &ScreenResult{ Resolution: dExt.windowSize, @@ -304,11 +303,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { SwipeStartTime: swipeStartTime.UnixMilli(), SwipeFinishTime: swipeFinishTime.UnixMilli(), } - dExt.cacheStepData.screenResults[time.Now().String()] = screenResult - log.Info(). - Interface("video", currentVideo). - Msg(FOUND_FEED_SUCCESS) // simulation watch feed video sleepStrict(swipeFinishTime, currentVideo.PlayDuration) diff --git a/hrp/step_mobile_ui.go b/hrp/step_mobile_ui.go index 09a3f194..66014878 100644 --- a/hrp/step_mobile_ui.go +++ b/hrp/step_mobile_ui.go @@ -625,7 +625,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 { - log.Error().Err(err2).Str("step", step.Name).Msg("auto handle popup failed") + log.Error().Err(err2).Str("step", step.Name).Msg("handle popup failed on step finished") } // save attachments