Merge branch 'fix-popup' into 'master'

Fix popup

See merge request iesqa/httprunner!13
This commit is contained in:
徐聪
2023-09-22 13:51:38 +00:00
2 changed files with 28 additions and 17 deletions
+20 -11
View File
@@ -1,6 +1,8 @@
package uixt package uixt
import ( import (
"math/rand"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@@ -97,7 +99,7 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) {
return nil, nil return nil, nil
} }
// 弹框不存在 & 关闭按钮不存在 // 弹框不存在 && 关闭按钮不存在
if closeResult.PopupArea.IsEmpty() && closeResult.CloseArea.IsEmpty() { if closeResult.PopupArea.IsEmpty() && closeResult.CloseArea.IsEmpty() {
if p.ClosePoints == nil { if p.ClosePoints == nil {
// 关闭图标不存在 => 100% 确定不存在弹窗 // 关闭图标不存在 => 100% 确定不存在弹窗
@@ -119,7 +121,7 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) {
Interface("closePoint", p.ClosePoints[0]). Interface("closePoint", p.ClosePoints[0]).
Interface("lastClosePoints", lastPopup.ClosePoints). Interface("lastClosePoints", lastPopup.ClosePoints).
Msg("popup close point detected") Msg("popup close point detected")
return &p.ClosePoints[0], nil return getRandomClosePoint(p.ClosePoints), nil
} }
// 连续两次图标位置不同 => 可能不是弹窗 => skip // 连续两次图标位置不同 => 可能不是弹窗 => skip
@@ -129,7 +131,7 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) {
return nil, nil return nil, nil
} }
// 弹窗存在 & 关闭按钮不存在 // 弹窗存在 && 关闭按钮不存在
if !closeResult.PopupArea.IsEmpty() && closeResult.CloseArea.IsEmpty() { if !closeResult.PopupArea.IsEmpty() && closeResult.CloseArea.IsEmpty() {
if p.ClosePoints == nil { if p.ClosePoints == nil {
// 关闭图标不存在 => 无法处理,抛异常 // 关闭图标不存在 => 无法处理,抛异常
@@ -137,19 +139,26 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) {
return nil, errors.Wrap(code.MobileUIPopupError, "popup close area not found") return nil, errors.Wrap(code.MobileUIPopupError, "popup close area not found")
} }
// 使用关闭图标作为关闭按钮 // 使用关闭图标作为关闭按钮(随机选择一个)
return &p.ClosePoints[0], nil return getRandomClosePoint(p.ClosePoints), nil
} }
closePoint := closeResult.CloseArea.Center() // 关闭按钮存在 && (弹框存在 || 不存在)
if closeResult.Type != "" || p.ClosePoints == nil {
// 弹窗存在 & 关闭按钮存在 => 可能是文字弹窗 => 基于关闭按钮关闭弹窗 // 弹窗类型存在 || 关闭图标不存在 => 基于关闭按钮关闭弹窗
if closeResult.PopupArea.IsEmpty() && !closeResult.CloseArea.IsEmpty() { closePoint := closeResult.CloseArea.Center()
return &closePoint, nil return &closePoint, nil
} else {
// 弹窗类型不存在 && 关闭图标存在,使用关闭图标作为关闭按钮(随机选择一个)
return getRandomClosePoint(p.ClosePoints), nil
} }
}
// 弹窗存在 & 关闭按钮存在 => 检测到弹窗存在 => 基于关闭按钮关闭弹窗 func getRandomClosePoint(closePoints []PointF) *PointF {
return &closePoint, nil if len(closePoints) == 1 {
return &closePoints[0]
}
return &closePoints[rand.Intn(len(closePoints))]
} }
func (dExt *DriverExt) ClosePopupsHandler() (err error) { func (dExt *DriverExt) ClosePopupsHandler() (err error) {
+8 -6
View File
@@ -205,9 +205,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
log.Info().Interface("video", currentVideo). log.Info().Interface("video", currentVideo).
Msg("live count achieved, skip entering live room") Msg("live count achieved, skip entering live room")
skipEnterLive = true skipEnterLive = true
} else if rand.Float64() <= 0.25 { } else if rand.Float64() <= 0.10 {
// 25% chance skip entering live room // 10% chance skip entering live room
log.Info().Msg("skip entering preview live by 25% chance") log.Info().Msg("skip entering preview live by 10% chance")
skipEnterLive = true skipEnterLive = true
} }
@@ -239,6 +239,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
crawler.LiveCount++ crawler.LiveCount++
log.Info().Interface("video", currentVideo).Msg(FOUND_LIVE_SUCCESS) log.Info().Interface("video", currentVideo).Msg(FOUND_LIVE_SUCCESS)
// wait 3s for live loading
time.Sleep(3 * time.Second)
// take screenshot and get screen texts by OCR // take screenshot and get screen texts by OCR
screenResult, err := crawler.driverExt.GetScreenResult( screenResult, err := crawler.driverExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotOCR(true),
@@ -272,9 +274,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
log.Info().Interface("live", currentVideo). log.Info().Interface("live", currentVideo).
Msg("live count achieved, exit live room") Msg("live count achieved, exit live room")
exitLive = true exitLive = true
} else if rand.Float64() <= 0.25 { } else if rand.Float64() <= 0.10 {
// 25% chance exit live room // 10% chance exit live room
log.Info().Msg("exit live room by 25% chance") log.Info().Msg("exit live room by 10% chance")
exitLive = true exitLive = true
} }
if exitLive && currentVideo.Type == VideoType_Live { if exitLive && currentVideo.Type == VideoType_Live {