mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: run xctest before start ios automation
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
|||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "wcl",
|
Use: "wcl",
|
||||||
Short: "Monitor FIFA World Cup Live",
|
Short: "Monitor FIFA World Cup Live",
|
||||||
Version: "2022.11.30.2341",
|
Version: "2022.12.01.2236",
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
log.Logger = zerolog.New(
|
log.Logger = zerolog.New(
|
||||||
zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr},
|
zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr},
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ func initIOSDevice(uuid string) uixt.Device {
|
|||||||
uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800),
|
uixt.WithWDAPort(8700), uixt.WithWDAMjpegPort(8800),
|
||||||
uixt.WithResetHomeOnStartup(false), // not reset home on startup
|
uixt.WithResetHomeOnStartup(false), // not reset home on startup
|
||||||
uixt.WithPerfOptions(perfOptions...),
|
uixt.WithPerfOptions(perfOptions...),
|
||||||
|
uixt.WithXCTest("com.gtf.wda.runner.xctrunner"),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("failed to init ios device")
|
log.Fatal().Err(err).Msg("failed to init ios device")
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ func TestConvertTimeToSeconds(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMainIOS(t *testing.T) {
|
func TestMainIOS(t *testing.T) {
|
||||||
|
uuid := "00008030-00194DA421C1802E"
|
||||||
device := initIOSDevice(uuid)
|
device := initIOSDevice(uuid)
|
||||||
bundleID := "com.ss.iphone.ugc.Aweme"
|
bundleID := "com.ss.iphone.ugc.Aweme"
|
||||||
wc := NewWorldCupLive(device, "", bundleID, 30, 10)
|
wc := NewWorldCupLive(device, "", bundleID, 30, 10)
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package uixt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
builtinJSON "encoding/json"
|
builtinJSON "encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
builtinLog "log"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net"
|
"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 {
|
func WithPerfOptions(options ...gidevice.PerfOption) IOSDeviceOption {
|
||||||
return func(device *IOSDevice) {
|
return func(device *IOSDevice) {
|
||||||
device.PerfOptions = &gidevice.PerfOptions{}
|
device.PerfOptions = &gidevice.PerfOptions{}
|
||||||
@@ -186,10 +194,21 @@ func NewIOSDevice(options ...IOSDeviceOption) (device *IOSDevice, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(deviceList) > 0 {
|
for _, dev := range deviceList {
|
||||||
device.UDID = deviceList[0].Properties().SerialNumber
|
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")
|
log.Info().Str("udid", device.UDID).Msg("select device")
|
||||||
device.d = deviceList[0]
|
|
||||||
return device, nil
|
return device, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,12 +217,13 @@ func NewIOSDevice(options ...IOSDeviceOption) (device *IOSDevice, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IOSDevice struct {
|
type IOSDevice struct {
|
||||||
d gidevice.Device
|
d gidevice.Device
|
||||||
PerfOptions *gidevice.PerfOptions `json:"perf_options,omitempty" yaml:"perf_options,omitempty"`
|
PerfOptions *gidevice.PerfOptions `json:"perf_options,omitempty" yaml:"perf_options,omitempty"`
|
||||||
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
UDID string `json:"udid,omitempty" yaml:"udid,omitempty"`
|
||||||
Port int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
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
|
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
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
|
// switch to iOS springboard before init WDA session
|
||||||
ResetHomeOnStartup bool `json:"reset_home_on_startup,omitempty" yaml:"reset_home_on_startup,omitempty"`
|
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
|
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) {
|
func (dExt *DriverExt) ConnectMjpegStream(httpClient *http.Client) (err error) {
|
||||||
if httpClient == nil {
|
if httpClient == nil {
|
||||||
return errors.New(`'httpClient' can't be nil`)
|
return errors.New(`'httpClient' can't be nil`)
|
||||||
|
|||||||
Reference in New Issue
Block a user