mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: miss device options
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2409251646
|
||||
v5.0.0-beta-2409252241
|
||||
@@ -42,6 +42,19 @@ func WithLogOn(logOn bool) HarmonyDeviceOption {
|
||||
}
|
||||
}
|
||||
|
||||
func GetHarmonyDeviceOptions(dev *HarmonyDevice) (deviceOptions []HarmonyDeviceOption) {
|
||||
if dev.ConnectKey != "" {
|
||||
deviceOptions = append(deviceOptions, WithConnectKey(dev.ConnectKey))
|
||||
}
|
||||
if dev.IgnorePopup {
|
||||
deviceOptions = append(deviceOptions, WithIgnorePopup(true))
|
||||
}
|
||||
if dev.LogOn {
|
||||
deviceOptions = append(deviceOptions, WithLogOn(true))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewHarmonyDevice(options ...HarmonyDeviceOption) (device *HarmonyDevice, err error) {
|
||||
device = &HarmonyDevice{}
|
||||
for _, option := range options {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/httprunner/httprunner/v4/hrp/code"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
// Run starts to run testcase with default configs.
|
||||
@@ -405,28 +406,71 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
|
||||
}
|
||||
r.parametersIterator = parametersIterator
|
||||
|
||||
// parse android/ios/harmony config
|
||||
for _, device := range parsedConfig.Android {
|
||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
||||
// init android devices
|
||||
for _, androidDevice := range parsedConfig.Android {
|
||||
err := r.parseDeviceConfig(androidDevice, parsedConfig.Variables)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.InvalidCaseError,
|
||||
fmt.Sprintf("parse android config failed: %v", err))
|
||||
}
|
||||
|
||||
device, err := uixt.NewAndroidDevice(
|
||||
uixt.GetAndroidDeviceOptions(androidDevice)...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init android device failed")
|
||||
}
|
||||
if err := device.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := device.NewDriver(uixt.WithDriverPlugin(r.parser.plugin))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init android driver failed")
|
||||
}
|
||||
uiClients[device.SerialNumber] = client
|
||||
}
|
||||
for _, device := range parsedConfig.IOS {
|
||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
||||
// init iOS devices
|
||||
for _, iosDevice := range parsedConfig.IOS {
|
||||
err := r.parseDeviceConfig(iosDevice, parsedConfig.Variables)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.InvalidCaseError,
|
||||
fmt.Sprintf("parse ios config failed: %v", err))
|
||||
}
|
||||
device, err := uixt.NewIOSDevice(
|
||||
uixt.GetIOSDeviceOptions(iosDevice)...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init ios device failed")
|
||||
}
|
||||
if err := device.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := device.NewDriver(uixt.WithDriverPlugin(r.parser.plugin))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init ios driver failed")
|
||||
}
|
||||
uiClients[device.UDID] = client
|
||||
}
|
||||
for _, device := range parsedConfig.Harmony {
|
||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
||||
// init harmony devices
|
||||
for _, harmonyDevice := range parsedConfig.Harmony {
|
||||
err := r.parseDeviceConfig(harmonyDevice, parsedConfig.Variables)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.InvalidCaseError,
|
||||
fmt.Sprintf("parse harmony config failed: %v", err))
|
||||
}
|
||||
device, err := uixt.NewHarmonyDevice(
|
||||
uixt.GetHarmonyDeviceOptions(harmonyDevice)...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init harmony device failed")
|
||||
}
|
||||
if err := device.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := device.NewDriver(uixt.WithDriverPlugin(r.parser.plugin))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "init harmony driver failed")
|
||||
}
|
||||
uiClients[device.ConnectKey] = client
|
||||
}
|
||||
|
||||
return parsedConfig, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ import (
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||
)
|
||||
|
||||
var uiClients map[string]*uixt.DriverExt // UI automation clients for iOS and Android, key is udid/serial
|
||||
var uiClients = make(map[string]*uixt.DriverExt) // UI automation clients for iOS and Android, key is udid/serial
|
||||
|
||||
func initUIClient(serial, osType string) (client *uixt.DriverExt, err error) {
|
||||
if uiClients == nil {
|
||||
uiClients = make(map[string]*uixt.DriverExt)
|
||||
}
|
||||
|
||||
// avoid duplicate init
|
||||
// get the first device
|
||||
if serial == "" && len(uiClients) > 0 {
|
||||
for _, v := range uiClients {
|
||||
return v, nil
|
||||
@@ -44,6 +44,10 @@ func initUIClient(serial, osType string) (client *uixt.DriverExt, err error) {
|
||||
return nil, errors.Wrapf(err, "init %s device failed", osType)
|
||||
}
|
||||
|
||||
if err := device.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client, err = device.NewDriver()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -595,26 +599,14 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
// ios step
|
||||
osType = "ios"
|
||||
mobileStep = step.IOS
|
||||
iosDevices := s.caseRunner.Config.IOS
|
||||
if mobileStep.Serial == "" && len(iosDevices) > 0 {
|
||||
mobileStep.Serial = iosDevices[0].UDID
|
||||
}
|
||||
} else if step.Harmony != nil {
|
||||
// harmony step
|
||||
osType = "harmony"
|
||||
mobileStep = step.Harmony
|
||||
harmonyDevices := s.caseRunner.Config.Harmony
|
||||
if mobileStep.Serial == "" && len(harmonyDevices) > 0 {
|
||||
mobileStep.Serial = harmonyDevices[0].ConnectKey
|
||||
}
|
||||
} else {
|
||||
// android step
|
||||
osType = "android"
|
||||
mobileStep = step.Android
|
||||
androidDevices := s.caseRunner.Config.Android
|
||||
if mobileStep.Serial == "" && len(androidDevices) > 0 {
|
||||
mobileStep.Serial = androidDevices[0].SerialNumber
|
||||
}
|
||||
}
|
||||
|
||||
// report GA event
|
||||
|
||||
Reference in New Issue
Block a user