mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
Merge branch 'fix-popup' into 'master'
Fix popup See merge request iesqa/httprunner!10
This commit is contained in:
@@ -668,7 +668,19 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
|
|||||||
}
|
}
|
||||||
return dExt.VideoCrawler(configs)
|
return dExt.VideoCrawler(configs)
|
||||||
case ACTION_ClosePopups:
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/httprunner/funplugin"
|
"github.com/httprunner/funplugin"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -438,8 +436,8 @@ type PointF struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p PointF) IsIdentical(p2 PointF) bool {
|
func (p PointF) IsIdentical(p2 PointF) bool {
|
||||||
return builtin.IsZeroFloat64(math.Abs(p.X-p2.X)) &&
|
// set the coordinate precision to 1 pixel
|
||||||
builtin.IsZeroFloat64(math.Abs(p.Y-p2.Y))
|
return math.Abs(p.X-p2.X) < 1 && math.Abs(p.Y-p2.Y) < 1
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rect struct {
|
type Rect struct {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,22 +88,20 @@ type ClosePopupsResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PopupInfo struct {
|
type PopupInfo struct {
|
||||||
CloseStatus string `json:"close_status"` // found/success/fail
|
CloseStatus string `json:"close_status"` // found/success/fail
|
||||||
Type string `json:"type"`
|
RetryCount int `json:"retry_count"`
|
||||||
Text string `json:"text"`
|
CloseBox Box `json:"close_box"` // CV 识别的弹窗关闭按钮(弹窗存在 && 关闭按钮存在)
|
||||||
RetryCount int `json:"retry_count"`
|
ClosePoints []PointF `json:"close_points,omitempty"` // CV 识别的所有关闭按钮(仅关闭按钮,可能存在多个)
|
||||||
PicName string `json:"pic_name"`
|
|
||||||
PicURL string `json:"pic_url"`
|
|
||||||
PopupArea Box `json:"popup_area"`
|
|
||||||
CloseArea Box `json:"close_area"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool {
|
func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool {
|
||||||
if lastPopup == nil || lastPopup.PopupArea.IsEmpty() {
|
if lastPopup == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if lastPopup.CloseBox.IsEmpty() {
|
||||||
if !p.CloseArea.IsIdentical(lastPopup.CloseArea) {
|
return false
|
||||||
|
}
|
||||||
|
if !p.CloseBox.IsIdentical(lastPopup.CloseBox) {
|
||||||
lastPopup.CloseStatus = CloseStatusSuccess
|
lastPopup.CloseStatus = CloseStatusSuccess
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -114,24 +111,6 @@ func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PopupInfo) exists() bool {
|
|
||||||
return p.PopupArea.IsEmpty() || p.CloseArea.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 {
|
func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
||||||
actionOptions := NewActionOptions(options...)
|
actionOptions := NewActionOptions(options...)
|
||||||
log.Info().Interface("actionOptions", actionOptions).Msg("try to find and close popups")
|
log.Info().Interface("actionOptions", actionOptions).Msg("try to find and close popups")
|
||||||
@@ -141,15 +120,18 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
|||||||
var lastPopup *PopupInfo
|
var lastPopup *PopupInfo
|
||||||
for retryCount := 0; retryCount < maxRetryTimes; retryCount++ {
|
for retryCount := 0; retryCount < maxRetryTimes; retryCount++ {
|
||||||
screenResult, err := dExt.GetScreenResult(
|
screenResult, err := dExt.GetScreenResult(
|
||||||
WithScreenShotClosePopups(true), WithScreenShotUpload(true))
|
WithScreenShotUpload(true),
|
||||||
|
WithScreenShotClosePopups(true),
|
||||||
|
WithScreenShotUITypes("close"), // get all close buttons
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
popup := screenResult.Popup
|
popup := screenResult.Popup
|
||||||
if popup == nil || !popup.exists() {
|
if popup == nil || popup.CloseBox.IsEmpty() {
|
||||||
log.Debug().Msg("no popup found")
|
log.Debug().Interface("popup", popup).Msg("no popup found")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
popup.CloseStatus = CloseStatusFound
|
popup.CloseStatus = CloseStatusFound
|
||||||
@@ -172,13 +154,13 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error {
|
func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error {
|
||||||
if popup == nil || !popup.exists() {
|
if popup == nil || popup.CloseBox.IsEmpty() {
|
||||||
log.Debug().Msg("no popup found")
|
log.Debug().Interface("popup", popup).Msg("no popup found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
popup.CloseStatus = CloseStatusFound
|
popup.CloseStatus = CloseStatusFound
|
||||||
|
|
||||||
popupClose := popup.CloseArea
|
popupClose := popup.CloseBox
|
||||||
if popupClose.IsEmpty() {
|
if popupClose.IsEmpty() {
|
||||||
log.Error().
|
log.Error().
|
||||||
Interface("popup", popup).
|
Interface("popup", popup).
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ type ImageResult struct {
|
|||||||
// Media(媒体)
|
// Media(媒体)
|
||||||
// Chat(语音)
|
// Chat(语音)
|
||||||
// Event(赛事)
|
// Event(赛事)
|
||||||
LiveType string `json:"liveType,omitempty"` // 直播间类型
|
LiveType string `json:"liveType,omitempty"` // 直播间类型
|
||||||
UIResult UIResultMap `json:"uiResult,omitempty"` // 图标检测
|
UIResult UIResultMap `json:"uiResult,omitempty"` // 图标检测
|
||||||
CPResult *ClosePopupsResult `json:"closeResult,omitempty"` // 弹窗按钮检测
|
ClosePopupsResult *ClosePopupsResult `json:"closeResult,omitempty"` // 弹窗按钮检测
|
||||||
}
|
}
|
||||||
|
|
||||||
type APIResponseImage struct {
|
type APIResponseImage struct {
|
||||||
@@ -407,15 +407,20 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
|
|||||||
screenResult.UploadedURL = imageResult.URL
|
screenResult.UploadedURL = imageResult.URL
|
||||||
screenResult.Icons = imageResult.UIResult
|
screenResult.Icons = imageResult.UIResult
|
||||||
|
|
||||||
if actionOptions.ScreenShotWithClosePopups && imageResult.CPResult != nil {
|
if actionOptions.ScreenShotWithClosePopups {
|
||||||
screenResult.Popup = &PopupInfo{
|
popup := &PopupInfo{}
|
||||||
Type: imageResult.CPResult.Type,
|
|
||||||
Text: imageResult.CPResult.Text,
|
closeResult := imageResult.ClosePopupsResult
|
||||||
PicName: imagePath,
|
if closeResult != nil && !closeResult.PopupArea.IsEmpty() && !closeResult.CloseArea.IsEmpty() {
|
||||||
PicURL: imageResult.URL,
|
popup.CloseBox = closeResult.CloseArea
|
||||||
PopupArea: imageResult.CPResult.PopupArea,
|
|
||||||
CloseArea: imageResult.CPResult.CloseArea,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeAreas, _ := imageResult.UIResult.FilterUIResults([]string{"close"})
|
||||||
|
for _, closeArea := range closeAreas {
|
||||||
|
popup.ClosePoints = append(popup.ClosePoints, closeArea.Center())
|
||||||
|
}
|
||||||
|
|
||||||
|
screenResult.Popup = popup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,9 +483,10 @@ func (box Box) IsEmpty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (box Box) IsIdentical(box2 Box) bool {
|
func (box Box) IsIdentical(box2 Box) bool {
|
||||||
|
// set the coordinate precision to 1 pixel
|
||||||
return box.Point.IsIdentical(box2.Point) &&
|
return box.Point.IsIdentical(box2.Point) &&
|
||||||
builtin.IsZeroFloat64(math.Abs(box.Width-box2.Width)) &&
|
math.Abs(box.Width-box2.Width) < 1 &&
|
||||||
builtin.IsZeroFloat64(math.Abs(box.Height-box2.Height))
|
math.Abs(box.Height-box2.Height) < 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (box Box) Center() PointF {
|
func (box Box) Center() PointF {
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
log.Warn().Msg("get current feed video failed")
|
log.Warn().Msg("get current feed video failed")
|
||||||
|
|
||||||
// check and handle popups
|
// check and handle popups
|
||||||
if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(3)); err != nil {
|
if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(1)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -624,7 +624,7 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// automatic handling of pop-up windows on each step finished
|
// 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")
|
log.Error().Err(err2).Str("step", step.Name).Msg("handle popup failed on step finished")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user