mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:19:44 +08:00
change: update logs for popup handler
This commit is contained in:
@@ -25,7 +25,7 @@ type ClosePopupsResult struct {
|
||||
}
|
||||
|
||||
type PopupInfo struct {
|
||||
CloseStatus string `json:"close_status"`
|
||||
CloseStatus string `json:"close_status"` // found/success/fail
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
RetryCount int `json:"retry_count"`
|
||||
@@ -50,8 +50,8 @@ func (dExt *DriverExt) ClosePopups(options ...ActionOption) error {
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
||||
log.Info().Msg("try to find and close popups")
|
||||
actionOptions := NewActionOptions(options...)
|
||||
log.Info().Interface("actionOptions", actionOptions).Msg("try to find and close popups")
|
||||
maxRetryTimes := actionOptions.MaxRetryTimes
|
||||
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")
|
||||
continue
|
||||
}
|
||||
screenResult.Popup.RetryCount = retryCount
|
||||
|
||||
// 1. there are no popups here (fast return normally)
|
||||
// 2. failed to close popup (maybe tap error, return error)
|
||||
// 3. successful to close popup (sleep and wait for next retry if existed)
|
||||
if screenResult.Popup == nil {
|
||||
log.Debug().Msg("no popup found")
|
||||
break
|
||||
}
|
||||
screenResult.Popup.RetryCount = retryCount
|
||||
|
||||
// popup found
|
||||
if !screenResult.Popup.PopupArea.IsEmpty() {
|
||||
screenResult.Popup.CloseStatus = CloseStatusFound
|
||||
}
|
||||
if screenResult.Popup.CloseArea.IsEmpty() {
|
||||
log.Warn().Msg("popup close area not found")
|
||||
break
|
||||
}
|
||||
screenResult.Popup.CloseStatus = CloseStatusFound
|
||||
@@ -80,6 +85,8 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
||||
if err = dExt.tapPopupHandler(screenResult.Popup); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info().Interface("popup", screenResult.Popup).Msg("close popup success")
|
||||
// sleep for another popup (if existed) to pop
|
||||
time.Sleep(time.Duration(1000*interval) * time.Millisecond)
|
||||
}
|
||||
@@ -91,11 +98,16 @@ func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error {
|
||||
return nil
|
||||
}
|
||||
if popup.CloseArea.IsEmpty() {
|
||||
log.Warn().Msg("popup close area not found")
|
||||
return nil
|
||||
}
|
||||
log.Info().Str("type", popup.Type).Str("text", popup.Text).Msg("close popup")
|
||||
popupCenter := popup.CloseArea.Center()
|
||||
if err := dExt.TapAbsXY(popupCenter.X, popupCenter.Y); err != nil {
|
||||
|
||||
closePoint := popup.CloseArea.Center()
|
||||
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")
|
||||
return errors.Wrap(code.MobileUIPopupError, err.Error())
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption)
|
||||
}
|
||||
points, err := screenResult.Texts.FindTexts(texts, dExt.ParseActionOptions(optionsWithoutIdentifier...)...)
|
||||
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
|
||||
if e := dExt.tapPopupHandler(screenResult.Popup); e != nil {
|
||||
log.Error().Err(e).Msg("auto handle popup failed")
|
||||
|
||||
@@ -251,7 +251,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user