refactor: move action options to pkg/uixt/options/action

This commit is contained in:
lilong.129
2025-02-06 16:42:16 +08:00
parent f1ef161377
commit 0accec04a9
43 changed files with 982 additions and 911 deletions

View File

@@ -4,7 +4,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -26,8 +25,8 @@ func TestAndroidDouyinE2E(t *testing.T) {
Home().
SwipeToTapApp(
"抖音",
uixt.WithMaxRetryTimes(5),
uixt.WithTapOffset(0, -50),
options.WithMaxRetryTimes(5),
options.WithTapOffset(0, -50),
).
Sleep(20).
Validate().
@@ -48,11 +47,11 @@ func TestAndroidDouyinE2E(t *testing.T) {
Android().
TapByOCR(
"直播中",
uixt.WithIgnoreNotFoundError(true),
uixt.WithIndex(-1),
options.WithIgnoreNotFoundError(true),
options.WithIndex(-1),
).
EndToEndDelay(uixt.WithInterval(5), uixt.WithTimeout(120)).
TapByUITypes(uixt.WithScreenShotUITypes("close")),
EndToEndDelay(options.WithInterval(5), options.WithTimeout(120)).
TapByUITypes(options.WithScreenShotUITypes("close")),
},
}

View File

@@ -59,7 +59,7 @@ func launchAppDriver(pkgName string) (driver *uixt.DriverExt, err error) {
}
// 进入推荐页
err = driver.TapByOCR("推荐", uixt.WithScope(0, 0, 1, 0.3))
err = driver.TapByOCR("推荐", options.WithScope(0, 0, 1, 0.3))
if err != nil {
return nil, err
}
@@ -92,7 +92,7 @@ func watchVideo(driver *uixt.DriverExt) (err error) {
// 切换横屏
err = driver.TapByUIDetection(
uixt.WithScreenShotUITypes("fullScreen"))
options.WithScreenShotUITypes("fullScreen"))
if err != nil {
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed
// 退出回到推荐页

View File

@@ -59,7 +59,7 @@ func launchAppDriver(pkgName string) (driver *uixt.DriverExt, err error) {
}
// 进入推荐页
err = driver.TapByOCR("推荐", uixt.WithScope(0, 0, 1, 0.3))
err = driver.TapByOCR("推荐", options.WithScope(0, 0, 1, 0.3))
if err != nil {
return nil, err
}
@@ -92,7 +92,7 @@ func watchVideo(driver *uixt.DriverExt) (err error) {
// 切换横屏
err = driver.TapByUIDetection(
uixt.WithScreenShotUITypes("fullScreen"))
options.WithScreenShotUITypes("fullScreen"))
if err != nil {
// 未找到横屏图标,该页面可能不是横版视频(直播|广告|Feed
// 退出回到推荐页

View File

@@ -6,7 +6,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -27,7 +26,7 @@ func TestAndroidDouyinFeedTest(t *testing.T) {
AssertAppInForeground("com.ss.android.ugc.aweme"),
hrp.NewStep("处理青少年弹窗").
Android().
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
TapByOCR("我知道了", options.WithIgnoreNotFoundError(true)),
hrp.NewStep("滑动 Feed 3 次,随机间隔 0-5s").
Loop(3).
Android().

View File

@@ -6,7 +6,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -27,10 +26,10 @@ func TestAndroidLiveSwipeTest(t *testing.T) {
AssertAppInForeground("com.ss.android.ugc.aweme"),
hrp.NewStep("处理青少年弹窗").
Android().
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
TapByOCR("我知道了", options.WithIgnoreNotFoundError(true)),
hrp.NewStep("在推荐页上划,直到出现「点击进入直播间」").
Android().
SwipeToTapText("点击进入直播间", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
SwipeToTapText("点击进入直播间", options.WithMaxRetryTimes(10), options.WithIdentifier("进入直播间")),
hrp.NewStep("滑动 Feed 5 次60% 随机间隔 0-5s40% 随机间隔 5-10s").
Loop(5).
Android().
@@ -38,8 +37,8 @@ func TestAndroidLiveSwipeTest(t *testing.T) {
SleepRandom(0, 5, 0.6, 5, 10, 0.4),
hrp.NewStep("向上滑动,等待 10s").
Android().
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(5).ScreenShot(). // 上划 1 次,等待 5s截图保存
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(5).ScreenShot(), // 再上划 1 次,等待 5s截图保存
SwipeUp(options.WithIdentifier("第一次上划")).Sleep(5).ScreenShot(). // 上划 1 次,等待 5s截图保存
SwipeUp(options.WithIdentifier("第二次上划")).Sleep(5).ScreenShot(), // 再上划 1 次,等待 5s截图保存
hrp.NewStep("exit").
Android().
AppTerminate("com.ss.android.ugc.aweme").

View File

@@ -6,7 +6,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -26,22 +25,34 @@ func TestIOSDouyinFollowLive(t *testing.T) {
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithIdentifier("启动抖音")).Sleep(5).
SwipeToTapApp("$app_name",
options.WithMaxRetryTimes(5),
options.WithIdentifier("启动抖音")).
Sleep(5).
Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
hrp.NewStep("处理青少年弹窗").
IOS().
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
TapByOCR("我知道了", options.WithIgnoreNotFoundError(true)),
hrp.NewStep("点击首页").
IOS().
TapByOCR("首页", uixt.WithIndex(-1)).Sleep(10),
TapByOCR("首页", options.WithIndex(-1)).Sleep(10),
hrp.NewStep("点击关注页").
IOS().
TapByOCR("关注", uixt.WithIndex(1)).Sleep(10),
TapByOCR("关注", options.WithIndex(1)).Sleep(10),
hrp.NewStep("向上滑动 2 次").
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"), uixt.WithOffsetRandomRange(-10, 10)).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s截图保存
Swipe(0.9, 0.7, 0.9, 0.3, uixt.WithIdentifier("slide_in_live"), uixt.WithOffsetRandomRange(-10, 10)).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s截图保存
IOS().
SwipeToTapTexts([]string{"理肤泉", "婉宝"},
options.WithCustomDirection(0.6, 0.2, 0.2, 0.2),
options.WithIdentifier("click_live")).Sleep(10).
Swipe(0.9, 0.7, 0.9, 0.3,
options.WithIdentifier("slide_in_live"),
options.WithOffsetRandomRange(-10, 10)).
Sleep(10).ScreenShot(). // 上划 1 次,等待 10s截图保存
Swipe(0.9, 0.7, 0.9, 0.3,
options.WithIdentifier("slide_in_live"),
options.WithOffsetRandomRange(-10, 10)).
Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s截图保存
},
}

View File

@@ -6,7 +6,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -26,19 +25,23 @@ func TestIOSDouyinLive(t *testing.T) {
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithIdentifier("启动抖音")).Sleep(5).
SwipeToTapApp("$app_name",
options.WithMaxRetryTimes(5),
options.WithIdentifier("启动抖音")).Sleep(5).
Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
hrp.NewStep("处理青少年弹窗").
IOS().
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
TapByOCR("我知道了", options.WithIgnoreNotFoundError(true)),
hrp.NewStep("向上滑动 2 次").
IOS().
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s截图保存
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s截图保存
SwipeUp(options.WithIdentifier("第一次上划")).Sleep(2).ScreenShot(). // 上划 1 次,等待 2s截图保存
SwipeUp(options.WithIdentifier("第二次上划")).Sleep(2).ScreenShot(), // 再上划 1 次,等待 2s截图保存
hrp.NewStep("在推荐页上划,直到出现「点击进入直播间」").
IOS().
SwipeToTapText("点击进入直播间", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
SwipeToTapText("点击进入直播间",
options.WithMaxRetryTimes(10),
options.WithIdentifier("进入直播间")),
},
}

View File

@@ -6,7 +6,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -26,23 +25,25 @@ func TestWDALog(t *testing.T) {
IOS().
Home().
AppTerminate("com.ss.iphone.ugc.Aweme"). // 关闭已运行的抖音
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithIdentifier("启动抖音")).Sleep(5).
SwipeToTapApp("$app_name",
options.WithMaxRetryTimes(5),
options.WithIdentifier("启动抖音")).Sleep(5).
Validate().
AssertOCRExists("推荐", "抖音启动失败,「推荐」不存在"),
hrp.NewStep("处理青少年弹窗").
IOS().
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
TapByOCR("我知道了", options.WithIgnoreNotFoundError(true)),
hrp.NewStep("进入购物页").
IOS().TapByOCR("商城", uixt.WithIdentifier("点击商城")).Sleep(5),
IOS().TapByOCR("商城", options.WithIdentifier("点击商城")).Sleep(5),
hrp.NewStep("进入推荐页").
IOS().TapByOCR("推荐", uixt.WithIdentifier("点击推荐")).Sleep(5),
IOS().TapByOCR("推荐", options.WithIdentifier("点击推荐")).Sleep(5),
hrp.NewStep("向上滑动 2 次").
IOS().
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("输入搜索关键词")),
SwipeUp(options.WithIdentifier("第 1 次上划")).Sleep(2).
SwipeUp(options.WithIdentifier("第 2 次上划")).Sleep(2).
SwipeUp(options.WithIdentifier("第 3 次上划")).Sleep(2).
TapXY(0.9, 0.1, options.WithIdentifier("点击进入搜索框")).Sleep(2).
Input("httprunner", options.WithIdentifier("输入搜索关键词")),
},
}

View File

@@ -4,7 +4,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -45,11 +44,11 @@ func TestAndroidExpertTest(t *testing.T) {
Android().
SwipeToTapTexts(
[]string{"直播", "直播中", "点击进入直播间"},
uixt.WithCustomDirection(0.5, 0.7, 0.5, 0.3),
uixt.WithScope(0.2, 0.2, 1, 0.8),
uixt.WithMaxRetryTimes(50),
uixt.WithWaitTime(1.5),
uixt.WithIdentifier("click_live"),
options.WithCustomDirection(0.5, 0.7, 0.5, 0.3),
options.WithScope(0.2, 0.2, 1, 0.8),
options.WithMaxRetryTimes(50),
options.WithWaitTime(1.5),
options.WithIdentifier("click_live"),
),
hrp.NewStep("sleep 10s").
Android().
@@ -58,7 +57,7 @@ func TestAndroidExpertTest(t *testing.T) {
Android().
Swipe(
0.5, 0.7, 0.5, 0.3,
uixt.WithIdentifier("slide_in_live"),
options.WithIdentifier("slide_in_live"),
).
Sleep(5).
Back().
@@ -68,22 +67,22 @@ func TestAndroidExpertTest(t *testing.T) {
Android().
TapXY(
0.9, 0.08,
uixt.WithIdentifier("click_search_in_middle_page"),
options.WithIdentifier("click_search_in_middle_page"),
).
Sleep(5),
hrp.NewStep("【搜索】输入query词 input").
Android().
Input(
"$query",
uixt.WithIdentifier("input_query"),
options.WithIdentifier("input_query"),
).
Sleep(5),
hrp.NewStep("【搜索】点击搜索按钮 tap_ocr 自定义配置").
Android().
TapByOCR(
"搜索",
uixt.WithIdentifier("click_search_after_input_query"),
uixt.WithIndex(0),
options.WithIdentifier("click_search_after_input_query"),
options.WithIndex(0),
).
Sleep(5),
hrp.NewStep("选择直播页签 tap_ocr 默认配置").
@@ -98,8 +97,8 @@ func TestAndroidExpertTest(t *testing.T) {
hrp.NewStep("【生活服务】点击货架商品 tap_ocr 自定义配置").
Android().
TapByUITypes(
uixt.WithScreenShotUITypes("dyhouse", "shoppingbag"),
uixt.WithIdentifier("click_sales_rack"),
options.WithScreenShotUITypes("dyhouse", "shoppingbag"),
options.WithIdentifier("click_sales_rack"),
).
Sleep(5),
// 冷启动
@@ -112,13 +111,13 @@ func TestAndroidExpertTest(t *testing.T) {
hrp.NewStep("home 以及 swipe_to_tap_app 自定义配置").
Android().
Home().
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithInterval(1), uixt.WithTapOffset(0, -50)).
SwipeToTapApp("$app_name", options.WithMaxRetryTimes(5), options.WithInterval(1), options.WithTapOffset(0, -50)).
Sleep(10),
hrp.NewStep("处理弹窗 close_popups 自定义配置 以及 ui_ocr exists 断言").
Android().
ClosePopups(
uixt.WithMaxRetryTimes(3),
uixt.WithInterval(2),
options.WithMaxRetryTimes(3),
options.WithInterval(2),
).
Validate().
AssertOCRExists("推荐", "进入抖音失败"),
@@ -128,7 +127,7 @@ func TestAndroidExpertTest(t *testing.T) {
Home().
AppTerminate("$bundle_id").
Sleep(3).
SwipeToTapApp("local", uixt.WithMaxRetryTimes(5)).Sleep(10),
SwipeToTapApp("local", options.WithMaxRetryTimes(5)).Sleep(10),
hrp.NewStep("screeshot 以及 sleep_random").
Loop(3).
Android().
@@ -179,11 +178,11 @@ func TestIOSExpertTest(t *testing.T) {
IOS().
SwipeToTapTexts(
[]string{"直播", "直播中", "点击进入直播间"},
uixt.WithCustomDirection(0.5, 0.7, 0.5, 0.3),
uixt.WithScope(0.2, 0.2, 1, 0.8),
uixt.WithMaxRetryTimes(50),
uixt.WithWaitTime(1.5),
uixt.WithIdentifier("click_live"),
options.WithCustomDirection(0.5, 0.7, 0.5, 0.3),
options.WithScope(0.2, 0.2, 1, 0.8),
options.WithMaxRetryTimes(50),
options.WithWaitTime(1.5),
options.WithIdentifier("click_live"),
),
hrp.NewStep("sleep 10s").
IOS().
@@ -192,7 +191,7 @@ func TestIOSExpertTest(t *testing.T) {
IOS().
Swipe(
0.5, 0.7, 0.5, 0.3,
uixt.WithIdentifier("slide_in_live"),
options.WithIdentifier("slide_in_live"),
).
Sleep(5).
Back().
@@ -202,22 +201,22 @@ func TestIOSExpertTest(t *testing.T) {
IOS().
TapXY(
0.9, 0.075,
uixt.WithIdentifier("click_search_in_middle_page"),
options.WithIdentifier("click_search_in_middle_page"),
).
Sleep(5),
hrp.NewStep("【搜索】输入query词 input").
IOS().
Input(
"$query",
uixt.WithIdentifier("input_query"),
options.WithIdentifier("input_query"),
).
Sleep(5),
hrp.NewStep("【搜索】点击搜索按钮 tap_ocr 自定义配置").
IOS().
TapByOCR(
"搜索",
uixt.WithIdentifier("click_search_after_input_query"),
uixt.WithIndex(0),
options.WithIdentifier("click_search_after_input_query"),
options.WithIndex(0),
).
Sleep(5),
// 生活服务赛道
@@ -232,8 +231,8 @@ func TestIOSExpertTest(t *testing.T) {
hrp.NewStep("【生活服务】点击货架商品 tap_ocr 自定义配置").
IOS().
TapByUITypes(
uixt.WithScreenShotUITypes("dyhouse", "shoppingbag"),
uixt.WithIdentifier("click_sales_rack"),
options.WithScreenShotUITypes("dyhouse", "shoppingbag"),
options.WithIdentifier("click_sales_rack"),
).
Sleep(5),
// 冷启动
@@ -245,13 +244,13 @@ func TestIOSExpertTest(t *testing.T) {
hrp.NewStep("home 以及 swipe_to_tap_app 自定义配置").
IOS().
Home().
SwipeToTapApp("$app_name", uixt.WithMaxRetryTimes(5), uixt.WithInterval(1), uixt.WithTapOffset(0, -50)).
SwipeToTapApp("$app_name", options.WithMaxRetryTimes(5), options.WithInterval(1), options.WithTapOffset(0, -50)).
Sleep(10),
hrp.NewStep("处理弹窗 close_popups 自定义配置 以及 ui_ocr exists 断言").
IOS().
ClosePopups(
uixt.WithMaxRetryTimes(3),
uixt.WithInterval(2),
options.WithMaxRetryTimes(3),
options.WithInterval(2),
).
Validate().
AssertOCRExists("推荐", "进入抖音失败"),
@@ -261,7 +260,7 @@ func TestIOSExpertTest(t *testing.T) {
Home().
AppTerminate("$bundle_id").
Sleep(3).
SwipeToTapApp("local", uixt.WithMaxRetryTimes(5)).Sleep(10),
SwipeToTapApp("local", options.WithMaxRetryTimes(5)).Sleep(10),
hrp.NewStep("screeshot 以及 sleep_random").
Loop(3).
IOS().

View File

@@ -4,7 +4,6 @@ import (
"testing"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/options"
)
@@ -26,8 +25,8 @@ func TestHarmonyDouyinE2E(t *testing.T) {
Home().
SwipeToTapApp(
"抖音",
uixt.WithMaxRetryTimes(5),
uixt.WithTapOffset(0, -50),
options.WithMaxRetryTimes(5),
options.WithTapOffset(0, -50),
).
Sleep(20).
Validate().
@@ -48,11 +47,11 @@ func TestHarmonyDouyinE2E(t *testing.T) {
Harmony().
TapByOCR(
"直播中",
uixt.WithIgnoreNotFoundError(true),
uixt.WithIndex(-1),
options.WithIgnoreNotFoundError(true),
options.WithIndex(-1),
).
EndToEndDelay(uixt.WithInterval(5), uixt.WithTimeout(120)).
TapByUITypes(uixt.WithScreenShotUITypes("close")),
EndToEndDelay(options.WithInterval(5), options.WithTimeout(120)).
TapByUITypes(options.WithScreenShotUITypes("close")),
},
}