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