Merge pull request #1678 from httprunner/parse-validator-expect

feat: support parsing expect value of ui validator
This commit is contained in:
debugtalk
2023-08-25 12:54:22 +08:00
committed by GitHub
3 changed files with 23 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ UI related:
- fix: add compatible support for indicating options separately at the `MobileAction` level
- fix: use Override size if existed, otherwise use Physical size (android devices)
- fix: add default options for `swipe_to_tap_app` action
- refactor: ui validation methods, support parsing expect value
- fix: reuse the same request body during `GetImage` retry
others:

View File

@@ -638,6 +638,23 @@ func (r *SessionRunner) ParseStepVariables(stepVariables map[string]interface{})
return parsedVariables, nil
}
func (r *SessionRunner) ParseStepValidators(iValidators []interface{}, stepVariables map[string]interface{}) ([]interface{}, error) {
var parsedValidators []interface{}
var err error
for _, iValidator := range iValidators {
validator, ok := iValidator.(Validator)
if !ok {
return nil, errors.New("validator type error")
}
validator.Expect, err = r.caseRunner.parser.Parse(validator.Expect, stepVariables)
if err != nil {
return nil, errors.Wrap(err, "failed to parse validator expect")
}
parsedValidators = append(parsedValidators, validator)
}
return parsedValidators, nil
}
// InitWithParameters updates session variables with given parameters.
// this is used for data driven
func (r *SessionRunner) InitWithParameters(parameters map[string]interface{}) {

View File

@@ -656,7 +656,11 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
}
// validate
validateResults, err := validateUI(uiDriver, step.Validators)
stepValidators, err := s.ParseStepValidators(step.Validators, stepVariables)
if err != nil {
return
}
validateResults, err := validateUI(uiDriver, stepValidators)
if err != nil {
if !code.IsErrorPredefined(err) {
err = errors.Wrap(code.MobileUIValidationError, err.Error())