feat: tap the first one matches text from given texts by ocr

This commit is contained in:
xucong.053
2022-10-11 14:53:21 +08:00
parent 98db4d7bfa
commit 2815d67331
12 changed files with 485 additions and 29 deletions

View File

@@ -0,0 +1,152 @@
{
"config": {
"name": "通过 关注天窗 进入指定主播抖音直播间",
"variables": {
"app_name": "抖音"
},
"ios": [
{
"port": 8100,
"mjpeg_port": 9100,
"log_on": true
}
]
},
"teststeps": [
{
"name": "启动抖音",
"ios": {
"actions": [
{
"method": "home"
},
{
"method": "app_terminate",
"params": "com.ss.iphone.ugc.Aweme"
},
{
"method": "swipe_to_tap_app",
"params": "$app_name",
"identifier": "启动抖音",
"max_retry_times": 5
},
{
"method": "sleep",
"params": 5
}
]
},
"validate": [
{
"check": "ui_ocr",
"assert": "exists",
"expect": "推荐",
"msg": "抖音启动失败,「推荐」不存在"
}
]
},
{
"name": "处理青少年弹窗",
"ios": {
"actions": [
{
"method": "tap_ocr",
"params": "我知道了",
"ignore_NotFoundError": true
}
]
}
},
{
"name": "点击首页",
"ios": {
"actions": [
{
"method": "tap_ocr",
"params": "首页",
"index": -1
},
{
"method": "sleep",
"params": 10
}
]
}
},
{
"name": "点击关注页",
"ios": {
"actions": [
{
"method": "tap_ocr",
"params": "关注",
"index": 1
},
{
"method": "sleep",
"params": 10
}
]
}
},
{
"name": "向上滑动 2 次",
"ios": {
"actions": [
{
"method": "swipe_to_tap_text",
"params": [
"理肤泉",
"婉宝"
],
"identifier": "click_live",
"direction": [
0.6,
0.2,
0.2,
0.2
]
},
{
"method": "sleep",
"params": 10
},
{
"method": "swipe",
"params": [
0.9,
0.7,
0.9,
0.3
],
"identifier": "slide_in_live"
},
{
"method": "sleep",
"params": 10
},
{
"method": "screenshot"
},
{
"method": "swipe",
"params": [
0.9,
0.7,
0.9,
0.3
],
"identifier": "slide_in_live"
},
{
"method": "sleep",
"params": 10
},
{
"method": "screenshot"
}
]
}
}
]
}

View File

@@ -0,0 +1,83 @@
config:
name: 通过 关注天窗 进入指定主播抖音直播间
variables:
app_name: 抖音
ios:
- port: 8100
mjpeg_port: 9100
log_on: true
teststeps:
- name: 启动抖音
ios:
actions:
- method: home
- method: app_terminate
params: com.ss.iphone.ugc.Aweme
- method: swipe_to_tap_app
params: $app_name
identifier: 启动抖音
max_retry_times: 5
- method: sleep
params: 5
validate:
- check: ui_ocr
assert: exists
expect: 推荐
msg: 抖音启动失败,「推荐」不存在
- name: 处理青少年弹窗
ios:
actions:
- method: tap_ocr
params: 我知道了
ignore_NotFoundError: true
- name: 点击首页
ios:
actions:
- method: tap_ocr
params: 首页
index: -1
- method: sleep
params: 10
- name: 点击关注页
ios:
actions:
- method: tap_ocr
params: 关注
index: 1
- method: sleep
params: 10
- name: 向上滑动 2 次
ios:
actions:
- method: swipe_to_tap_text
params:
- 理肤泉
- 婉宝
identifier: click_live
direction:
- 0.6
- 0.2
- 0.2
- 0.2
- method: sleep
params: 10
- method: swipe
params:
- 0.9
- 0.7
- 0.9
- 0.3
identifier: slide_in_live
- method: sleep
params: 10
- method: screenshot
- method: swipe
params:
- 0.9
- 0.7
- 0.9
- 0.3
identifier: slide_in_live
- method: sleep
params: 10
- method: screenshot

View File

@@ -0,0 +1,58 @@
//go:build localtest
package uitest
import (
"testing"
"github.com/httprunner/httprunner/v4/hrp"
)
func TestIOSDouyinFollowLive(t *testing.T) {
testCase := &hrp.TestCase{
Config: hrp.NewConfig("通过 关注天窗 进入指定主播抖音直播间").
WithVariables(map[string]interface{}{
"app_name": "抖音",
}).
SetIOS(
hrp.WithLogOn(true),
hrp.WithWDAPort(8100),
hrp.WithWDAMjpegPort(9100),
),
TestSteps: []hrp.IStep{
hrp.NewStep("启动抖音").
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5).
Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
hrp.NewStep("处理青少年弹窗").
IOS().
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
hrp.NewStep("点击首页").
IOS().
TapByOCR("首页", hrp.WithIndex(-1)).Sleep(10),
hrp.NewStep("点击关注页").
IOS().
TapByOCR("关注", hrp.WithIndex(1)).Sleep(10),
hrp.NewStep("向上滑动 2 次").
IOS().SwipeToTapFromTexts([]string{"理肤泉", "婉宝"}, hrp.WithDirection([]float64{0.6, 0.2, 0.2, 0.2}), hrp.WithIdentifier("click_live")).Sleep(10).
Swipe(0.9, 0.7, 0.9, 0.3, hrp.WithIdentifier("slide_in_live")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s截图保存
Swipe(0.9, 0.7, 0.9, 0.3, hrp.WithIdentifier("slide_in_live")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s截图保存
},
}
if err := testCase.Dump2JSON("demo_douyin_follow_live.json"); err != nil {
t.Fatal(err)
}
if err := testCase.Dump2YAML("demo_douyin_follow_live.yaml"); err != nil {
t.Fatal(err)
}
runner := hrp.NewRunner(t).SetSaveTests(true)
err := runner.Run(testCase)
if err != nil {
t.Fatal(err)
}
}