mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-15 20:38:44 +08:00
Merge pull request #1113 from lihuacai168/master
feat: support variable and function in response extract expression
This commit is contained in:
@@ -167,12 +167,21 @@ class ResponseObject(object):
|
||||
|
||||
return check_value
|
||||
|
||||
def extract(self, extractors: Dict[Text, Text]) -> Dict[Text, Any]:
|
||||
def extract(self,
|
||||
extractors: Dict[Text, Text],
|
||||
variables_mapping: VariablesMapping = None,
|
||||
functions_mapping: FunctionsMapping = None,
|
||||
) -> Dict[Text, Any]:
|
||||
if not extractors:
|
||||
return {}
|
||||
|
||||
extract_mapping = {}
|
||||
for key, field in extractors.items():
|
||||
if '$' in field:
|
||||
# field contains variable or function
|
||||
field = parse_data(
|
||||
field, variables_mapping, functions_mapping
|
||||
)
|
||||
field_value = self._search_jmespath(field)
|
||||
extract_mapping[key] = field_value
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ class HttpRunner(object):
|
||||
|
||||
# extract
|
||||
extractors = step.extract
|
||||
extract_mapping = resp_obj.extract(extractors)
|
||||
extract_mapping = resp_obj.extract(extractors, step.variables, self.__project_meta.functions)
|
||||
step_data.export_vars = extract_mapping
|
||||
|
||||
variables_mapping = step.variables
|
||||
|
||||
Reference in New Issue
Block a user