refactor: ClosePopupsHandler

This commit is contained in:
lilong.129
2023-09-21 22:23:32 +08:00
parent d1c30000a7
commit 4a96dea903
4 changed files with 18 additions and 25 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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")
}