mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
fix: get ocr exact text in first priority
This commit is contained in:
@@ -21,19 +21,17 @@ func TestIOSWeixinLive(t *testing.T) {
|
|||||||
hrp.NewStep("进入直播页").
|
hrp.NewStep("进入直播页").
|
||||||
IOS().
|
IOS().
|
||||||
Tap("发现"). // 进入「发现页」
|
Tap("发现"). // 进入「发现页」
|
||||||
TapByOCR("视频号"). // 通过 OCR 识别「视频号」
|
TapByOCR("视频号"), // 通过 OCR 识别「视频号」
|
||||||
Validate().
|
|
||||||
AssertLabelExists("视频号"),
|
|
||||||
hrp.NewStep("处理青少年弹窗").
|
hrp.NewStep("处理青少年弹窗").
|
||||||
IOS().
|
IOS().
|
||||||
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(false)),
|
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
||||||
hrp.NewStep("在推荐页上划,直到出现「轻触进入直播间」").
|
hrp.NewStep("在推荐页上划,直到出现「轻触进入直播间」").
|
||||||
IOS().
|
IOS().
|
||||||
SwipeToTapText("轻触进入直播间", hrp.WithMaxRetryTimes(10)),
|
SwipeToTapText("轻触进入直播间", hrp.WithMaxRetryTimes(10)),
|
||||||
hrp.NewStep("向上滑动,等待 60s").
|
hrp.NewStep("向上滑动,等待 10s").
|
||||||
IOS().
|
IOS().
|
||||||
SwipeUp().Sleep(60).ScreenShot(). // 上划 1 次,等待 60s,截图保存
|
SwipeUp().Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||||
SwipeUp().Times(60).ScreenShot(), // 再上划 1 次,等待 60s,截图保存
|
SwipeUp().Times(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
fmt.Println(testCase)
|
fmt.Println(testCase)
|
||||||
|
|||||||
@@ -92,14 +92,13 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte) (rect image.Rec
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rects []image.Rectangle
|
||||||
for _, ocrResult := range ocrResults {
|
for _, ocrResult := range ocrResults {
|
||||||
// not contains text
|
// not contains text
|
||||||
if !strings.Contains(ocrResult.Text, text) {
|
if !strings.Contains(ocrResult.Text, text) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// contains text
|
|
||||||
// only find the first matched one
|
|
||||||
rect = image.Rectangle{
|
rect = image.Rectangle{
|
||||||
// ocrResult.Points 顺序:左上 -> 右上 -> 右下 -> 左下
|
// ocrResult.Points 顺序:左上 -> 右上 -> 右下 -> 左下
|
||||||
Min: image.Point{
|
Min: image.Point{
|
||||||
@@ -111,7 +110,20 @@ func (s *veDEMOCRService) FindText(text string, imageBuf []byte) (rect image.Rec
|
|||||||
Y: int(ocrResult.Points[2].Y),
|
Y: int(ocrResult.Points[2].Y),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
// contains text while not match exactly
|
||||||
|
if ocrResult.Text != text {
|
||||||
|
rects = append(rects, rect)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// match exactly
|
||||||
|
return rect, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// only find the first matched one
|
||||||
|
if len(rects) > 0 {
|
||||||
|
return rects[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return image.Rectangle{}, fmt.Errorf("text %s not found", text)
|
return image.Rectangle{}, fmt.Errorf("text %s not found", text)
|
||||||
|
|||||||
@@ -460,11 +460,18 @@ func (r *HRPRunner) InitWDAClient(device WDADevice) (client *uiDriver, err error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
driverExt, err := uixt.InitWDAClient(
|
var deviceOptions []gwda.DeviceOption
|
||||||
gwda.WithSerialNumber(device.UDID),
|
if device.UDID != "" {
|
||||||
gwda.WithPort(device.Port),
|
deviceOptions = append(deviceOptions, gwda.WithSerialNumber(device.UDID))
|
||||||
gwda.WithMjpegPort(device.MjpegPort),
|
}
|
||||||
)
|
if device.Port != 0 {
|
||||||
|
deviceOptions = append(deviceOptions, gwda.WithPort(device.Port))
|
||||||
|
}
|
||||||
|
if device.MjpegPort != 0 {
|
||||||
|
deviceOptions = append(deviceOptions, gwda.WithMjpegPort(device.MjpegPort))
|
||||||
|
}
|
||||||
|
|
||||||
|
driverExt, err := uixt.InitWDAClient(deviceOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user