feat: support parsing expect value of ui validator

This commit is contained in:
buyuxiang
2023-08-25 11:55:31 +08:00
parent 244bf039e6
commit 6bcde3627b
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: add compatible support for indicating options separately at the `MobileAction` level
- fix: use Override size if existed, otherwise use Physical size (android devices) - fix: use Override size if existed, otherwise use Physical size (android devices)
- fix: add default options for `swipe_to_tap_app` action - 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 - fix: reuse the same request body during `GetImage` retry
others: others:

View File

@@ -638,6 +638,23 @@ func (r *SessionRunner) ParseStepVariables(stepVariables map[string]interface{})
return parsedVariables, nil 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. // InitWithParameters updates session variables with given parameters.
// this is used for data driven // this is used for data driven
func (r *SessionRunner) InitWithParameters(parameters map[string]interface{}) { func (r *SessionRunner) InitWithParameters(parameters map[string]interface{}) {

View File

@@ -656,7 +656,11 @@ func runStepMobileUI(s *SessionRunner, step *TStep) (stepResult *StepResult, err
} }
// validate // 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 err != nil {
if !code.IsErrorPredefined(err) { if !code.IsErrorPredefined(err) {
err = errors.Wrap(code.MobileUIValidationError, err.Error()) err = errors.Wrap(code.MobileUIValidationError, err.Error())