feat: locate ocr text with index

This commit is contained in:
debugtalk
2022-09-26 22:25:13 +08:00
parent 1de68a1847
commit 1122e7db5b
14 changed files with 249 additions and 32 deletions

View File

@@ -0,0 +1,89 @@
{
"config": {
"name": "通过 feed 卡片进入微信直播间",
"ios": [
{
"port": 8700,
"mjpeg_port": 8800,
"log_on": true
}
]
},
"teststeps": [
{
"name": "启动抖音",
"ios": {
"actions": [
{
"method": "home"
},
{
"method": "app_terminate",
"params": "com.ss.iphone.ugc.Aweme"
},
{
"method": "swipe_to_tap_app",
"params": "抖音",
"max_retry_times": 5
},
{
"method": "sleep",
"params": 5
}
]
},
"validate": [
{
"check": "ui_ocr",
"assert": "exists",
"expect": "推荐",
"msg": "抖音启动失败,「推荐」不存在"
}
]
},
{
"name": "在推荐页上划,直到出现「点击进入直播间」",
"ios": {
"actions": [
{
"method": "swipe_to_tap_text",
"params": "点击进入直播间",
"identifier": "进入直播间",
"max_retry_times": 100
}
]
}
},
{
"name": "向上滑动,等待 10s",
"ios": {
"actions": [
{
"method": "swipe",
"params": "up",
"identifier": "第一次上划"
},
{
"method": "sleep",
"params": 2
},
{
"method": "screenshot"
},
{
"method": "swipe",
"params": "up",
"identifier": "第二次上划"
},
{
"method": "sleep",
"params": 2
},
{
"method": "screenshot"
}
]
}
}
]
}

View File

@@ -0,0 +1,45 @@
config:
name: 通过 feed 卡片进入微信直播间
ios:
- port: 8700
mjpeg_port: 8800
log_on: true
teststeps:
- name: 启动抖音
ios:
actions:
- method: home
- method: app_terminate
params: com.ss.iphone.ugc.Aweme
- method: swipe_to_tap_app
params: 抖音
max_retry_times: 5
- method: sleep
params: 5
validate:
- check: ui_ocr
assert: exists
expect: 推荐
msg: 抖音启动失败,「推荐」不存在
- name: 在推荐页上划,直到出现「点击进入直播间」
ios:
actions:
- method: swipe_to_tap_text
params: 点击进入直播间
identifier: 进入直播间
max_retry_times: 100
- name: 向上滑动,等待 10s
ios:
actions:
- method: swipe
params: up
identifier: 第一次上划
- method: sleep
params: 2
- method: screenshot
- method: swipe
params: up
identifier: 第二次上划
- method: sleep
params: 2
- method: screenshot

View File

@@ -0,0 +1,52 @@
package uitest
import (
"fmt"
"testing"
"github.com/httprunner/httprunner/v4/hrp"
)
func TestIOSDouyinLive(t *testing.T) {
testCase := &hrp.TestCase{
Config: hrp.NewConfig("通过 feed 卡片进入微信直播间").
SetIOS(hrp.WithLogOn(true), hrp.WithPort(8700), hrp.WithMjpegPort(8800)),
TestSteps: []hrp.IStep{
hrp.NewStep("启动抖音").
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("抖音", hrp.WithMaxRetryTimes(5)).Sleep(5).
Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
// hrp.NewStep("处理青少年弹窗").
// IOS().
// TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
hrp.NewStep("在推荐页上划,直到出现「点击进入直播间」").
IOS().
SwipeToTapText("点击进入直播间", hrp.WithMaxRetryTimes(100), hrp.WithIdentifier("进入直播间")),
hrp.NewStep("向上滑动,等待 10s").
IOS().
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s截图保存
SwipeUp(hrp.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s截图保存
},
}
if err := testCase.Dump2JSON("demo_douyin_live.json"); err != nil {
t.Fatal(err)
}
if err := testCase.Dump2YAML("demo_douyin_live.yaml"); err != nil {
t.Fatal(err)
}
runner := hrp.NewRunner(t)
sessionRunner, err := runner.NewSessionRunner(testCase)
if err != nil {
t.Fatal(err)
}
if err := sessionRunner.Start(nil); err != nil {
t.Fatal(err)
}
summary := sessionRunner.GetSummary()
fmt.Println(summary)
}

View File

@@ -48,7 +48,8 @@
{
"method": "tap_ocr",
"params": "视频号",
"identifier": "进入视频号"
"identifier": "进入视频号",
"index": -1
}
]
}

View File

@@ -27,6 +27,7 @@ teststeps:
- method: tap_ocr
params: 视频号
identifier: 进入视频号
index: -1
- name: 处理青少年弹窗
ios:
actions:

View File

@@ -21,8 +21,8 @@ func TestIOSWeixinLive(t *testing.T) {
AssertLabelExists("通讯录", "微信启动失败,「通讯录」不存在"),
hrp.NewStep("进入直播页").
IOS().
Tap("发现"). // 进入「发现页」
TapByOCR("视频号", hrp.WithIdentifier("进入视频号")), // 通过 OCR 识别「视频号」
Tap("发现"). // 进入「发现页」
TapByOCR("视频号", hrp.WithIdentifier("进入视频号"), hrp.WithIndex(-1)), // 通过 OCR 识别「视频号」
hrp.NewStep("处理青少年弹窗").
IOS().
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),