mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 16:40:50 +08:00
change: remove unused local popup handler
This commit is contained in:
@@ -10,76 +10,12 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: add more popup texts
|
|
||||||
var popups = [][]string{
|
|
||||||
{".*青少年.*", "我知道了"}, // 青少年弹窗
|
|
||||||
{".*个人信息保护.*", "同意"},
|
|
||||||
{".*通讯录.*", "拒绝"},
|
|
||||||
{".*更新.*", "以后再说|稍后|取消"},
|
|
||||||
{".*升级.*", "以后再说|稍后|取消"},
|
|
||||||
{".*定位.*", "仅.*允许"},
|
|
||||||
{".*拍照.*", "仅.*允许"},
|
|
||||||
{".*录音.*", "仅.*允许"},
|
|
||||||
{".*位置.*", "仅.*允许"},
|
|
||||||
{".*权限.*", "仅.*允许|始终允许"},
|
|
||||||
{".*允许.*", "仅.*允许|始终允许"},
|
|
||||||
{".*风险.*", "继续使用"},
|
|
||||||
{"管理使用时间", ".*忽略.*"},
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CloseStatusFound = "found"
|
CloseStatusFound = "found"
|
||||||
CloseStatusSuccess = "success"
|
CloseStatusSuccess = "success"
|
||||||
CloseStatusFail = "fail"
|
CloseStatusFail = "fail"
|
||||||
)
|
)
|
||||||
|
|
||||||
func findTextPopup(screenTexts OCRTexts) (closePoint *OCRText) {
|
|
||||||
for _, popup := range popups {
|
|
||||||
if len(popup) != 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
points, err := screenTexts.FindTexts([]string{popup[0], popup[1]}, WithRegex(true))
|
|
||||||
if err == nil {
|
|
||||||
log.Warn().Interface("popup", popup).
|
|
||||||
Interface("texts", screenTexts).Msg("text popup found")
|
|
||||||
closePoint = &points[1]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) handleTextPopup(screenTexts OCRTexts) error {
|
|
||||||
closePoint := findTextPopup(screenTexts)
|
|
||||||
if closePoint == nil {
|
|
||||||
// no popup found
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info().Str("text", closePoint.Text).Msg("close popup")
|
|
||||||
pointCenter := closePoint.Center()
|
|
||||||
if err := dExt.TapAbsXY(pointCenter.X, pointCenter.Y); err != nil {
|
|
||||||
log.Error().Err(err).Msg("tap popup failed")
|
|
||||||
return errors.Wrap(code.MobileUIPopupError, err.Error())
|
|
||||||
}
|
|
||||||
// tap popup success
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) AutoPopupHandler() error {
|
|
||||||
// TODO: check popup by activity type
|
|
||||||
|
|
||||||
// check popup by screenshot
|
|
||||||
screenResult, err := dExt.GetScreenResult(
|
|
||||||
WithScreenShotOCR(true), WithScreenShotUpload(true))
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "get screen result failed for popup handler")
|
|
||||||
}
|
|
||||||
|
|
||||||
return dExt.handleTextPopup(screenResult.Texts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClosePopupsResult represents the result of recognized popup to close
|
// ClosePopupsResult represents the result of recognized popup to close
|
||||||
type ClosePopupsResult struct {
|
type ClosePopupsResult struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,27 +51,6 @@ func TestOCRWithLocalFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func matchPopup(text string) bool {
|
|
||||||
for _, popup := range popups {
|
|
||||||
if regexp.MustCompile(popup[1]).MatchString(text) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMatchRegex(t *testing.T) {
|
|
||||||
testData := []string{
|
|
||||||
"以后再说", "我知道了", "同意", "拒绝", "稍后",
|
|
||||||
"始终允许", "继续使用", "仅在使用中允许",
|
|
||||||
}
|
|
||||||
for _, text := range testData {
|
|
||||||
if !matchPopup(text) {
|
|
||||||
t.Fatal(text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTapUIWithScreenshot(t *testing.T) {
|
func TestTapUIWithScreenshot(t *testing.T) {
|
||||||
serialNumber := os.Getenv("SERIAL_NUMBER")
|
serialNumber := os.Getenv("SERIAL_NUMBER")
|
||||||
device, _ := NewAndroidDevice(WithSerialNumber(serialNumber))
|
device, _ := NewAndroidDevice(WithSerialNumber(serialNumber))
|
||||||
|
|||||||
Reference in New Issue
Block a user