change: update logs for popup handler

This commit is contained in:
lilong.129
2023-09-21 15:26:27 +08:00
parent bdc8c30c18
commit f68b644548
3 changed files with 20 additions and 8 deletions
+18 -6
View File
@@ -25,7 +25,7 @@ type ClosePopupsResult struct {
} }
type PopupInfo struct { type PopupInfo struct {
CloseStatus string `json:"close_status"` CloseStatus string `json:"close_status"` // found/success/fail
Type string `json:"type"` Type string `json:"type"`
Text string `json:"text"` Text string `json:"text"`
RetryCount int `json:"retry_count"` RetryCount int `json:"retry_count"`
@@ -50,8 +50,8 @@ func (dExt *DriverExt) ClosePopups(options ...ActionOption) error {
} }
func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error { func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
log.Info().Msg("try to find and close popups")
actionOptions := NewActionOptions(options...) actionOptions := NewActionOptions(options...)
log.Info().Interface("actionOptions", actionOptions).Msg("try to find and close popups")
maxRetryTimes := actionOptions.MaxRetryTimes maxRetryTimes := actionOptions.MaxRetryTimes
interval := actionOptions.Interval interval := actionOptions.Interval
@@ -62,17 +62,22 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
log.Error().Err(err).Msg("get screen result failed for popup handler") log.Error().Err(err).Msg("get screen result failed for popup handler")
continue continue
} }
screenResult.Popup.RetryCount = retryCount
// 1. there are no popups here (fast return normally) // 1. there are no popups here (fast return normally)
// 2. failed to close popup maybe tap error, return error // 2. failed to close popup maybe tap error, return error
// 3. successful to close popup (sleep and wait for next retry if existed) // 3. successful to close popup (sleep and wait for next retry if existed)
if screenResult.Popup == nil { if screenResult.Popup == nil {
log.Debug().Msg("no popup found")
break break
} }
screenResult.Popup.RetryCount = retryCount
// popup found
if !screenResult.Popup.PopupArea.IsEmpty() { if !screenResult.Popup.PopupArea.IsEmpty() {
screenResult.Popup.CloseStatus = CloseStatusFound screenResult.Popup.CloseStatus = CloseStatusFound
} }
if screenResult.Popup.CloseArea.IsEmpty() { if screenResult.Popup.CloseArea.IsEmpty() {
log.Warn().Msg("popup close area not found")
break break
} }
screenResult.Popup.CloseStatus = CloseStatusFound screenResult.Popup.CloseStatus = CloseStatusFound
@@ -80,6 +85,8 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
if err = dExt.tapPopupHandler(screenResult.Popup); err != nil { if err = dExt.tapPopupHandler(screenResult.Popup); err != nil {
return err return err
} }
log.Info().Interface("popup", screenResult.Popup).Msg("close popup success")
// sleep for another popup (if existed) to pop // sleep for another popup (if existed) to pop
time.Sleep(time.Duration(1000*interval) * time.Millisecond) time.Sleep(time.Duration(1000*interval) * time.Millisecond)
} }
@@ -91,11 +98,16 @@ func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error {
return nil return nil
} }
if popup.CloseArea.IsEmpty() { if popup.CloseArea.IsEmpty() {
log.Warn().Msg("popup close area not found")
return nil return nil
} }
log.Info().Str("type", popup.Type).Str("text", popup.Text).Msg("close popup")
popupCenter := popup.CloseArea.Center() closePoint := popup.CloseArea.Center()
if err := dExt.TapAbsXY(popupCenter.X, popupCenter.Y); err != nil { log.Info().
Interface("popup", popup).
Interface("closePoint", closePoint).
Msg("tap to close popup")
if err := dExt.TapAbsXY(closePoint.X, closePoint.Y); err != nil {
log.Error().Err(err).Msg("tap popup failed") log.Error().Err(err).Msg("tap popup failed")
return errors.Wrap(code.MobileUIPopupError, err.Error()) return errors.Wrap(code.MobileUIPopupError, err.Error())
} }
+1 -1
View File
@@ -150,7 +150,7 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption)
} }
points, err := screenResult.Texts.FindTexts(texts, dExt.ParseActionOptions(optionsWithoutIdentifier...)...) points, err := screenResult.Texts.FindTexts(texts, dExt.ParseActionOptions(optionsWithoutIdentifier...)...)
if err != nil { if err != nil {
log.Error().Err(err).Msg("swipeToTapTexts failed") log.Error().Err(err).Strs("texts", texts).Msg("find texts failed")
// target texts not found, try to auto handle popup // target texts not found, try to auto handle popup
if e := dExt.tapPopupHandler(screenResult.Popup); e != nil { if e := dExt.tapPopupHandler(screenResult.Popup); e != nil {
log.Error().Err(e).Msg("auto handle popup failed") log.Error().Err(e).Msg("auto handle popup failed")
+1 -1
View File
@@ -251,7 +251,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
continue continue
} }
if e := crawler.driverExt.tapPopupHandler(screenResult.Popup); e != nil { if e := crawler.driverExt.tapPopupHandler(screenResult.Popup); e != nil {
log.Error().Err(e).Msg("auto handle popup failed") log.Error().Err(e).Msg("close live popup failed")
continue continue
} }