mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
change: update examples
This commit is contained in:
@@ -1,44 +0,0 @@
|
|||||||
//go:build localtest
|
|
||||||
|
|
||||||
package uitest
|
|
||||||
|
|
||||||
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(uixt.WithUIA2(false), uixt.WithAdbLogOn(true)),
|
|
||||||
TestSteps: []hrp.IStep{
|
|
||||||
hrp.NewStep("启动抖音").
|
|
||||||
Android().
|
|
||||||
Home().
|
|
||||||
AppTerminate("com.ss.android.ugc.aweme"). // 关闭已运行的抖音,确保启动抖音后在「抖音」首页
|
|
||||||
SwipeToTapApp("抖音", uixt.WithMaxRetryTimes(5)).
|
|
||||||
Sleep(10),
|
|
||||||
hrp.NewStep("处理青少年弹窗").
|
|
||||||
Android().
|
|
||||||
Tap("推荐").
|
|
||||||
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)).
|
|
||||||
Validate().
|
|
||||||
AssertOCRExists("首页", "抖音启动失败,「首页」不存在"),
|
|
||||||
hrp.NewStep("在推荐页上划,直到出现 feed 头像「直播」").
|
|
||||||
Android().
|
|
||||||
SwipeToTapText("直播", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
|
|
||||||
hrp.NewStep("向上滑动,等待 10s").
|
|
||||||
Android().
|
|
||||||
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
|
||||||
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
runner := hrp.NewRunner(t).SetSaveTests(true)
|
|
||||||
err := runner.Run(testCase)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,7 +50,7 @@ func TestAndroidDouyinFeedTest(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := testCase.Dump2JSON("demo_android_feed_random_swipe.json"); err != nil {
|
if err := testCase.Dump2JSON("demo_android_feed_swipe.json"); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "sleep",
|
"method": "sleep",
|
||||||
"params": 10
|
"params": 5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -51,45 +51,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "滑动 Feed 3 次,随机间隔 0-5s",
|
"name": "在推荐页上划,直到出现「点击进入直播间」",
|
||||||
"android": {
|
"android": {
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"method": "swipe",
|
"method": "swipe_to_tap_text",
|
||||||
"params": "up"
|
"params": "点击进入直播间",
|
||||||
},
|
"identifier": "进入直播间",
|
||||||
{
|
"max_retry_times": 10
|
||||||
"method": "sleep_random",
|
|
||||||
"params": [
|
|
||||||
0,
|
|
||||||
5
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
"loops": 3
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "滑动 Feed 1 次,随机间隔 5-10s",
|
"name": "滑动 Feed 5 次,60% 随机间隔 0-5s,40% 随机间隔 5-10s",
|
||||||
"android": {
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"method": "swipe",
|
|
||||||
"params": "up"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"method": "sleep_random",
|
|
||||||
"params": [
|
|
||||||
5,
|
|
||||||
10
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"loops": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "滑动 Feed 10 次,70% 随机间隔 0-5s,30% 随机间隔 5-10s",
|
|
||||||
"android": {
|
"android": {
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
@@ -101,15 +76,46 @@
|
|||||||
"params": [
|
"params": [
|
||||||
0,
|
0,
|
||||||
5,
|
5,
|
||||||
0.7,
|
0.6,
|
||||||
5,
|
5,
|
||||||
10,
|
10,
|
||||||
0.3
|
0.4
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"loops": 2
|
"loops": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "向上滑动,等待 10s",
|
||||||
|
"android": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"method": "swipe",
|
||||||
|
"params": "up",
|
||||||
|
"identifier": "第一次上划"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "sleep",
|
||||||
|
"params": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "screenshot"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "swipe",
|
||||||
|
"params": "up",
|
||||||
|
"identifier": "第二次上划"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "sleep",
|
||||||
|
"params": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "screenshot"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "exit",
|
"name": "exit",
|
||||||
59
examples/uitest/demo_android_live_swipe_test.go
Normal file
59
examples/uitest/demo_android_live_swipe_test.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
//go:build localtest
|
||||||
|
|
||||||
|
package uitest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAndroidLiveSwipeTest(t *testing.T) {
|
||||||
|
testCase := &hrp.TestCase{
|
||||||
|
Config: hrp.NewConfig("点播_抖音_滑动场景_随机间隔_android").
|
||||||
|
WithVariables(map[string]interface{}{
|
||||||
|
"device": "${ENV(SerialNumber)}",
|
||||||
|
}).
|
||||||
|
SetAndroid(uixt.WithSerialNumber("$device")),
|
||||||
|
TestSteps: []hrp.IStep{
|
||||||
|
hrp.NewStep("启动抖音").
|
||||||
|
Android().
|
||||||
|
AppTerminate("com.ss.android.ugc.aweme").
|
||||||
|
AppLaunch("com.ss.android.ugc.aweme").
|
||||||
|
Sleep(5).
|
||||||
|
Validate().
|
||||||
|
AssertAppInForeground("com.ss.android.ugc.aweme"),
|
||||||
|
hrp.NewStep("处理青少年弹窗").
|
||||||
|
Android().
|
||||||
|
TapByOCR("我知道了", uixt.WithIgnoreNotFoundError(true)),
|
||||||
|
hrp.NewStep("在推荐页上划,直到出现「点击进入直播间」").
|
||||||
|
Android().
|
||||||
|
SwipeToTapText("点击进入直播间", uixt.WithMaxRetryTimes(10), uixt.WithIdentifier("进入直播间")),
|
||||||
|
hrp.NewStep("滑动 Feed 5 次,60% 随机间隔 0-5s,40% 随机间隔 5-10s").
|
||||||
|
Loop(5).
|
||||||
|
Android().
|
||||||
|
SwipeUp().
|
||||||
|
SleepRandom(0, 5, 0.6, 5, 10, 0.4),
|
||||||
|
hrp.NewStep("向上滑动,等待 10s").
|
||||||
|
Android().
|
||||||
|
SwipeUp(uixt.WithIdentifier("第一次上划")).Sleep(10).ScreenShot(). // 上划 1 次,等待 10s,截图保存
|
||||||
|
SwipeUp(uixt.WithIdentifier("第二次上划")).Sleep(10).ScreenShot(), // 再上划 1 次,等待 10s,截图保存
|
||||||
|
hrp.NewStep("exit").
|
||||||
|
Android().
|
||||||
|
AppTerminate("com.ss.android.ugc.aweme").
|
||||||
|
Validate().
|
||||||
|
AssertAppNotInForeground("com.ss.android.ugc.aweme"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := testCase.Dump2JSON("demo_android_live_swipe.json"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runner := hrp.NewRunner(t).SetSaveTests(true)
|
||||||
|
err := runner.Run(testCase)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user