mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 11:19:43 +08:00
Merge pull request #1531 from httprunner/wcl
release v4.3.1 - feat: add option WithScreenShot - feat: run xctest before start ios automation - feat: run step with specified loop times - feat: add options for FindTexts - refactor: move all UI APIs to uixt pkg - docs: add examples for UI APIs
This commit is contained in:
@@ -6,32 +6,33 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestAndroidDouYinLive(t *testing.T) {
|
||||
testCase := &hrp.TestCase{
|
||||
Config: hrp.NewConfig("通过 feed 头像进入抖音直播间").
|
||||
SetAndroid(hrp.WithAdbLogOn(true), hrp.WithSerialNumber("2d06bf70")),
|
||||
SetAndroid(uixt.WithAdbLogOn(true), uixt.WithSerialNumber("2d06bf70")),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动抖音").
|
||||
Android().
|
||||
Home().
|
||||
AppTerminate("com.ss.android.ugc.aweme"). // 关闭已运行的抖音,确保启动抖音后在「抖音」首页
|
||||
SwipeToTapApp("抖音", hrp.WithMaxRetryTimes(5)).
|
||||
SwipeToTapApp("抖音", uixt.WithMaxRetryTimes(5)).
|
||||
Sleep(10),
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
Android().
|
||||
Tap("推荐").
|
||||
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)).
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)).
|
||||
Validate().
|
||||
AssertOCRExists("首页", "抖音启动失败,「首页」不存在"),
|
||||
hrp.NewStep("在推荐页上划,直到出现 feed 头像「直播」").
|
||||
Android().
|
||||
SwipeToTapText("直播", hrp.WithMaxRetryTimes(10), hrp.WithIdentifier("进入直播间")),
|
||||
SwipeToTapText("直播", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
|
||||
hrp.NewStep("向上滑动,等待 10s").
|
||||
Android().
|
||||
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||
SwipeUp(hrp.WithIdentifier("第二次上划")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
config:
|
||||
name: 通过 关注天窗 进入指定主播抖音直播间
|
||||
variables:
|
||||
app_name: 抖音
|
||||
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: $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_texts
|
||||
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
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestIOSDouyinFollowLive(t *testing.T) {
|
||||
@@ -15,31 +16,31 @@ func TestIOSDouyinFollowLive(t *testing.T) {
|
||||
"app_name": "抖音",
|
||||
}).
|
||||
SetIOS(
|
||||
hrp.WithLogOn(true),
|
||||
hrp.WithWDAPort(8700),
|
||||
hrp.WithWDAMjpegPort(8800),
|
||||
uixt.WithWDALogOn(true),
|
||||
uixt.WithWDAPort(8700),
|
||||
uixt.WithWDAMjpegPort(8800),
|
||||
),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动抖音").
|
||||
IOS().
|
||||
Home().
|
||||
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
|
||||
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5).
|
||||
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithIdentifier("启动抖音")).Sleep(5).
|
||||
Validate().
|
||||
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
IOS().
|
||||
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
|
||||
hrp.NewStep("点击首页").
|
||||
IOS().
|
||||
TapByOCR("首页", hrp.WithIndex(-1)).Sleep(10),
|
||||
TapByOCR("首页", uixt.WithIndex(-1)).Sleep(10),
|
||||
hrp.NewStep("点击关注页").
|
||||
IOS().
|
||||
TapByOCR("关注", hrp.WithIndex(1)).Sleep(10),
|
||||
TapByOCR("关注", uixt.WithIndex(1)).Sleep(10),
|
||||
hrp.NewStep("向上滑动 2 次").
|
||||
IOS().SwipeToTapTexts([]string{"理肤泉", "婉宝"}, hrp.WithCustomDirection(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,截图保存
|
||||
IOS().SwipeToTapTexts([]string{"理肤泉", "婉宝"}, uixt.WithCustomDirection(0.6, 0.2, 0.2, 0.2), uixt.WithIdentifier("click_live")).Sleep(10).
|
||||
Swipe(0.9, 0.7, 0.9, 0.3, uixt.WithIdentifier("slide_in_live")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||
Swipe(0.9, 0.7, 0.9, 0.3, uixt.WithIdentifier("slide_in_live")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
config:
|
||||
name: 通过 feed 卡片进入抖音直播间
|
||||
variables:
|
||||
app_name: 抖音
|
||||
ios:
|
||||
- perf_options:
|
||||
sys_cpu: true
|
||||
sys_mem: true
|
||||
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: $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: 向上滑动 2 次
|
||||
ios:
|
||||
actions:
|
||||
- method: swipe
|
||||
params: up
|
||||
identifier: 第一次上划
|
||||
- method: sleep
|
||||
params: 2
|
||||
- method: screenshot
|
||||
- method: swipe
|
||||
params: up
|
||||
identifier: 第二次上划
|
||||
- method: sleep
|
||||
params: 2
|
||||
- method: screenshot
|
||||
- name: 在推荐页上划,直到出现「点击进入直播间」
|
||||
ios:
|
||||
actions:
|
||||
- method: swipe_to_tap_text
|
||||
params: 点击进入直播间
|
||||
identifier: 进入直播间
|
||||
max_retry_times: 10
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestIOSDouyinLive(t *testing.T) {
|
||||
@@ -15,12 +16,12 @@ func TestIOSDouyinLive(t *testing.T) {
|
||||
"app_name": "抖音",
|
||||
}).
|
||||
SetIOS(
|
||||
hrp.WithLogOn(true),
|
||||
hrp.WithWDAPort(8700),
|
||||
hrp.WithWDAMjpegPort(8800),
|
||||
hrp.WithPerfOptions(
|
||||
hrp.WithPerfSystemCPU(true),
|
||||
hrp.WithPerfSystemMem(true),
|
||||
uixt.WithWDALogOn(true),
|
||||
uixt.WithWDAPort(8700),
|
||||
uixt.WithWDAMjpegPort(8800),
|
||||
uixt.WithIOSPerfOptions(
|
||||
uixt.WithIOSPerfSystemCPU(true),
|
||||
uixt.WithIOSPerfSystemMem(true),
|
||||
),
|
||||
),
|
||||
TestSteps: []hrp.IStep{
|
||||
@@ -28,19 +29,19 @@ func TestIOSDouyinLive(t *testing.T) {
|
||||
IOS().
|
||||
Home().
|
||||
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
|
||||
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5).
|
||||
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithIdentifier("启动抖音")).Sleep(5).
|
||||
Validate().
|
||||
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
IOS().
|
||||
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
|
||||
hrp.NewStep("向上滑动 2 次").
|
||||
IOS().
|
||||
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存
|
||||
SwipeUp(hrp.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s,截图保存
|
||||
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s,截图保存
|
||||
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s,截图保存
|
||||
hrp.NewStep("在推荐页上划,直到出现「点击进入直播间」").
|
||||
IOS().
|
||||
SwipeToTapText("点击进入直播间", hrp.WithMaxRetryTimes(10), hrp.WithIdentifier("进入直播间")),
|
||||
SwipeToTapText("点击进入直播间", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
68
examples/uitest/demo_kuaishou_test.go
Normal file
68
examples/uitest/demo_kuaishou_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
//go:build localtest
|
||||
|
||||
package uitest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestAndroidKuaiShouFeedCardLive(t *testing.T) {
|
||||
testCase := &hrp.TestCase{
|
||||
Config: hrp.NewConfig("直播_快手_Feed卡片_android").
|
||||
WithVariables(map[string]interface{}{
|
||||
"device": "${ENV(SerialNumber)}",
|
||||
}).
|
||||
SetAndroid(
|
||||
uixt.WithSerialNumber("$device"),
|
||||
uixt.WithAdbLogOn(true)),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动快手").
|
||||
Android().
|
||||
AppTerminate("com.smile.gifmaker").
|
||||
AppLaunch("com.smile.gifmaker").
|
||||
Home().
|
||||
SwipeToTapApp("快手", uixt.WithMaxRetryTimes(5)).Sleep(10),
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
Android().
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)).
|
||||
Validate().
|
||||
AssertOCRExists("精选", "进入快手失败"),
|
||||
hrp.NewStep("点击精选").
|
||||
Android().
|
||||
TapByOCR("精选", uixt.WithIndex(-1), uixt.WithOffset(0, -50)).Sleep(10),
|
||||
hrp.NewStep("点击直播标签,进入直播间").
|
||||
Android().
|
||||
SwipeToTapText("点击进入直播间",
|
||||
uixt.WithCustomDirection(0.9, 0.7, 0.9, 0.3),
|
||||
uixt.WithScope(0.2, 0.5, 0.8, 0.8),
|
||||
uixt.WithMaxRetryTimes(20),
|
||||
uixt.WithWaitTime(60),
|
||||
uixt.WithIdentifier("click_live"),
|
||||
),
|
||||
hrp.NewStep("等待1分钟").
|
||||
Android().
|
||||
Sleep(60),
|
||||
hrp.NewStep("上滑进入下一个直播间").
|
||||
Android().
|
||||
Swipe(0.9, 0.7, 0.9, 0.3, uixt.WithIdentifier("slide_in_live")).Sleep(60),
|
||||
hrp.NewStep("返回主界面,并打开本地时间戳").
|
||||
Android().
|
||||
Home().SwipeToTapApp("local", uixt.WithMaxRetryTimes(5)).Sleep(10).
|
||||
Validate().
|
||||
AssertOCRExists("16", "打开本地时间戳失败"),
|
||||
},
|
||||
}
|
||||
|
||||
if err := testCase.Dump2JSON("android_feed_card_live_test.json"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
runner := hrp.NewRunner(t).SetSaveTests(true)
|
||||
err := runner.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
config:
|
||||
name: 通过 feed 卡片进入微信直播间
|
||||
ios:
|
||||
- port: 8700
|
||||
mjpeg_port: 8800
|
||||
log_on: true
|
||||
teststeps:
|
||||
- name: 启动微信
|
||||
ios:
|
||||
actions:
|
||||
- method: home
|
||||
- method: app_terminate
|
||||
params: com.tencent.xin
|
||||
- method: swipe_to_tap_app
|
||||
params: 微信
|
||||
max_retry_times: 5
|
||||
validate:
|
||||
- check: ui_label
|
||||
assert: exists
|
||||
expect: 通讯录
|
||||
msg: 微信启动失败,「通讯录」不存在
|
||||
- name: 进入直播页
|
||||
ios:
|
||||
actions:
|
||||
- method: tap
|
||||
params: 发现
|
||||
- method: tap_ocr
|
||||
params: 视频号
|
||||
identifier: 进入视频号
|
||||
index: -1
|
||||
- name: 处理青少年弹窗
|
||||
ios:
|
||||
actions:
|
||||
- method: tap_ocr
|
||||
params: 我知道了
|
||||
ignore_NotFoundError: true
|
||||
- name: 在推荐页上划,直到出现「轻触进入直播间」
|
||||
ios:
|
||||
actions:
|
||||
- method: swipe_to_tap_text
|
||||
params: 轻触进入直播间
|
||||
identifier: 进入直播间
|
||||
max_retry_times: 10
|
||||
- name: 向上滑动,等待 10s
|
||||
ios:
|
||||
actions:
|
||||
- method: swipe
|
||||
params: up
|
||||
identifier: 第一次上划
|
||||
- method: sleep
|
||||
params: 10
|
||||
- method: screenshot
|
||||
- method: swipe
|
||||
params: up
|
||||
identifier: 第二次上划
|
||||
- method: sleep
|
||||
params: 10
|
||||
- method: screenshot
|
||||
@@ -6,34 +6,35 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestIOSWeixinLive(t *testing.T) {
|
||||
testCase := &hrp.TestCase{
|
||||
Config: hrp.NewConfig("通过 feed 卡片进入微信直播间").
|
||||
SetIOS(hrp.WithLogOn(true), hrp.WithWDAPort(8700), hrp.WithWDAMjpegPort(8800)),
|
||||
SetIOS(uixt.WithWDALogOn(true), uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800)),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动微信").
|
||||
IOS().
|
||||
Home().
|
||||
AppTerminate("com.tencent.xin"). // 关闭已运行的微信,确保启动微信后在「微信」首页
|
||||
SwipeToTapApp("微信", hrp.WithMaxRetryTimes(5)).
|
||||
SwipeToTapApp("微信", uixt.WithMaxRetryTimes(5)).
|
||||
Validate().
|
||||
AssertLabelExists("通讯录", "微信启动失败,「通讯录」不存在"),
|
||||
hrp.NewStep("进入直播页").
|
||||
IOS().
|
||||
Tap("发现"). // 进入「发现页」
|
||||
TapByOCR("视频号", hrp.WithIdentifier("进入视频号"), hrp.WithIndex(-1)), // 通过 OCR 识别「视频号」
|
||||
Tap("发现"). // 进入「发现页」
|
||||
TapByOCR("视频号", uixt.WithIdentifier("进入视频号"), uixt.WithIndex(-1)), // 通过 OCR 识别「视频号」
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
IOS().
|
||||
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
|
||||
hrp.NewStep("在推荐页上划,直到出现「轻触进入直播间」").
|
||||
IOS().
|
||||
SwipeToTapText("轻触进入直播间", hrp.WithMaxRetryTimes(10), hrp.WithIdentifier("进入直播间")),
|
||||
SwipeToTapText("轻触进入直播间", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
|
||||
hrp.NewStep("向上滑动,等待 10s").
|
||||
IOS().
|
||||
SwipeUp(hrp.WithIdentifier("第一次上划")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||
SwipeUp(hrp.WithIdentifier("第二次上划")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestIOSKuaiShouLive(t *testing.T) {
|
||||
@@ -15,33 +16,37 @@ func TestIOSKuaiShouLive(t *testing.T) {
|
||||
"device": "${ENV(UDID)}",
|
||||
"ups": "${ENV(LIVEUPLIST)}",
|
||||
}).
|
||||
SetIOS(hrp.WithUDID("$device"), hrp.WithLogOn(true), hrp.WithWDAPort(8100), hrp.WithWDAMjpegPort(9100)),
|
||||
SetIOS(
|
||||
uixt.WithUDID("$device"),
|
||||
uixt.WithWDALogOn(true),
|
||||
uixt.WithWDAPort(8100),
|
||||
uixt.WithWDAMjpegPort(9100)),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动快手").
|
||||
IOS().
|
||||
AppTerminate("com.jiangjia.gif").
|
||||
AppLaunch("com.jiangjia.gif").
|
||||
Home().
|
||||
SwipeToTapApp("快手", hrp.WithMaxRetryTimes(5)).Sleep(10).
|
||||
SwipeToTapApp("快手", uixt.WithMaxRetryTimes(5)).Sleep(10).
|
||||
Validate().
|
||||
AssertOCRExists("精选", "进入快手失败"),
|
||||
hrp.NewStep("点击首页").
|
||||
IOS().
|
||||
TapByOCR("首页", hrp.WithIndex(-1)).Sleep(10),
|
||||
TapByOCR("首页", uixt.WithIndex(-1)).Sleep(10),
|
||||
hrp.NewStep("点击发现页").
|
||||
IOS().
|
||||
TapByOCR("发现", hrp.WithIndex(1)).Sleep(10),
|
||||
TapByOCR("发现", uixt.WithIndex(1)).Sleep(10),
|
||||
hrp.NewStep("点击关注页").
|
||||
IOS().
|
||||
TapByOCR("关注", hrp.WithIndex(1)).Sleep(10),
|
||||
TapByOCR("关注", uixt.WithIndex(1)).Sleep(10),
|
||||
hrp.NewStep("点击直播标签,进入直播间").
|
||||
IOS().
|
||||
SwipeToTapTexts("${split_by_comma($ups)}", hrp.WithCustomDirection(0.6, 0.2, 0.2, 0.2), hrp.WithIdentifier("click_live")).Sleep(60).
|
||||
SwipeToTapTexts("${split_by_comma($ups)}", uixt.WithCustomDirection(0.6, 0.2, 0.2, 0.2), uixt.WithIdentifier("click_live")).Sleep(60).
|
||||
Validate().
|
||||
AssertOCRExists("说点什么", "进入直播间失败"),
|
||||
hrp.NewStep("下滑进入下一个直播间").
|
||||
IOS().
|
||||
Swipe(0.9, 0.7, 0.9, 0.3, hrp.WithIdentifier("slide_in_live")).Sleep(60),
|
||||
Swipe(0.9, 0.7, 0.9, 0.3, uixt.WithIdentifier("slide_in_live")).Sleep(60),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
config:
|
||||
name: 直播_快手_关注天窗_ios
|
||||
variables:
|
||||
device: ${ENV(UDID)}
|
||||
ups: ${ENV(LIVEUPLIST)}
|
||||
ios:
|
||||
- udid: $device
|
||||
port: 8100
|
||||
mjpeg_port: 9100
|
||||
log_on: true
|
||||
teststeps:
|
||||
- name: 启动快手
|
||||
ios:
|
||||
actions:
|
||||
- method: app_terminate
|
||||
params: com.jiangjia.gif
|
||||
- method: app_launch
|
||||
params: com.jiangjia.gif
|
||||
- method: home
|
||||
- method: swipe_to_tap_app
|
||||
params: 快手
|
||||
max_retry_times: 5
|
||||
- method: sleep
|
||||
params: 10
|
||||
validate:
|
||||
- check: ui_ocr
|
||||
assert: exists
|
||||
expect: 精选
|
||||
msg: 进入快手失败
|
||||
- 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: 点击关注页
|
||||
ios:
|
||||
actions:
|
||||
- method: tap_ocr
|
||||
params: 关注
|
||||
index: 1
|
||||
- method: sleep
|
||||
params: 10
|
||||
- name: 点击直播标签,进入直播间
|
||||
ios:
|
||||
actions:
|
||||
- method: swipe_to_tap_texts
|
||||
params: ${split_by_comma($ups)}
|
||||
identifier: click_live
|
||||
direction:
|
||||
- 0.6
|
||||
- 0.2
|
||||
- 0.2
|
||||
- 0.2
|
||||
- method: sleep
|
||||
params: 60
|
||||
validate:
|
||||
- check: ui_ocr
|
||||
assert: exists
|
||||
expect: 说点什么
|
||||
msg: 进入直播间失败
|
||||
- name: 下滑进入下一个直播间
|
||||
ios:
|
||||
actions:
|
||||
- method: swipe
|
||||
params:
|
||||
- 0.9
|
||||
- 0.7
|
||||
- 0.9
|
||||
- 0.3
|
||||
identifier: slide_in_live
|
||||
- method: sleep
|
||||
params: 60
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestWDALog(t *testing.T) {
|
||||
@@ -14,29 +15,38 @@ func TestWDALog(t *testing.T) {
|
||||
WithVariables(map[string]interface{}{
|
||||
"app_name": "抖音",
|
||||
}).
|
||||
SetIOS(hrp.WithLogOn(true), hrp.WithWDAPort(8700), hrp.WithWDAMjpegPort(8800)),
|
||||
SetIOS(
|
||||
uixt.WithWDALogOn(true),
|
||||
uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800),
|
||||
uixt.WithIOSPerfOptions(
|
||||
uixt.WithIOSPerfSystemCPU(true),
|
||||
uixt.WithIOSPerfSystemMem(true),
|
||||
uixt.WithIOSPerfNetwork(true),
|
||||
uixt.WithIOSPerfFPS(true),
|
||||
),
|
||||
),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动抖音").
|
||||
IOS().
|
||||
Home().
|
||||
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
|
||||
SwipeToTapApp("$app_name", hrp.WithMaxRetryTimes(5), hrp.WithIdentifier("启动抖音")).Sleep(5).
|
||||
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithIdentifier("启动抖音")).Sleep(5).
|
||||
Validate().
|
||||
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
|
||||
hrp.NewStep("处理青少年弹窗").
|
||||
IOS().
|
||||
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
|
||||
hrp.NewStep("进入购物页").
|
||||
IOS().TapByOCR("购物", hrp.WithIdentifier("点击购物")).Sleep(5),
|
||||
IOS().TapByOCR("商城", uixt.WithIdentifier("点击商城")).Sleep(5),
|
||||
hrp.NewStep("进入推荐页").
|
||||
IOS().TapByOCR("推荐", hrp.WithIdentifier("点击推荐")).Sleep(5),
|
||||
IOS().TapByOCR("推荐", uixt.WithIdentifier("点击推荐")).Sleep(5),
|
||||
hrp.NewStep("向上滑动 2 次").
|
||||
IOS().
|
||||
SwipeUp(hrp.WithIdentifier("第 1 次上划")).Sleep(2).
|
||||
SwipeUp(hrp.WithIdentifier("第 2 次上划")).Sleep(2).
|
||||
SwipeUp(hrp.WithIdentifier("第 3 次上划")).Sleep(2).
|
||||
TapXY(0.9, 0.1, hrp.WithIdentifier("点击进入搜索框")).Sleep(2).
|
||||
Input("httprunner", hrp.WithIdentifier("输入搜索关键词")),
|
||||
SwipeUp(uixt.WithIdentifier("第 1 次上划")).Sleep(2).
|
||||
SwipeUp(uixt.WithIdentifier("第 2 次上划")).Sleep(2).
|
||||
SwipeUp(uixt.WithIdentifier("第 3 次上划")).Sleep(2).
|
||||
TapXY(0.9, 0.1, uixt.WithIdentifier("点击进入搜索框")).Sleep(2).
|
||||
Input("httprunner", uixt.WithIdentifier("输入搜索关键词")),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
36
examples/worldcup/README.md
Normal file
36
examples/worldcup/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# World Cup Live
|
||||
|
||||
```text
|
||||
$ wcl -h
|
||||
Monitor FIFA World Cup Live
|
||||
|
||||
Usage:
|
||||
wcl [flags]
|
||||
|
||||
Flags:
|
||||
--android string run android app
|
||||
--auto auto enter live
|
||||
-d, --duration int set duration in seconds (default 30)
|
||||
-h, --help help for wcl
|
||||
-i, --interval int set interval in seconds (default 15)
|
||||
--ios string run ios app
|
||||
-l, --log-level string set log level (default "INFO")
|
||||
-n, --match-name string specify match name
|
||||
-p, --perf strings specify performance monitor, e.g. sys_cpu,sys_mem,sys_net,sys_disk,fps,network,gpu
|
||||
-u, --uuid string specify device serial or udid
|
||||
-v, --version version for wcl
|
||||
```
|
||||
|
||||
|
||||
```bash
|
||||
$ wcl -n "比利时vs摩洛哥" --android com.ss.android.ugc.aweme -d 300 -i 15 -u caf0cd51
|
||||
$ wcl -n "比利时vs摩洛哥" --ios com.ss.iphone.ugc.Aweme -d 300 -i 15 -p sys_cpu,sys_mem,sys_disk,sys_net,fps,network,gpu -u 00008030-000438191421802E
|
||||
```
|
||||
|
||||
## bundle id
|
||||
|
||||
| app | iOS | Android |
|
||||
| -- | -- | -- |
|
||||
| 抖音 | com.ss.iphone.ugc.Aweme | com.ss.android.ugc.aweme |
|
||||
| 央视频 | com.cctv.yangshipin.app.iphone | com.cctv.yangshipin.app.androidp |
|
||||
| 咪咕视频 | com.wondertek.hecmccmobile | com.cmcc.cmvideo |
|
||||
99
examples/worldcup/cli.go
Normal file
99
examples/worldcup/cli.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "wcl",
|
||||
Short: "Monitor FIFA World Cup Live",
|
||||
Version: "2022.12.03.0018",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
log.Logger = zerolog.New(
|
||||
zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr},
|
||||
).With().Timestamp().Logger()
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var device uixt.Device
|
||||
var bundleID string
|
||||
if iosApp != "" {
|
||||
log.Info().Str("bundleID", iosApp).Msg("init ios device")
|
||||
device = initIOSDevice(uuid)
|
||||
bundleID = iosApp
|
||||
} else if androidApp != "" {
|
||||
log.Info().Str("bundleID", androidApp).Msg("init android device")
|
||||
device = initAndroidDevice(uuid)
|
||||
bundleID = androidApp
|
||||
} else {
|
||||
return errors.New("android or ios app bundldID is required")
|
||||
}
|
||||
|
||||
wc := NewWorldCupLive(device, matchName, bundleID, duration, interval)
|
||||
|
||||
if auto {
|
||||
wc.EnterLive(bundleID)
|
||||
}
|
||||
|
||||
wc.Start()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
uuid string
|
||||
iosApp string
|
||||
androidApp string
|
||||
auto bool
|
||||
duration int
|
||||
interval int
|
||||
logLevel string
|
||||
matchName string
|
||||
perf []string
|
||||
)
|
||||
|
||||
func main() {
|
||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||
rootCmd.PersistentFlags().StringVarP(&uuid, "uuid", "u", "", "specify device serial or udid")
|
||||
rootCmd.PersistentFlags().StringVar(&iosApp, "ios", "", "run ios app")
|
||||
rootCmd.PersistentFlags().StringVar(&androidApp, "android", "", "run android app")
|
||||
rootCmd.PersistentFlags().BoolVar(&auto, "auto", false, "auto enter live")
|
||||
rootCmd.PersistentFlags().IntVarP(&duration, "duration", "d", 30, "set duration in seconds")
|
||||
rootCmd.PersistentFlags().IntVarP(&interval, "interval", "i", 15, "set interval in seconds")
|
||||
rootCmd.PersistentFlags().StringVarP(&matchName, "match-name", "n", "", "specify match name")
|
||||
rootCmd.PersistentFlags().StringSliceVarP(&perf, "perf", "p", nil,
|
||||
"specify performance monitor, e.g. sys_cpu,sys_mem,sys_net,sys_disk,fps,network,gpu")
|
||||
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func setLogLevel(level string) {
|
||||
level = strings.ToUpper(level)
|
||||
log.Info().Str("level", level).Msg("Set log level")
|
||||
switch level {
|
||||
case "DEBUG":
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
case "INFO":
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
case "WARN":
|
||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
||||
case "ERROR":
|
||||
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
||||
case "FATAL":
|
||||
zerolog.SetGlobalLevel(zerolog.FatalLevel)
|
||||
case "PANIC":
|
||||
zerolog.SetGlobalLevel(zerolog.PanicLevel)
|
||||
}
|
||||
}
|
||||
286
examples/worldcup/main.go
Normal file
286
examples/worldcup/main.go
Normal file
@@ -0,0 +1,286 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func convertTimeToSeconds(timeStr string) (int, error) {
|
||||
if !strings.Contains(timeStr, ":") {
|
||||
return 0, fmt.Errorf("invalid time string: %s", timeStr)
|
||||
}
|
||||
|
||||
ss := strings.Split(timeStr, ":")
|
||||
var seconds int
|
||||
for idx, s := range ss {
|
||||
i, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
seconds += i * int(math.Pow(60, float64(len(ss)-idx-1)))
|
||||
}
|
||||
|
||||
return seconds, nil
|
||||
}
|
||||
|
||||
func initIOSDevice(uuid string) uixt.Device {
|
||||
perfOptions := []uixt.IOSPerfOption{}
|
||||
for _, p := range perf {
|
||||
switch p {
|
||||
case "sys_cpu":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemCPU(true))
|
||||
case "sys_mem":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemMem(true))
|
||||
case "sys_net":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemNetwork(true))
|
||||
case "sys_disk":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemDisk(true))
|
||||
case "network":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfNetwork(true))
|
||||
case "fps":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfFPS(true))
|
||||
case "gpu":
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfGPU(true))
|
||||
}
|
||||
}
|
||||
perfOptions = append(perfOptions, uixt.WithIOSPerfOutputInterval(interval*1000))
|
||||
|
||||
device, err := uixt.NewIOSDevice(
|
||||
uixt.WithUDID(uuid),
|
||||
uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800),
|
||||
uixt.WithResetHomeOnStartup(false), // not reset home on startup
|
||||
uixt.WithIOSPerfOptions(perfOptions...),
|
||||
uixt.WithXCTest("com.gtf.wda.runner.xctrunner"),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to init ios device")
|
||||
}
|
||||
return device
|
||||
}
|
||||
|
||||
func initAndroidDevice(uuid string) uixt.Device {
|
||||
device, err := uixt.NewAndroidDevice(uixt.WithSerialNumber(uuid))
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to init android device")
|
||||
}
|
||||
return device
|
||||
}
|
||||
|
||||
type timeLog struct {
|
||||
UTCTimeStr string `json:"utc_time_str"`
|
||||
UTCTime int64 `json:"utc_time"`
|
||||
LiveTime string `json:"live_time"`
|
||||
LiveTimeSeconds int `json:"live_time_seconds"`
|
||||
}
|
||||
|
||||
type WorldCupLive struct {
|
||||
driver *uixt.DriverExt
|
||||
file *os.File
|
||||
resultDir string
|
||||
UUID string `json:"uuid"`
|
||||
MatchName string `json:"matchName"`
|
||||
BundleID string `json:"bundleID"`
|
||||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
Interval int `json:"interval"` // seconds
|
||||
Duration int `json:"duration"` // seconds
|
||||
Timelines []timeLog `json:"timelines"`
|
||||
PerfData []string `json:"perfData"`
|
||||
}
|
||||
|
||||
func NewWorldCupLive(device uixt.Device, matchName, bundleID string, duration, interval int) *WorldCupLive {
|
||||
driverExt, err := device.NewDriver(nil)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to init driver")
|
||||
}
|
||||
|
||||
if matchName == "" {
|
||||
matchName = "unknown-match"
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
matchName = fmt.Sprintf("%s-%s", startTime.Format("2006-01-02"), matchName)
|
||||
resultDir := filepath.Join("worldcuplive", matchName, startTime.Format("15:04:05"))
|
||||
|
||||
if err = os.MkdirAll(filepath.Join(resultDir, "screenshot"), 0o755); err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to create result dir")
|
||||
}
|
||||
|
||||
filename := filepath.Join(resultDir, "log.txt")
|
||||
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o755)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to open file")
|
||||
}
|
||||
// write title
|
||||
f.WriteString(fmt.Sprintf("%s\t%s\t%s\n", matchName, device.UUID(), bundleID))
|
||||
f.WriteString("utc_time\tutc_timestamp\tlive_time\tlive_seconds\n")
|
||||
|
||||
if interval == 0 {
|
||||
interval = 15
|
||||
}
|
||||
if duration == 0 {
|
||||
duration = 30
|
||||
}
|
||||
|
||||
return &WorldCupLive{
|
||||
driver: driverExt,
|
||||
file: f,
|
||||
resultDir: resultDir,
|
||||
UUID: device.UUID(),
|
||||
BundleID: bundleID,
|
||||
Duration: duration,
|
||||
Interval: interval,
|
||||
StartTime: startTime.Format("2006-01-02 15:04:05"),
|
||||
MatchName: matchName,
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
|
||||
utcTimeStr := utcTime.Format("15:04:05")
|
||||
fileName := filepath.Join(
|
||||
wc.resultDir, "screenshot", utcTimeStr)
|
||||
ocrTexts, err := wc.driver.GetTextsByOCR(
|
||||
uixt.WithScreenShot(fileName),
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("get ocr texts failed")
|
||||
return err
|
||||
}
|
||||
|
||||
// filter ocr texts with time format
|
||||
secondsMap := map[string]int{}
|
||||
var secondsTexts []string
|
||||
for _, ocrText := range ocrTexts {
|
||||
seconds, err := convertTimeToSeconds(ocrText.Text)
|
||||
if err == nil {
|
||||
secondsTexts = append(secondsTexts, ocrText.Text)
|
||||
secondsMap[ocrText.Text] = seconds
|
||||
}
|
||||
}
|
||||
|
||||
var secondsText string
|
||||
if len(secondsTexts) == 1 {
|
||||
secondsText = secondsTexts[0]
|
||||
} else if len(secondsTexts) >= 2 {
|
||||
// select the second, the first maybe mobile system time
|
||||
secondsText = secondsTexts[1]
|
||||
} else {
|
||||
log.Warn().Msg("no time text found")
|
||||
return nil
|
||||
}
|
||||
|
||||
liveTimeSeconds := secondsMap[secondsText]
|
||||
line := fmt.Sprintf("%s\t%d\t%s\t%d\n",
|
||||
utcTimeStr, utcTime.Unix(), secondsText, liveTimeSeconds)
|
||||
log.Info().Str("utcTime", utcTimeStr).Str("liveTime", secondsText).Msg("log live time")
|
||||
if _, err := wc.file.WriteString(line); err != nil {
|
||||
log.Error().Err(err).Str("line", line).Msg("write timeseries failed")
|
||||
}
|
||||
wc.Timelines = append(wc.Timelines, timeLog{
|
||||
UTCTimeStr: utcTimeStr,
|
||||
UTCTime: utcTime.Unix(),
|
||||
LiveTime: secondsText,
|
||||
LiveTimeSeconds: liveTimeSeconds,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wc *WorldCupLive) EnterLive(bundleID string) error {
|
||||
log.Info().Msg("enter world cup live")
|
||||
|
||||
// kill app
|
||||
_, err := wc.driver.Driver.AppTerminate(bundleID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("terminate app failed")
|
||||
}
|
||||
|
||||
// launch app
|
||||
err = wc.driver.Driver.AppLaunch(bundleID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("launch app failed")
|
||||
return err
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// 青少年弹窗处理
|
||||
if points, err := wc.driver.GetTextXYs([]string{"青少年模式", "我知道了"}); err == nil {
|
||||
_ = wc.driver.TapAbsXY(points[1].X, points[1].Y)
|
||||
}
|
||||
|
||||
// 进入世界杯 tab
|
||||
if err = wc.driver.TapByOCR("世界杯"); err != nil {
|
||||
log.Error().Err(err).Msg("enter 直播中 failed")
|
||||
return err
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
// 进入世界杯直播
|
||||
if err = wc.driver.TapByOCR("直播中"); err != nil {
|
||||
log.Error().Err(err).Msg("enter 直播中 failed")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wc *WorldCupLive) Start() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
|
||||
timer := time.NewTimer(time.Duration(wc.Duration) * time.Second)
|
||||
for {
|
||||
select {
|
||||
case <-timer.C:
|
||||
wc.dumpResult()
|
||||
return
|
||||
case <-c:
|
||||
wc.dumpResult()
|
||||
return
|
||||
default:
|
||||
utcTime := time.Now()
|
||||
if utcTime.Unix()%int64(wc.Interval) == 0 {
|
||||
wc.getCurrentLiveTime(utcTime)
|
||||
} else {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *WorldCupLive) dumpResult() error {
|
||||
wc.EndTime = time.Now().Format("2006-01-02 15:04:05")
|
||||
|
||||
// init json encoder
|
||||
buffer := new(bytes.Buffer)
|
||||
encoder := json.NewEncoder(buffer)
|
||||
encoder.SetEscapeHTML(false)
|
||||
encoder.SetIndent("", " ")
|
||||
|
||||
wc.PerfData = wc.driver.GetPerfData()
|
||||
err := encoder.Encode(wc)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("encode json failed")
|
||||
return err
|
||||
}
|
||||
|
||||
path := filepath.Join(wc.resultDir, "summary.json")
|
||||
err = os.WriteFile(path, buffer.Bytes(), 0o755)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("dump json path failed")
|
||||
return err
|
||||
}
|
||||
log.Info().Str("path", path).Msg("dump summary success")
|
||||
return nil
|
||||
}
|
||||
100
examples/worldcup/main_test.go
Normal file
100
examples/worldcup/main_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
//go:build localtest
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
func TestConvertTimeToSeconds(t *testing.T) {
|
||||
testData := []struct {
|
||||
timeStr string
|
||||
seconds int
|
||||
}{
|
||||
{"00:00", 0},
|
||||
{"00:01", 1},
|
||||
{"01:00", 60},
|
||||
{"01:01", 61},
|
||||
{"00:01:02", 62},
|
||||
{"01:02:03", 3723},
|
||||
}
|
||||
|
||||
for _, td := range testData {
|
||||
seconds, err := convertTimeToSeconds(td.timeStr)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, td.seconds, seconds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainIOS(t *testing.T) {
|
||||
uuid := "00008030-00194DA421C1802E"
|
||||
device := initIOSDevice(uuid)
|
||||
bundleID := "com.ss.iphone.ugc.Aweme"
|
||||
wc := NewWorldCupLive(device, "", bundleID, 30, 10)
|
||||
wc.EnterLive(bundleID)
|
||||
wc.Start()
|
||||
}
|
||||
|
||||
func TestMainAndroid(t *testing.T) {
|
||||
device := initAndroidDevice(uuid)
|
||||
bundleID := "com.ss.android.ugc.aweme"
|
||||
wc := NewWorldCupLive(device, "", bundleID, 30, 10)
|
||||
wc.EnterLive(bundleID)
|
||||
wc.Start()
|
||||
}
|
||||
|
||||
func TestIOSDouyinWorldCupLive(t *testing.T) {
|
||||
testCase := &hrp.TestCase{
|
||||
Config: hrp.NewConfig("直播_抖音_世界杯_ios").
|
||||
WithVariables(map[string]interface{}{
|
||||
"appBundleID": "com.ss.iphone.ugc.Aweme",
|
||||
}).
|
||||
SetIOS(
|
||||
uixt.WithUDID(uuid),
|
||||
uixt.WithWDALogOn(true),
|
||||
uixt.WithWDAPort(8700),
|
||||
uixt.WithWDAMjpegPort(8800),
|
||||
uixt.WithXCTest("com.gtf.wda.runner.xctrunner"),
|
||||
),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("启动抖音").
|
||||
IOS().
|
||||
Home().
|
||||
AppTerminate("$appBundleID"). // 关闭已运行的抖音
|
||||
AppLaunch("$appBundleID").
|
||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)). // 处理青少年弹窗
|
||||
Validate().
|
||||
AssertOCRExists("首页", "抖音启动失败,「首页」不存在"),
|
||||
hrp.NewStep("点击首页").
|
||||
IOS().
|
||||
TapByOCR("首页", uixt.WithIndex(-1)).Sleep(2),
|
||||
hrp.NewStep("点击世界杯页").
|
||||
IOS().
|
||||
SwipeToTapText("世界杯",
|
||||
uixt.WithMaxRetryTimes(5),
|
||||
uixt.WithCustomDirection(0.4, 0.07, 0.6, 0.07), // 滑动 tab,从左到右,解决「世界杯」被遮挡的问题
|
||||
uixt.WithScope(0, 0, 1, 0.15), // 限定 tab 区域
|
||||
uixt.WithWaitTime(1),
|
||||
),
|
||||
hrp.NewStep("点击进入赛程晋级").
|
||||
Loop(5). // 重复执行 5 次
|
||||
IOS().
|
||||
TapByOCR("赛程晋级", uixt.WithIdentifier("click_live"), uixt.WithIndex(-1)).
|
||||
Sleep(3).Back().Sleep(3),
|
||||
hrp.NewStep("关闭抖音").
|
||||
IOS().
|
||||
AppTerminate("$appBundleID"),
|
||||
},
|
||||
}
|
||||
|
||||
runner := hrp.NewRunner(t).SetSaveTests(true)
|
||||
err := runner.Run(testCase)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user