mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-26 01:51:29 +08:00
refactor: GetScreenTextsByOCR returns image path and ocr texts
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")
|
||||
ocrTexts, err := wc.driver.GetScreenTextsByOCR()
|
||||
_, ocrTexts, err := wc.driver.GetScreenTextsByOCR()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("get ocr texts failed")
|
||||
return err
|
||||
@@ -212,7 +212,7 @@ func (wc *WorldCupLive) EnterLive(bundleID string) error {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// 青少年弹窗处理
|
||||
if ocrTexts, err := wc.driver.GetScreenTextsByOCR(); err == nil {
|
||||
if _, ocrTexts, err := wc.driver.GetScreenTextsByOCR(); err == nil {
|
||||
if points, err := ocrTexts.FindTexts([]string{"青少年模式", "我知道了"}); err == nil {
|
||||
point := points[1].Center()
|
||||
_ = wc.driver.TapAbsXY(point.X, point.Y)
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestIOSDemo(t *testing.T) {
|
||||
// 持续监测手机屏幕,直到出现青少年模式弹窗后,点击「我知道了」
|
||||
for {
|
||||
// take screenshot and get screen texts by OCR
|
||||
texts, err := driverExt.GetScreenTextsByOCR()
|
||||
_, texts, err := driverExt.GetScreenTextsByOCR()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -280,15 +280,15 @@ type IOCRService interface {
|
||||
GetTexts(imageBuf *bytes.Buffer) (texts OCRTexts, err error)
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) GetScreenTextsByOCR() (texts OCRTexts, err error) {
|
||||
// GetScreenTextsByOCR takes a screenshot, returns the image path and OCR texts.
|
||||
func (dExt *DriverExt) GetScreenTextsByOCR() (imagePath string, ocrTexts OCRTexts, err error) {
|
||||
var bufSource *bytes.Buffer
|
||||
var imagePath string
|
||||
if bufSource, imagePath, err = dExt.TakeScreenShot(
|
||||
builtin.GenNameWithTimestamp("%d_ocr")); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ocrTexts, err := dExt.OCRService.GetTexts(bufSource)
|
||||
ocrTexts, err = dExt.OCRService.GetTexts(bufSource)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("GetScreenTextsByOCR failed")
|
||||
return
|
||||
@@ -296,11 +296,11 @@ func (dExt *DriverExt) GetScreenTextsByOCR() (texts OCRTexts, err error) {
|
||||
|
||||
o, _ := json.Marshal(ocrTexts)
|
||||
dExt.cacheStepData.OcrResults[imagePath] = string(o)
|
||||
return ocrTexts, nil
|
||||
return imagePath, ocrTexts, nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) FindScreenTextByOCR(text string, options ...ActionOption) (point PointF, err error) {
|
||||
ocrTexts, err := dExt.GetScreenTextsByOCR()
|
||||
_, ocrTexts, err := dExt.GetScreenTextsByOCR()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (dExt *DriverExt) swipeToTapTexts(texts []string, options ...ActionOption)
|
||||
var point PointF
|
||||
findTexts := func(d *DriverExt) error {
|
||||
var err error
|
||||
ocrTexts, err := d.GetScreenTextsByOCR()
|
||||
_, ocrTexts, err := d.GetScreenTextsByOCR()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (s *VideoStat) incrFeed(texts OCRTexts, driverExt *DriverExt) error {
|
||||
driverExt.GenAbsScope(0, 0.5, 1, 1).Option(),
|
||||
}
|
||||
if ocrText, err := texts.FindText("^@", actionOptions...); err == nil {
|
||||
log.Info().Str("author", ocrText.Text).Msg("found feed author")
|
||||
log.Debug().Str("author", ocrText.Text).Msg("found feed author")
|
||||
}
|
||||
|
||||
for _, targetLabel := range s.configs.Feed.TargetLabels {
|
||||
@@ -197,7 +197,7 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error {
|
||||
}
|
||||
|
||||
// take screenshot and get screen texts by OCR
|
||||
_, err := l.driver.GetScreenTextsByOCR()
|
||||
_, _, err := l.driver.GetScreenTextsByOCR()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||
continue
|
||||
@@ -299,7 +299,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
}
|
||||
|
||||
// take screenshot and get screen texts by OCR
|
||||
texts, err := dExt.GetScreenTextsByOCR()
|
||||
_, texts, err := dExt.GetScreenTextsByOCR()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user