mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 16:29:37 +08:00
fix: exit live room
This commit is contained in:
59
examples/uitest/demo_android_video_crawler.json
Normal file
59
examples/uitest/demo_android_video_crawler.json
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"name": "抓取抖音视频信息",
|
||||||
|
"variables": {
|
||||||
|
"device": "${ENV(SerialNumber)}"
|
||||||
|
},
|
||||||
|
"android": [
|
||||||
|
{
|
||||||
|
"serial": "$device"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"teststeps": [
|
||||||
|
{
|
||||||
|
"name": "滑动消费 feed 至少 10 个,live 至少 3 个;滑动过程中,70% 随机间隔 0-5s,30% 随机间隔 5-10s",
|
||||||
|
"android": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"method": "video_crawler",
|
||||||
|
"params": {
|
||||||
|
"app_package_name": "com.ss.android.ugc.aweme",
|
||||||
|
"sleep_random": [
|
||||||
|
0,
|
||||||
|
5,
|
||||||
|
0.7,
|
||||||
|
5,
|
||||||
|
10,
|
||||||
|
0.3
|
||||||
|
],
|
||||||
|
"target_count": {
|
||||||
|
"feed_count": 5,
|
||||||
|
"live_count": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "exit",
|
||||||
|
"android": {
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"method": "app_terminate",
|
||||||
|
"params": "com.ss.android.ugc.aweme"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "ui_foreground_app",
|
||||||
|
"assert": "not_equal",
|
||||||
|
"expect": "com.ss.android.ugc.aweme",
|
||||||
|
"msg": "app [com.ss.android.ugc.aweme] should not be in foreground"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
47
examples/uitest/demo_android_video_crawler_test.go
Normal file
47
examples/uitest/demo_android_video_crawler_test.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//go:build localtest
|
||||||
|
|
||||||
|
package uitest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAndroidVideoCrawlerTest(t *testing.T) {
|
||||||
|
testCase := &hrp.TestCase{
|
||||||
|
Config: hrp.NewConfig("抓取抖音视频信息").
|
||||||
|
WithVariables(map[string]interface{}{
|
||||||
|
"device": "${ENV(SerialNumber)}",
|
||||||
|
}).
|
||||||
|
SetAndroid(uixt.WithSerialNumber("$device")),
|
||||||
|
TestSteps: []hrp.IStep{
|
||||||
|
hrp.NewStep("滑动消费 feed 至少 10 个,live 至少 3 个;滑动过程中,70% 随机间隔 0-5s,30% 随机间隔 5-10s").
|
||||||
|
Android().
|
||||||
|
VideoCrawler(map[string]interface{}{
|
||||||
|
"app_package_name": "com.ss.android.ugc.aweme",
|
||||||
|
"target_count": map[string]interface{}{
|
||||||
|
"feed_count": 5,
|
||||||
|
"live_count": 3,
|
||||||
|
},
|
||||||
|
"sleep_random": []float64{0, 5, 0.7, 5, 10, 0.3},
|
||||||
|
}),
|
||||||
|
hrp.NewStep("exit").
|
||||||
|
Android().
|
||||||
|
AppTerminate("com.ss.android.ugc.aweme").
|
||||||
|
Validate().
|
||||||
|
AssertAppNotInForeground("com.ss.android.ugc.aweme"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := testCase.Dump2JSON("demo_android_video_crawler.json"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runner := hrp.NewRunner(t).SetSaveTests(true)
|
||||||
|
err := runner.Run(testCase)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -371,7 +371,7 @@ func (ad *adbDriver) AssertAppForeground(packageName string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if app.BundleId != packageName {
|
if app.PackageName != packageName {
|
||||||
return errors.New("app is not in foreground")
|
return errors.New("app is not in foreground")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -397,8 +397,8 @@ func (ad *adbDriver) GetForegroundApp() (app AppInfo, err error) {
|
|||||||
s := strings.Split(str, "/")
|
s := strings.Split(str, "/")
|
||||||
app := AppInfo{
|
app := AppInfo{
|
||||||
AppBaseInfo: AppBaseInfo{
|
AppBaseInfo: AppBaseInfo{
|
||||||
BundleId: s[0],
|
PackageName: s[0],
|
||||||
Activity: s[1],
|
Activity: s[1],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return app, nil
|
return app, nil
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ func TestDriver_IsAppInForeground(t *testing.T) {
|
|||||||
|
|
||||||
app, err := driverExt.Driver.GetForegroundApp()
|
app, err := driverExt.Driver.GetForegroundApp()
|
||||||
checkErr(t, err)
|
checkErr(t, err)
|
||||||
if app.BundleId != "com.android.settings" {
|
if app.PackageName != "com.android.settings" {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
if app.Activity != ".Settings" {
|
if app.Activity != ".Settings" {
|
||||||
|
|||||||
@@ -251,9 +251,11 @@ type AppInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AppBaseInfo struct {
|
type AppBaseInfo struct {
|
||||||
Pid int `json:"pid,omitempty"`
|
Pid int `json:"pid,omitempty"`
|
||||||
BundleId string `json:"bundleId"` // package name for android
|
BundleId string `json:"bundleId,omitempty"` // ios package name
|
||||||
Activity string // view controller for ios
|
ViewController string `json:"viewController,omitempty"` // ios view controller
|
||||||
|
PackageName string `json:"packageName,omitempty"` // android package name
|
||||||
|
Activity string `json:"activity,omitempty"` // android activity
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppState int
|
type AppState int
|
||||||
|
|||||||
@@ -89,8 +89,17 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// take screenshot and get screen texts by OCR
|
||||||
|
_, err := l.driver.GetScreenTextsByOCR()
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: check live type
|
||||||
|
|
||||||
// swipe to next live video
|
// swipe to next live video
|
||||||
err := l.driver.SwipeUp()
|
err = l.driver.SwipeUp()
|
||||||
// TODO: sleep custom random time
|
// TODO: sleep custom random time
|
||||||
time.Sleep(15 * time.Second)
|
time.Sleep(15 * time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -110,9 +119,8 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *LiveCrawler) exitLiveRoom() error {
|
func (l *LiveCrawler) exitLiveRoom() error {
|
||||||
// FIXME: exit live room
|
for i := 0; i < 3; i++ {
|
||||||
for i := 0; i < 5; i++ {
|
l.driver.SwipeRelative(0.1, 0.5, 0.9, 0.5)
|
||||||
l.driver.SwipeRelative(0, 0.5, 0.5, 0.5)
|
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
// check if back to feed page
|
// check if back to feed page
|
||||||
@@ -159,7 +167,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
texts, err := dExt.GetScreenTextsByOCR()
|
texts, err := dExt.GetScreenTextsByOCR()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("OCR GetTexts failed")
|
log.Error().Err(err).Msg("OCR GetTexts failed")
|
||||||
return err
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatic handling of pop-up windows
|
// automatic handling of pop-up windows
|
||||||
@@ -202,8 +210,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) assertActivity(pacakgeName, activityType string) error {
|
func (dExt *DriverExt) assertActivity(packageName, activityType string) error {
|
||||||
log.Debug().Str("pacakge_name", pacakgeName).
|
log.Debug().Str("pacakge_name", packageName).
|
||||||
Str("activity_type", activityType).Msg("assert activity")
|
Str("activity_type", activityType).Msg("assert activity")
|
||||||
app, err := dExt.Driver.GetForegroundApp()
|
app, err := dExt.Driver.GetForegroundApp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -211,11 +219,11 @@ func (dExt *DriverExt) assertActivity(pacakgeName, activityType string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.BundleId != pacakgeName {
|
if app.PackageName != packageName {
|
||||||
return fmt.Errorf("app %s is not in foreground", pacakgeName)
|
return fmt.Errorf("app %s is not in foreground", packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if activities, ok := androidActivities[app.BundleId]; ok {
|
if activities, ok := androidActivities[app.PackageName]; ok {
|
||||||
if activity, ok := activities[activityType]; ok {
|
if activity, ok := activities[activityType]; ok {
|
||||||
if strings.HasSuffix(app.Activity, activity) {
|
if strings.HasSuffix(app.Activity, activity) {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user