docs: enter WC live

This commit is contained in:
debugtalk
2022-11-27 00:16:02 +08:00
parent 21b57ac70a
commit 446e37236a
6 changed files with 130 additions and 27 deletions

View File

@@ -0,0 +1,15 @@
# World Cup Live
```bash
$ wcl -n "法国vs丹麦" --android com.ss.android.ugc.aweme -d 120
```
抖音:
- com.ss.iphone.ugc.Aweme
- com.ss.android.ugc.aweme
央视频:
咪咕视频:

View File

@@ -1,12 +1,15 @@
package main package main
import ( import (
"errors"
"os" "os"
"strings" "strings"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
) )
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@@ -21,7 +24,21 @@ var rootCmd = &cobra.Command{
setLogLevel(logLevel) setLogLevel(logLevel)
}, },
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
wc := NewWorldCupLive(matchName, osType, duration, interval) var device uixt.Device
var bundleID string
if iosApp != "" {
log.Info().Str("bundleID", iosApp).Msg("init ios device")
device = initIOSDevice()
bundleID = iosApp
} else if androidApp != "" {
log.Info().Str("bundleID", androidApp).Msg("init android device")
device = initAndroidDevice()
bundleID = androidApp
} else {
return errors.New("android or ios app bundldID is required")
}
wc := NewWorldCupLive(device, matchName, bundleID, duration, interval)
wc.Start() wc.Start()
wc.DumpResult() wc.DumpResult()
return nil return nil
@@ -29,19 +46,21 @@ var rootCmd = &cobra.Command{
} }
var ( var (
uuid string uuid string
osType string iosApp string
duration int androidApp string
interval int duration int
logLevel string interval int
matchName string logLevel string
perf []string matchName string
perf []string
) )
func main() { func main() {
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level") rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
rootCmd.PersistentFlags().StringVarP(&uuid, "uuid", "u", "", "specify device serial or udid") rootCmd.PersistentFlags().StringVarP(&uuid, "uuid", "u", "", "specify device serial or udid")
rootCmd.PersistentFlags().StringVarP(&osType, "os-type", "t", "ios", "specify mobile os type") rootCmd.PersistentFlags().StringVar(&iosApp, "ios", "", "run ios app")
rootCmd.PersistentFlags().StringVar(&androidApp, "android", "", "run android app")
rootCmd.PersistentFlags().IntVarP(&duration, "duration", "d", 30, "set duration in seconds") rootCmd.PersistentFlags().IntVarP(&duration, "duration", "d", 30, "set duration in seconds")
rootCmd.PersistentFlags().IntVarP(&interval, "interval", "i", 15, "set interval 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().StringVarP(&matchName, "match-name", "n", "", "specify match name")

View File

@@ -90,6 +90,7 @@ type WorldCupLive struct {
resultDir string resultDir string
UUID string `json:"uuid"` UUID string `json:"uuid"`
MatchName string `json:"matchName"` MatchName string `json:"matchName"`
BundleID string `json:"bundleID"`
StartTime string `json:"startTime"` StartTime string `json:"startTime"`
EndTime string `json:"endTime"` EndTime string `json:"endTime"`
Interval int `json:"interval"` // seconds Interval int `json:"interval"` // seconds
@@ -98,15 +99,7 @@ type WorldCupLive struct {
PerfData []string `json:"perfData"` PerfData []string `json:"perfData"`
} }
func NewWorldCupLive(matchName, osType string, duration, interval int) *WorldCupLive { func NewWorldCupLive(device uixt.Device, matchName, bundleID string, duration, interval int) *WorldCupLive {
var device uixt.Device
log.Info().Str("osType", osType).Msg("init device")
if osType == "ios" {
device = initIOSDevice()
} else {
device = initAndroidDevice()
}
driverExt, err := device.NewDriver(nil) driverExt, err := device.NewDriver(nil)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("failed to init driver") log.Fatal().Err(err).Msg("failed to init driver")
@@ -130,6 +123,7 @@ func NewWorldCupLive(matchName, osType string, duration, interval int) *WorldCup
log.Fatal().Err(err).Msg("failed to open file") log.Fatal().Err(err).Msg("failed to open file")
} }
// write title // 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") f.WriteString("utc_time\tutc_timestamp\tlive_time\tlive_seconds\n")
if interval == 0 { if interval == 0 {
@@ -139,16 +133,22 @@ func NewWorldCupLive(matchName, osType string, duration, interval int) *WorldCup
duration = 30 duration = 30
} }
return &WorldCupLive{ wc := &WorldCupLive{
driver: driverExt, driver: driverExt,
file: f, file: f,
resultDir: resultDir, resultDir: resultDir,
UUID: device.UUID(), UUID: device.UUID(),
BundleID: bundleID,
Duration: duration, Duration: duration,
Interval: interval, Interval: interval,
StartTime: startTime.Format("2006-01-02 15:04:05"), StartTime: startTime.Format("2006-01-02 15:04:05"),
MatchName: matchName, MatchName: matchName,
} }
if bundleID != "" {
wc.EnterLive(bundleID)
}
return wc
} }
func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error { func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
@@ -183,6 +183,52 @@ func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
return nil 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
}
// 青少年弹窗处理
if points, err := wc.driver.GetTextXYs([]string{"青少年模式", "我知道了"}); err == nil {
_ = wc.driver.TapAbsXY(points[1].X, points[1].Y)
}
// 点击进入搜索
err = wc.driver.TapXY(0.9, 0.07)
if err != nil {
log.Error().Err(err).Msg("enter search failed")
return err
}
// 搜索世界杯
_ = wc.driver.Input("世界杯")
err = wc.driver.TapByOCR("搜索")
if err != nil {
log.Error().Err(err).Msg("search 世界杯 failed")
return err
}
time.Sleep(2 * time.Second)
// 进入世界杯直播
if err = wc.driver.TapByOCR("直播中"); err != nil {
log.Error().Err(err).Msg("enter 直播中 failed")
return err
}
return nil
}
func (wc *WorldCupLive) Start() { func (wc *WorldCupLive) Start() {
wc.done = make(chan bool) wc.done = make(chan bool)
go func() { go func() {

View File

@@ -1,11 +1,7 @@
//go:build localtest
package main package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvertTimeToSeconds(t *testing.T) { func TestConvertTimeToSeconds(t *testing.T) {
testData := []struct { testData := []struct {
timeStr string timeStr string
@@ -26,6 +22,16 @@ func TestConvertTimeToSeconds(t *testing.T) {
} }
} }
func TestMain(t *testing.T) { func TestMainIOS(t *testing.T) {
main() device := initIOSDevice()
wc := NewWorldCupLive(device, "", "com.ss.iphone.ugc.Aweme", 30, 10)
wc.Start()
wc.DumpResult()
}
func TestMainAndroid(t *testing.T) {
device := initAndroidDevice()
wc := NewWorldCupLive(device, "", "com.ss.android.ugc.aweme", 30, 10)
wc.Start()
wc.DumpResult()
} }

12
hrp/cmd/ios/ios_test.go Normal file
View File

@@ -0,0 +1,12 @@
//go:build localtest
package ios
func TestGetDevice(t *testing.T) {
device, err := getDevice(udid)
if err != nil {
t.Fatal(err)
}
t.Logf("device: %v", device)
}

5
hrp/pkg/uixt/input.go Normal file
View File

@@ -0,0 +1,5 @@
package uixt
func (dExt *DriverExt) Input(text string) (err error) {
return dExt.Driver.Input(text)
}