mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
fix: extract variables
This commit is contained in:
@@ -87,10 +87,11 @@ func (v *ResponseObject) Extract(extractors map[string]string) map[string]interf
|
|||||||
|
|
||||||
extractMapping := make(map[string]interface{})
|
extractMapping := make(map[string]interface{})
|
||||||
for key, value := range extractors {
|
for key, value := range extractors {
|
||||||
extractMapping[key] = v.searchJmespath(value)
|
extractedValue := v.searchJmespath(value)
|
||||||
|
log.Printf("extract %s => %v", value, extractedValue)
|
||||||
|
extractMapping[key] = extractedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[Extract] extractMapping: %v", extractMapping)
|
|
||||||
return extractMapping
|
return extractMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,8 +140,11 @@ func (r *Runner) runStepRequest(step *TStep) (stepData *StepData, err error) {
|
|||||||
extractMapping := respObj.Extract(extractors)
|
extractMapping := respObj.Extract(extractors)
|
||||||
stepData.ExportVars = extractMapping
|
stepData.ExportVars = extractMapping
|
||||||
|
|
||||||
|
// override step variables with extracted variables
|
||||||
|
stepVariables := mergeVariables(step.Variables, extractMapping)
|
||||||
|
|
||||||
// validate response
|
// validate response
|
||||||
err = respObj.Validate(step.Validators, step.Variables)
|
err = respObj.Validate(step.Validators, stepVariables)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
1
step.go
1
step.go
@@ -170,6 +170,7 @@ func (s *requestWithOptionalArgs) Validate() *stepRequestValidation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction {
|
func (s *requestWithOptionalArgs) Extract() *stepRequestExtraction {
|
||||||
|
s.step.Extract = make(map[string]string)
|
||||||
return &stepRequestExtraction{
|
return &stepRequestExtraction{
|
||||||
step: s.step,
|
step: s.step,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user