mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
feat: add GetScreenTexts
This commit is contained in:
@@ -150,7 +150,7 @@ func NewWorldCupLive(device uixt.Device, matchName, bundleID string, duration, i
|
|||||||
|
|
||||||
func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
|
func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
|
||||||
utcTimeStr := utcTime.Format("15:04:05")
|
utcTimeStr := utcTime.Format("15:04:05")
|
||||||
imageResult, err := wc.driver.GetScreenResult()
|
ocrTexts, err := wc.driver.GetScreenTexts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("get ocr texts failed")
|
log.Error().Err(err).Msg("get ocr texts failed")
|
||||||
return err
|
return err
|
||||||
@@ -159,7 +159,7 @@ func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
|
|||||||
// filter ocr texts with time format
|
// filter ocr texts with time format
|
||||||
secondsMap := map[string]int{}
|
secondsMap := map[string]int{}
|
||||||
var secondsTexts []string
|
var secondsTexts []string
|
||||||
for _, ocrText := range imageResult.OCRResult.ToOCRTexts() {
|
for _, ocrText := range ocrTexts {
|
||||||
seconds, err := convertTimeToSeconds(ocrText.Text)
|
seconds, err := convertTimeToSeconds(ocrText.Text)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
secondsTexts = append(secondsTexts, ocrText.Text)
|
secondsTexts = append(secondsTexts, ocrText.Text)
|
||||||
@@ -212,9 +212,8 @@ func (wc *WorldCupLive) EnterLive(bundleID string) error {
|
|||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
// 青少年弹窗处理
|
// 青少年弹窗处理
|
||||||
if imageResult, err := wc.driver.GetScreenResult(); err == nil {
|
if ocrTexts, err := wc.driver.GetScreenTexts(); err == nil {
|
||||||
if points, err := imageResult.OCRResult.ToOCRTexts().
|
if points, err := ocrTexts.FindTexts([]string{"青少年模式", "我知道了"}); err == nil {
|
||||||
FindTexts([]string{"青少年模式", "我知道了"}); err == nil {
|
|
||||||
point := points[1].Center()
|
point := points[1].Center()
|
||||||
_ = wc.driver.TapAbsXY(point.X, point.Y)
|
_ = wc.driver.TapAbsXY(point.X, point.Y)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ func TestIOSDemo(t *testing.T) {
|
|||||||
// 持续监测手机屏幕,直到出现青少年模式弹窗后,点击「我知道了」
|
// 持续监测手机屏幕,直到出现青少年模式弹窗后,点击「我知道了」
|
||||||
for {
|
for {
|
||||||
// take screenshot and get screen texts by OCR
|
// take screenshot and get screen texts by OCR
|
||||||
imageResult, err := driverExt.GetScreenResult()
|
ocrTexts, err := driverExt.GetScreenTexts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
points, err := imageResult.OCRResult.ToOCRTexts().FindTexts([]string{"青少年模式", "我知道了"})
|
points, err := ocrTexts.FindTexts([]string{"青少年模式", "我知道了"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -360,12 +360,21 @@ func (dExt *DriverExt) GetScreenResult() (imageResult ImageResult, err error) {
|
|||||||
return imageResult, nil
|
return imageResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) FindScreenText(text string, options ...ActionOption) (point PointF, err error) {
|
func (dExt *DriverExt) GetScreenTexts() (ocrTexts OCRTexts, err error) {
|
||||||
imageResult, err := dExt.GetScreenResult()
|
imageResult, err := dExt.GetScreenResult()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result, err := imageResult.OCRResult.ToOCRTexts().FindText(text, dExt.ParseActionOptions(options...)...)
|
return imageResult.OCRResult.ToOCRTexts(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dExt *DriverExt) FindScreenText(text string, options ...ActionOption) (point PointF, err error) {
|
||||||
|
ocrTexts, err := dExt.GetScreenTexts()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := ocrTexts.FindText(text, dExt.ParseActionOptions(options...)...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Msgf("FindText failed: %s", err.Error())
|
log.Warn().Msgf("FindText failed: %s", err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -135,12 +135,11 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption)
|
|||||||
var point PointF
|
var point PointF
|
||||||
findTexts := func(d *DriverExt) error {
|
findTexts := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
imageResult, err := d.GetScreenResult()
|
ocrTexts, err := d.GetScreenTexts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
points, err := imageResult.OCRResult.ToOCRTexts().
|
points, err := ocrTexts.FindTexts(texts, dExt.ParseActionOptions(options...)...)
|
||||||
FindTexts(texts, dExt.ParseActionOptions(options...)...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user