mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-01 05:49:40 +08:00
fix: miss device serial for mobile step
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2409251315
|
||||
v5.0.0-beta-2409251646
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"reflect"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
@@ -404,9 +405,62 @@ 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)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.InvalidCaseError,
|
||||
fmt.Sprintf("parse android config failed: %v", err))
|
||||
}
|
||||
}
|
||||
for _, device := range parsedConfig.IOS {
|
||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.InvalidCaseError,
|
||||
fmt.Sprintf("parse ios config failed: %v", err))
|
||||
}
|
||||
}
|
||||
for _, device := range parsedConfig.Harmony {
|
||||
err := r.parseDeviceConfig(device, parsedConfig.Variables)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.InvalidCaseError,
|
||||
fmt.Sprintf("parse harmony config failed: %v", err))
|
||||
}
|
||||
}
|
||||
return parsedConfig, nil
|
||||
}
|
||||
|
||||
func (r *CaseRunner) parseDeviceConfig(
|
||||
device interface{}, configVariables map[string]interface{}) error {
|
||||
deviceValue := reflect.ValueOf(device).Elem()
|
||||
deviceType := deviceValue.Type()
|
||||
for i := 0; i < deviceType.NumField(); i++ {
|
||||
field := deviceType.Field(i)
|
||||
fieldValue := deviceValue.Field(i)
|
||||
if fieldValue.Kind() != reflect.String {
|
||||
continue
|
||||
}
|
||||
|
||||
parsedValue, err := r.parser.ParseString(
|
||||
fieldValue.String(), configVariables)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf(
|
||||
"parse config device variable %s failed", field.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
parsedValueReflect := reflect.ValueOf(parsedValue)
|
||||
if parsedValueReflect.Type().ConvertibleTo(fieldValue.Type()) {
|
||||
convertedValue := parsedValueReflect.Convert(fieldValue.Type())
|
||||
fieldValue.Set(convertedValue)
|
||||
} else {
|
||||
log.Error().Msgf("update config device variable %s failed", field.Name)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// each boomer task initiates a new session
|
||||
// in order to avoid data racing
|
||||
func (r *CaseRunner) NewSession() *SessionRunner {
|
||||
|
||||
@@ -73,6 +73,8 @@ type StepMobile struct {
|
||||
func (s *StepMobile) obj() *MobileUI {
|
||||
if s.step.IOS != nil {
|
||||
return s.step.IOS
|
||||
} else if s.step.Harmony != nil {
|
||||
return s.step.Harmony
|
||||
}
|
||||
return s.step.Android
|
||||
}
|
||||
@@ -593,13 +595,26 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
|
||||
// ios step
|
||||
osType = "ios"
|
||||
mobileStep = step.IOS
|
||||
} else if step.Android != nil {
|
||||
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
|
||||
} else {
|
||||
osType = "harmony"
|
||||
mobileStep = step.Harmony
|
||||
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