mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +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) {
|
func NewHarmonyDevice(options ...HarmonyDeviceOption) (device *HarmonyDevice, err error) {
|
||||||
device = &HarmonyDevice{}
|
device = &HarmonyDevice{}
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/code"
|
"github.com/httprunner/httprunner/v4/hrp/code"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run starts to run testcase with default configs.
|
// Run starts to run testcase with default configs.
|
||||||
@@ -405,28 +406,71 @@ func (r *CaseRunner) parseConfig() (parsedConfig *TConfig, err error) {
|
|||||||
}
|
}
|
||||||
r.parametersIterator = parametersIterator
|
r.parametersIterator = parametersIterator
|
||||||
|
|
||||||
// parse android/ios/harmony config
|
// init android devices
|
||||||
for _, device := range parsedConfig.Android {
|
for _, androidDevice := range parsedConfig.Android {
|
||||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
err := r.parseDeviceConfig(androidDevice, parsedConfig.Variables)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(code.InvalidCaseError,
|
return nil, errors.Wrap(code.InvalidCaseError,
|
||||||
fmt.Sprintf("parse android config failed: %v", err))
|
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 {
|
// init iOS devices
|
||||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
for _, iosDevice := range parsedConfig.IOS {
|
||||||
|
err := r.parseDeviceConfig(iosDevice, parsedConfig.Variables)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(code.InvalidCaseError,
|
return nil, errors.Wrap(code.InvalidCaseError,
|
||||||
fmt.Sprintf("parse ios config failed: %v", err))
|
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 {
|
// init harmony devices
|
||||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
for _, harmonyDevice := range parsedConfig.Harmony {
|
||||||
|
err := r.parseDeviceConfig(harmonyDevice, parsedConfig.Variables)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(code.InvalidCaseError,
|
return nil, errors.Wrap(code.InvalidCaseError,
|
||||||
fmt.Sprintf("parse harmony config failed: %v", err))
|
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
|
return parsedConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import (
|
|||||||
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
|
"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) {
|
func initUIClient(serial, osType string) (client *uixt.DriverExt, err error) {
|
||||||
if uiClients == nil {
|
if uiClients == nil {
|
||||||
uiClients = make(map[string]*uixt.DriverExt)
|
uiClients = make(map[string]*uixt.DriverExt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid duplicate init
|
// get the first device
|
||||||
if serial == "" && len(uiClients) > 0 {
|
if serial == "" && len(uiClients) > 0 {
|
||||||
for _, v := range uiClients {
|
for _, v := range uiClients {
|
||||||
return v, nil
|
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)
|
return nil, errors.Wrapf(err, "init %s device failed", osType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := device.Init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client, err = device.NewDriver()
|
client, err = device.NewDriver()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -595,26 +599,14 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
|||||||
// ios step
|
// ios step
|
||||||
osType = "ios"
|
osType = "ios"
|
||||||
mobileStep = step.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 {
|
} else if step.Harmony != nil {
|
||||||
// harmony step
|
// harmony step
|
||||||
osType = "harmony"
|
osType = "harmony"
|
||||||
mobileStep = step.Harmony
|
mobileStep = step.Harmony
|
||||||
harmonyDevices := s.caseRunner.Config.Harmony
|
|
||||||
if mobileStep.Serial == "" && len(harmonyDevices) > 0 {
|
|
||||||
mobileStep.Serial = harmonyDevices[0].ConnectKey
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// android step
|
// android step
|
||||||
osType = "android"
|
osType = "android"
|
||||||
mobileStep = step.Android
|
mobileStep = step.Android
|
||||||
androidDevices := s.caseRunner.Config.Android
|
|
||||||
if mobileStep.Serial == "" && len(androidDevices) > 0 {
|
|
||||||
mobileStep.Serial = androidDevices[0].SerialNumber
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// report GA event
|
// report GA event
|
||||||
|
|||||||
Reference in New Issue
Block a user