docs: enter WC live

This commit is contained in:
debugtalk
2022-11-27 00:16:02 +08:00
parent a64151361d
commit 7312d50a33
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
import (
"errors"
"os"
"strings"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
var rootCmd = &cobra.Command{
@@ -21,7 +24,21 @@ var rootCmd = &cobra.Command{
setLogLevel(logLevel)
},
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.DumpResult()
return nil
@@ -29,19 +46,21 @@ var rootCmd = &cobra.Command{
}
var (
uuid string
osType string
duration int
interval int
logLevel string
matchName string
perf []string
uuid string
iosApp string
androidApp string
duration int
interval int
logLevel string
matchName string
perf []string
)
func main() {
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(&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(&interval, "interval", "i", 15, "set interval in seconds")
rootCmd.PersistentFlags().StringVarP(&matchName, "match-name", "n", "", "specify match name")

View File

@@ -90,6 +90,7 @@ type WorldCupLive struct {
resultDir string
UUID string `json:"uuid"`
MatchName string `json:"matchName"`
BundleID string `json:"bundleID"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
Interval int `json:"interval"` // seconds
@@ -98,15 +99,7 @@ type WorldCupLive struct {
PerfData []string `json:"perfData"`
}
func NewWorldCupLive(matchName, osType 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()
}
func NewWorldCupLive(device uixt.Device, matchName, bundleID string, duration, interval int) *WorldCupLive {
driverExt, err := device.NewDriver(nil)
if err != nil {
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")
}
// 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")
if interval == 0 {
@@ -139,16 +133,22 @@ func NewWorldCupLive(matchName, osType string, duration, interval int) *WorldCup
duration = 30
}
return &WorldCupLive{
wc := &WorldCupLive{
driver: driverExt,
file: f,
resultDir: resultDir,
UUID: device.UUID(),
BundleID: bundleID,
Duration: duration,
Interval: interval,
StartTime: startTime.Format("2006-01-02 15:04:05"),
MatchName: matchName,
}
if bundleID != "" {
wc.EnterLive(bundleID)
}
return wc
}
func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
@@ -183,6 +183,52 @@ func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
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() {
wc.done = make(chan bool)
go func() {

View File

@@ -1,11 +1,7 @@
//go:build localtest
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvertTimeToSeconds(t *testing.T) {
testData := []struct {
timeStr string
@@ -26,6 +22,16 @@ func TestConvertTimeToSeconds(t *testing.T) {
}
}
func TestMain(t *testing.T) {
main()
func TestMainIOS(t *testing.T) {
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()
}