mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +08:00
feat: run xctest before start ios automation
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "wcl",
|
||||
Short: "Monitor FIFA World Cup Live",
|
||||
Version: "2022.11.30.2341",
|
||||
Version: "2022.12.01.2236",
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
log.Logger = zerolog.New(
|
||||
zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr},
|
||||
|
||||
@@ -65,6 +65,7 @@ func initIOSDevice(uuid string) uixt.Device {
|
||||
uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800),
|
||||
uixt.WithResetHomeOnStartup(false), // not reset home on startup
|
||||
uixt.WithPerfOptions(perfOptions...),
|
||||
uixt.WithXCTest("com.gtf.wda.runner.xctrunner"),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed to init ios device")
|
||||
|
||||
@@ -29,6 +29,7 @@ func TestConvertTimeToSeconds(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMainIOS(t *testing.T) {
|
||||
uuid := "00008030-00194DA421C1802E"
|
||||
device := initIOSDevice(uuid)
|
||||
bundleID := "com.ss.iphone.ugc.Aweme"
|
||||
wc := NewWorldCupLive(device, "", bundleID, 30, 10)
|
||||
|
||||
@@ -2,10 +2,12 @@ package uixt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
builtinJSON "encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
builtinLog "log"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
"net"
|
||||
@@ -96,6 +98,12 @@ func WithDismissAlertButtonSelector(selector string) IOSDeviceOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithXCTest(bundleID string) IOSDeviceOption {
|
||||
return func(device *IOSDevice) {
|
||||
device.XCTestBundleID = bundleID
|
||||
}
|
||||
}
|
||||
|
||||
func WithPerfOptions(options ...gidevice.PerfOption) IOSDeviceOption {
|
||||
return func(device *IOSDevice) {
|
||||
device.PerfOptions = &gidevice.PerfOptions{}
|
||||
@@ -186,10 +194,21 @@ func NewIOSDevice(options ...IOSDeviceOption) (device *IOSDevice, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(deviceList) > 0 {
|
||||
device.UDID = deviceList[0].Properties().SerialNumber
|
||||
for _, dev := range deviceList {
|
||||
udid := dev.Properties().SerialNumber
|
||||
device.UDID = udid
|
||||
device.d = dev
|
||||
|
||||
// run xctest if XCTestBundleID is set
|
||||
if device.XCTestBundleID != "" {
|
||||
_, err = device.RunXCTest(device.XCTestBundleID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("udid", udid).Msg("failed to init XCTest")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
log.Info().Str("udid", device.UDID).Msg("select device")
|
||||
device.d = deviceList[0]
|
||||
return device, nil
|
||||
}
|
||||
|
||||
@@ -198,12 +217,13 @@ func NewIOSDevice(options ...IOSDeviceOption) (device *IOSDevice, err error) {
|
||||
}
|
||||
|
||||
type IOSDevice struct {
|
||||
d gidevice.Device
|
||||
PerfOptions *gidevice.PerfOptions `json:"perf_options,omitempty" yaml:"perf_options,omitempty"`
|
||||
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
||||
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
d gidevice.Device
|
||||
PerfOptions *gidevice.PerfOptions `json:"perf_options,omitempty" yaml:"perf_options,omitempty"`
|
||||
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
||||
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
XCTestBundleID string `json:"xctest_bundle_id,omitempty" yaml:"xctest_bundle_id,omitempty"`
|
||||
|
||||
// switch to iOS springboard before init WDA session
|
||||
ResetHomeOnStartup bool `json:"reset_home_on_startup,omitempty" yaml:"reset_home_on_startup,omitempty"`
|
||||
@@ -479,6 +499,33 @@ func (dev *IOSDevice) NewUSBDriver(capabilities Capabilities) (driver WebDriver,
|
||||
return wd, nil
|
||||
}
|
||||
|
||||
func (dev *IOSDevice) RunXCTest(bundleID string) (cancel context.CancelFunc, err error) {
|
||||
log.Info().Str("bundleID", bundleID).Msg("run xctest")
|
||||
out, cancel, err := dev.d.XCTest(bundleID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "run xctest failed")
|
||||
}
|
||||
// wait for xctest to start
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
f, err := os.OpenFile(fmt.Sprintf("xctest_%s.log", dev.UDID),
|
||||
os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer builtinLog.SetOutput(f)
|
||||
|
||||
// print xctest running logs
|
||||
go func() {
|
||||
for s := range out {
|
||||
builtinLog.Print(s)
|
||||
}
|
||||
f.Close()
|
||||
}()
|
||||
|
||||
return cancel, nil
|
||||
}
|
||||
|
||||
func (dExt *DriverExt) ConnectMjpegStream(httpClient *http.Client) (err error) {
|
||||
if httpClient == nil {
|
||||
return errors.New(`'httpClient' can't be nil`)
|
||||
|
||||
Reference in New Issue
Block a user