Merge pull request #1113 from lihuacai168/master

feat: support variable and function in response extract expression
This commit is contained in:
debugtalk
2022-03-22 17:17:23 +08:00
committed by GitHub
3 changed files with 27 additions and 3 deletions

View File

@@ -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

View File

@@ -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