mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-10 17:43:00 +08:00
feat: lazy setup WDA
This commit is contained in:
@@ -30,6 +30,9 @@ const (
|
||||
)
|
||||
|
||||
func NewStubIOSDriver(dev *uixt.IOSDevice) (*StubIOSDriver, error) {
|
||||
// lazy setup WDA
|
||||
dev.Options.LazySetup = true
|
||||
|
||||
wdaDriver, err := uixt.NewWDADriver(dev)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -37,9 +37,11 @@ func NewWDADriver(device *IOSDevice) (*WDADriver, error) {
|
||||
Session: NewDriverSession(),
|
||||
}
|
||||
|
||||
// setup driver
|
||||
if err := driver.Setup(); err != nil {
|
||||
return nil, err
|
||||
if !device.Options.LazySetup {
|
||||
// setup driver
|
||||
if err := driver.Setup(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// register driver session reset handler
|
||||
|
||||
@@ -33,6 +33,20 @@ func TestDevice_IOS_Install(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestDriver_WDA_LazySetup(t *testing.T) {
|
||||
device, err := NewIOSDevice(
|
||||
option.WithWDAPort(8700),
|
||||
option.WithWDAMjpegPort(8800),
|
||||
option.WithLazySetup(true))
|
||||
require.Nil(t, err)
|
||||
driver, err := NewWDADriver(device)
|
||||
require.Nil(t, err)
|
||||
err = driver.PressButton(types.DeviceButtonHome)
|
||||
assert.Nil(t, err)
|
||||
err = driver.TapXY(0.5, 0.5)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestDevice_IOS_New(t *testing.T) {
|
||||
device, err := NewIOSDevice(
|
||||
option.WithWDAPort(8700),
|
||||
|
||||
@@ -5,6 +5,7 @@ type IOSDeviceOptions struct {
|
||||
WDAPort int `json:"port,omitempty" yaml:"port,omitempty"` // WDA remote port
|
||||
WDAMjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"` // WDA remote MJPEG port
|
||||
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
|
||||
LazySetup bool `json:"lazy_setup,omitempty" yaml:"lazy_setup,omitempty"` // lazy setup WDA
|
||||
|
||||
// switch to iOS springboard before init WDA session
|
||||
ResetHomeOnStartup bool `json:"reset_home_on_startup,omitempty" yaml:"reset_home_on_startup,omitempty"`
|
||||
@@ -28,6 +29,9 @@ func (dev *IOSDeviceOptions) Options() (deviceOptions []IOSDeviceOption) {
|
||||
if dev.LogOn {
|
||||
deviceOptions = append(deviceOptions, WithWDALogOn(true))
|
||||
}
|
||||
if dev.LazySetup {
|
||||
deviceOptions = append(deviceOptions, WithLazySetup(true))
|
||||
}
|
||||
if dev.ResetHomeOnStartup {
|
||||
deviceOptions = append(deviceOptions, WithResetHomeOnStartup(true))
|
||||
}
|
||||
@@ -115,6 +119,12 @@ func WithWDALogOn(logOn bool) IOSDeviceOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithLazySetup(lazySetup bool) IOSDeviceOption {
|
||||
return func(device *IOSDeviceOptions) {
|
||||
device.LazySetup = lazySetup
|
||||
}
|
||||
}
|
||||
|
||||
func WithResetHomeOnStartup(reset bool) IOSDeviceOption {
|
||||
return func(device *IOSDeviceOptions) {
|
||||
device.ResetHomeOnStartup = reset
|
||||
|
||||
Reference in New Issue
Block a user