mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 19:39:44 +08:00
fix: check if the current popup equals to the last popup
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -87,40 +86,6 @@ func (screenResults ScreenResultMap) getScreenShotUrls() map[string]string {
|
||||
return screenShotsUrls
|
||||
}
|
||||
|
||||
// updatePopupCloseStatus checks if popup closed normally in every screenResult with close_popups on:
|
||||
func (screenResults ScreenResultMap) updatePopupCloseStatus() {
|
||||
var popupScreenResultList []*ScreenResult
|
||||
for _, screenResult := range screenResults {
|
||||
if screenResult.Popup == nil {
|
||||
continue
|
||||
}
|
||||
popupScreenResultList = append(popupScreenResultList, screenResult)
|
||||
}
|
||||
if len(popupScreenResultList) == 0 {
|
||||
return
|
||||
}
|
||||
sort.Slice(popupScreenResultList, func(i, j int) bool {
|
||||
return popupScreenResultList[i].Popup.RetryCount < popupScreenResultList[j].Popup.RetryCount
|
||||
})
|
||||
|
||||
for i := 0; i < len(popupScreenResultList)-1; i++ {
|
||||
curPopup := popupScreenResultList[i].Popup
|
||||
nextPopup := popupScreenResultList[i+1].Popup
|
||||
|
||||
// popup not existed, no need to close
|
||||
if curPopup.CloseArea.IsEmpty() {
|
||||
continue
|
||||
}
|
||||
// popup existed, but identical popups occurs during next retry
|
||||
if nextPopup.CloseArea.IsIdentical(curPopup.CloseArea) {
|
||||
popupScreenResultList[i].Popup.CloseStatus = CloseStatusFail
|
||||
continue
|
||||
}
|
||||
// popup existed, but no popup or different popup occurs during next retry (IsClosed=true)
|
||||
popupScreenResultList[i].Popup.CloseStatus = CloseStatusSuccess
|
||||
}
|
||||
}
|
||||
|
||||
type cacheStepData struct {
|
||||
// cache step screenshot paths
|
||||
screenShots []string
|
||||
@@ -273,7 +238,6 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
|
||||
cacheData["screenshots"] = dExt.cacheStepData.screenShots
|
||||
|
||||
cacheData["screenshots_urls"] = dExt.cacheStepData.screenResults.getScreenShotUrls()
|
||||
dExt.cacheStepData.screenResults.updatePopupCloseStatus()
|
||||
cacheData["screen_results"] = dExt.cacheStepData.screenResults
|
||||
|
||||
// clear cache
|
||||
|
||||
@@ -119,6 +119,7 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
||||
maxRetryTimes := actionOptions.MaxRetryTimes
|
||||
interval := actionOptions.Interval
|
||||
|
||||
var lastPopup *PopupInfo
|
||||
for retryCount := 0; retryCount < maxRetryTimes; retryCount++ {
|
||||
screenResult, err := dExt.GetScreenResult(
|
||||
WithScreenShotClosePopups(true), WithScreenShotUpload(true))
|
||||
@@ -132,18 +133,40 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
||||
log.Debug().Msg("no popup found")
|
||||
break
|
||||
}
|
||||
popup.CloseStatus = CloseStatusFound
|
||||
popup.RetryCount = retryCount
|
||||
|
||||
// check if the current popup equals to the last popup
|
||||
if isPopupIdentical(popup, lastPopup) {
|
||||
return errors.Wrap(code.MobileUIPopupError, "handle popup failed")
|
||||
}
|
||||
|
||||
if err = dExt.tapPopupHandler(popup); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// sleep for another popup (if existed) to pop
|
||||
time.Sleep(time.Duration(1000*interval) * time.Millisecond)
|
||||
lastPopup = popup
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isPopupIdentical(popup, lastPopup *PopupInfo) bool {
|
||||
if lastPopup == nil || lastPopup.PopupArea.IsEmpty() {
|
||||
return false
|
||||
}
|
||||
|
||||
if !popup.CloseArea.IsIdentical(lastPopup.CloseArea) {
|
||||
lastPopup.CloseStatus = CloseStatusSuccess
|
||||
return false
|
||||
}
|
||||
|
||||
popup.CloseStatus = CloseStatusFail
|
||||
lastPopup.CloseStatus = CloseStatusFail
|
||||
return true
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error {
|
||||
if popup == nil || popup.PopupArea.IsEmpty() {
|
||||
log.Debug().Msg("no popup found")
|
||||
|
||||
Reference in New Issue
Block a user