refactor: move uixt API

This commit is contained in:
debugtalk
2022-12-13 23:31:02 +08:00
parent 11abdf07af
commit 5786ff59a2
17 changed files with 189 additions and 424 deletions

View File

@@ -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截图保存
},
}

View File

@@ -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

View File

@@ -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截图保存
},
}

View File

@@ -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

View File

@@ -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("进入直播间")),
},
}

View File

@@ -0,0 +1,69 @@
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)
}
if err := testCase.Dump2YAML("android_feed_card_live_test.yaml"); err != nil {
t.Fatal(err)
}
runner := hrp.NewRunner(t).SetSaveTests(true)
err := runner.Run(testCase)
if err != nil {
t.Fatal(err)
}
}

View File

@@ -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

View File

@@ -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截图保存
},
}

View File

@@ -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),
},
}

View File

@@ -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

View File

@@ -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("输入搜索关键词")),
},
}

View File

@@ -15,8 +15,6 @@ import (
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp"
"github.com/httprunner/httprunner/v4/hrp/pkg/gidevice"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
@@ -39,32 +37,32 @@ func convertTimeToSeconds(timeStr string) (int, error) {
}
func initIOSDevice(uuid string) uixt.Device {
perfOptions := []gidevice.PerfOption{}
perfOptions := []uixt.IOSPerfOption{}
for _, p := range perf {
switch p {
case "sys_cpu":
perfOptions = append(perfOptions, hrp.WithPerfSystemCPU(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemCPU(true))
case "sys_mem":
perfOptions = append(perfOptions, hrp.WithPerfSystemMem(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemMem(true))
case "sys_net":
perfOptions = append(perfOptions, hrp.WithPerfSystemNetwork(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemNetwork(true))
case "sys_disk":
perfOptions = append(perfOptions, hrp.WithPerfSystemDisk(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfSystemDisk(true))
case "network":
perfOptions = append(perfOptions, hrp.WithPerfNetwork(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfNetwork(true))
case "fps":
perfOptions = append(perfOptions, hrp.WithPerfFPS(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfFPS(true))
case "gpu":
perfOptions = append(perfOptions, hrp.WithPerfGPU(true))
perfOptions = append(perfOptions, uixt.WithIOSPerfGPU(true))
}
}
perfOptions = append(perfOptions, hrp.WithPerfOutputInterval(interval*1000))
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.WithPerfOptions(perfOptions...),
uixt.WithIOSPerfOptions(perfOptions...),
uixt.WithXCTest("com.gtf.wda.runner.xctrunner"),
)
if err != nil {

View File

@@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/httprunner/httprunner/v4/hrp"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
func TestConvertTimeToSeconds(t *testing.T) {
@@ -54,11 +55,11 @@ func TestIOSDouyinWorldCupLive(t *testing.T) {
"appBundleID": "com.ss.iphone.ugc.Aweme",
}).
SetIOS(
hrp.WithUDID(uuid),
hrp.WithLogOn(true),
hrp.WithWDAPort(8700),
hrp.WithWDAMjpegPort(8800),
hrp.WithXCTest("com.gtf.wda.runner.xctrunner"),
uixt.WithUDID(uuid),
uixt.WithWDALogOn(true),
uixt.WithWDAPort(8700),
uixt.WithWDAMjpegPort(8800),
uixt.WithXCTest("com.gtf.wda.runner.xctrunner"),
),
TestSteps: []hrp.IStep{
hrp.NewStep("启动抖音").
@@ -70,22 +71,22 @@ func TestIOSDouyinWorldCupLive(t *testing.T) {
AssertOCRExists("首页", "抖音启动失败,「首页」不存在"),
hrp.NewStep("处理青少年弹窗").
IOS().
TapByOCR("我知道了", hrp.WithIgnoreNotFoundError(true)),
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
hrp.NewStep("点击首页").
IOS().
TapByOCR("首页", hrp.WithIndex(-1)).Sleep(5),
TapByOCR("首页", uixt.WithIndex(-1)).Sleep(5),
hrp.NewStep("点击世界杯页").
IOS().
SwipeToTapText("世界杯",
hrp.WithMaxRetryTimes(5),
hrp.WithCustomDirection(0.4, 0.07, 0.6, 0.07), // 滑动 tab从左到右解决「世界杯」被遮挡的问题
hrp.WithScope(0, 0, 1, 0.15), // 限定 tab 区域
hrp.WithWaitTime(1),
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("点击进入直播间").
IOS().
Loop(5). // 重复执行 5 次
TapByOCR("直播中", hrp.WithIdentifier("click_live"), hrp.WithIndex(-1)).
TapByOCR("直播中", uixt.WithIdentifier("click_live"), uixt.WithIndex(-1)).
Sleep(3).Back().Sleep(3),
hrp.NewStep("关闭抖音").
IOS().

View File

@@ -48,6 +48,23 @@ const (
dismissAlertButtonSelector = "**/XCUIElementTypeButton[`label IN {'不允许','暂不'}`]"
)
type IOSPerfOption = gidevice.PerfOption
var (
WithIOSPerfSystemCPU = gidevice.WithPerfSystemCPU
WithIOSPerfSystemMem = gidevice.WithPerfSystemMem
WithIOSPerfSystemDisk = gidevice.WithPerfSystemDisk
WithIOSPerfSystemNetwork = gidevice.WithPerfSystemNetwork
WithIOSPerfGPU = gidevice.WithPerfGPU
WithIOSPerfFPS = gidevice.WithPerfFPS
WithIOSPerfNetwork = gidevice.WithPerfNetwork
WithIOSPerfBundleID = gidevice.WithPerfBundleID
WithIOSPerfPID = gidevice.WithPerfPID
WithIOSPerfOutputInterval = gidevice.WithPerfOutputInterval
WithIOSPerfProcessAttributes = gidevice.WithPerfProcessAttributes
WithIOSPerfSystemAttributes = gidevice.WithPerfSystemAttributes
)
type IOSDeviceOption func(*IOSDevice)
func WithUDID(udid string) IOSDeviceOption {
@@ -68,7 +85,7 @@ func WithWDAMjpegPort(port int) IOSDeviceOption {
}
}
func WithLogOn(logOn bool) IOSDeviceOption {
func WithWDALogOn(logOn bool) IOSDeviceOption {
return func(device *IOSDevice) {
device.LogOn = logOn
}
@@ -104,7 +121,7 @@ func WithXCTest(bundleID string) IOSDeviceOption {
}
}
func WithPerfOptions(options ...gidevice.PerfOption) IOSDeviceOption {
func WithIOSPerfOptions(options ...gidevice.PerfOption) IOSDeviceOption {
return func(device *IOSDevice) {
device.PerfOptions = &gidevice.PerfOptions{}
for _, option := range options {
@@ -154,10 +171,10 @@ func GetIOSDeviceOptions(dev *IOSDevice) (deviceOptions []IOSDeviceOption) {
deviceOptions = append(deviceOptions, WithWDAMjpegPort(dev.MjpegPort))
}
if dev.LogOn {
deviceOptions = append(deviceOptions, WithLogOn(true))
deviceOptions = append(deviceOptions, WithWDALogOn(true))
}
if dev.PerfOptions != nil {
deviceOptions = append(deviceOptions, WithPerfOptions(dev.perfOpitons()...))
deviceOptions = append(deviceOptions, WithIOSPerfOptions(dev.perfOpitons()...))
}
if dev.XCTestBundleID != "" {
deviceOptions = append(deviceOptions, WithXCTest(dev.XCTestBundleID))

View File

@@ -1,10 +1,5 @@
package hrp
import (
"github.com/httprunner/httprunner/v4/hrp/pkg/gidevice"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
type StepType string
const (
@@ -19,39 +14,6 @@ const (
stepTypeIOS StepType = "ios"
)
var (
WithIdentifier = uixt.WithIdentifier
WithMaxRetryTimes = uixt.WithMaxRetryTimes
WithWaitTime = uixt.WithWaitTime // only applicable to SwipeToTap* action
WithIndex = uixt.WithIndex // index of the target element, should start from 1, only applicable to ocr actions
WithTimeout = uixt.WithTimeout
WithIgnoreNotFoundError = uixt.WithIgnoreNotFoundError
WithText = uixt.WithText
WithID = uixt.WithID
WithDescription = uixt.WithDescription
WithDuration = uixt.WithDuration // only applicable to ios swipe action
WithSteps = uixt.WithSteps // only applicable to android swipe action
WithDirection = uixt.WithDirection
WithCustomDirection = uixt.WithCustomDirection
WithScope = uixt.WithScope // only applicable to ocr actions
WithOffset = uixt.WithOffset
)
var (
WithPerfSystemCPU = gidevice.WithPerfSystemCPU
WithPerfSystemMem = gidevice.WithPerfSystemMem
WithPerfSystemDisk = gidevice.WithPerfSystemDisk
WithPerfSystemNetwork = gidevice.WithPerfSystemNetwork
WithPerfGPU = gidevice.WithPerfGPU
WithPerfFPS = gidevice.WithPerfFPS
WithPerfNetwork = gidevice.WithPerfNetwork
WithPerfBundleID = gidevice.WithPerfBundleID
WithPerfPID = gidevice.WithPerfPID
WithPerfOutputInterval = gidevice.WithPerfOutputInterval
WithPerfProcessAttributes = gidevice.WithPerfProcessAttributes
WithPerfSystemAttributes = gidevice.WithPerfSystemAttributes
)
type StepResult struct {
Name string `json:"name" yaml:"name"` // step name
StepType StepType `json:"step_type" yaml:"step_type"` // step type, testcase/request/transaction/rendezvous

View File

@@ -11,28 +11,6 @@ import (
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
// ios setting options
var (
WithUDID = uixt.WithUDID
WithWDAPort = uixt.WithWDAPort
WithWDAMjpegPort = uixt.WithWDAMjpegPort
WithLogOn = uixt.WithLogOn
WithResetHomeOnStartup = uixt.WithResetHomeOnStartup
WithSnapshotMaxDepth = uixt.WithSnapshotMaxDepth
WithAcceptAlertButtonSelector = uixt.WithAcceptAlertButtonSelector
WithDismissAlertButtonSelector = uixt.WithDismissAlertButtonSelector
WithPerfOptions = uixt.WithPerfOptions
WithXCTest = uixt.WithXCTest
)
// android setting options
var (
WithSerialNumber = uixt.WithSerialNumber
WithAdbIP = uixt.WithAdbIP
WithAdbPort = uixt.WithAdbPort
WithAdbLogOn = uixt.WithAdbLogOn
)
type MobileStep struct {
Serial string `json:"serial,omitempty" yaml:"serial,omitempty"`
Loops int `json:"loops,omitempty" yaml:"loops,omitempty"`

View File

@@ -4,12 +4,14 @@ package hrp
import (
"testing"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
func TestIOSSettingsAction(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("ios ui action on Settings").
SetIOS(WithWDAPort(8700), WithWDAMjpegPort(8800)),
SetIOS(uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800)),
TestSteps: []IStep{
NewStep("launch Settings").
IOS().Home().Tap("设置").
@@ -48,7 +50,7 @@ func TestIOSSearchApp(t *testing.T) {
func TestIOSAppLaunch(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("启动 & 关闭 App").
SetIOS(WithWDAPort(8700), WithWDAMjpegPort(8800)),
SetIOS(uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800)),
TestSteps: []IStep{
NewStep("终止今日头条").
IOS().AppTerminate("com.ss.iphone.article.News"),
@@ -69,7 +71,7 @@ func TestIOSAppLaunch(t *testing.T) {
func TestIOSWeixinLive(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("ios ui action on 微信直播").
SetIOS(WithLogOn(true), WithWDAPort(8100), WithWDAMjpegPort(9100)),
SetIOS(uixt.WithWDALogOn(true), uixt.WithWDAPort(8100), uixt.WithWDAMjpegPort(9100)),
TestSteps: []IStep{
NewStep("启动微信").
IOS().