mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
rename keyword: extract_binds => extractors
This commit is contained in:
@@ -98,7 +98,7 @@ And here is testset example of typical scenario: get `token` at the beginning, a
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
+4
-4
@@ -56,9 +56,9 @@ class ResponseObject(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise exception.ParseResponseError("failed to extract bind variable in response!")
|
raise exception.ParseResponseError("failed to extract bind variable in response!")
|
||||||
|
|
||||||
def extract_response(self, extract_binds):
|
def extract_response(self, extractors):
|
||||||
""" extract content from requests.Response
|
""" extract content from requests.Response
|
||||||
@param (list) extract_binds
|
@param (list) extractors
|
||||||
[
|
[
|
||||||
{"resp_status_code": "status_code"},
|
{"resp_status_code": "status_code"},
|
||||||
{"resp_headers_content_type": "headers.content-type"},
|
{"resp_headers_content_type": "headers.content-type"},
|
||||||
@@ -68,11 +68,11 @@ class ResponseObject(object):
|
|||||||
@return (OrderDict) variable binds ordered dict
|
@return (OrderDict) variable binds ordered dict
|
||||||
"""
|
"""
|
||||||
extracted_variables_mapping = OrderedDict()
|
extracted_variables_mapping = OrderedDict()
|
||||||
extract_binds_order_dict = utils.convert_to_order_dict(extract_binds)
|
extract_binds_order_dict = utils.convert_to_order_dict(extractors)
|
||||||
|
|
||||||
for key, field in extract_binds_order_dict.items():
|
for key, field in extract_binds_order_dict.items():
|
||||||
if not isinstance(field, utils.string_type):
|
if not isinstance(field, utils.string_type):
|
||||||
raise exception.ParamsError("invalid extract_binds in testcase extract_binds!")
|
raise exception.ParamsError("invalid extractors in testcase!")
|
||||||
|
|
||||||
extracted_variables_mapping[key] = self.extract_field(field)
|
extracted_variables_mapping[key] = self.extract_field(field)
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -84,7 +84,7 @@ class Runner(object):
|
|||||||
},
|
},
|
||||||
"body": '{"name": "user", "password": "123456"}'
|
"body": '{"name": "user", "password": "123456"}'
|
||||||
},
|
},
|
||||||
"extract_binds": [], # optional
|
"extractors": [], # optional
|
||||||
"validators": [], # optional
|
"validators": [], # optional
|
||||||
"setup": [], # optional
|
"setup": [], # optional
|
||||||
"teardown": [] # optional
|
"teardown": [] # optional
|
||||||
@@ -100,7 +100,9 @@ class Runner(object):
|
|||||||
raise exception.ParamsError("URL or METHOD missed!")
|
raise exception.ParamsError("URL or METHOD missed!")
|
||||||
|
|
||||||
run_times = int(testcase.get("times", 1))
|
run_times = int(testcase.get("times", 1))
|
||||||
extract_binds = testcase.get("extract_binds", [])
|
extractors = testcase.get("extractors") \
|
||||||
|
or testcase.get("extractor") \
|
||||||
|
or testcase.get("extract_binds", [])
|
||||||
validators = testcase.get("validators", [])
|
validators = testcase.get("validators", [])
|
||||||
setup_actions = testcase.get("setup", [])
|
setup_actions = testcase.get("setup", [])
|
||||||
teardown_actions = testcase.get("teardown", [])
|
teardown_actions = testcase.get("teardown", [])
|
||||||
@@ -115,7 +117,7 @@ class Runner(object):
|
|||||||
resp = self.http_client_session.request(url=url, method=method, **parsed_request)
|
resp = self.http_client_session.request(url=url, method=method, **parsed_request)
|
||||||
resp_obj = response.ResponseObject(resp)
|
resp_obj = response.ResponseObject(resp)
|
||||||
|
|
||||||
extracted_variables_mapping = resp_obj.extract_response(extract_binds)
|
extracted_variables_mapping = resp_obj.extract_response(extractors)
|
||||||
self.context.bind_variables(extracted_variables_mapping, level="testset")
|
self.context.bind_variables(extracted_variables_mapping, level="testset")
|
||||||
|
|
||||||
resp_obj.validate(validators, self.context.get_testcase_variables_mapping())
|
resp_obj.validate(validators, self.context.get_testcase_variables_mapping())
|
||||||
@@ -142,7 +144,7 @@ class Runner(object):
|
|||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"variable_binds": [], # optional, override
|
"variable_binds": [], # optional, override
|
||||||
"request": {},
|
"request": {},
|
||||||
"extract_binds": {}, # optional
|
"extractors": {}, # optional
|
||||||
"validators": {} # optional
|
"validators": {} # optional
|
||||||
},
|
},
|
||||||
testcase12
|
testcase12
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Suppose we get the following HTTP response.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
In `extract_binds` and `validators`, we can do chain operation to extract data field in HTTP response.
|
In `extractors` and `validators`, we can do chain operation to extract data field in HTTP response.
|
||||||
|
|
||||||
For instance, if we want to get `Content-Type` in response headers, then we can specify `headers.content-type`; if we want to get `first_name` in response content, we can specify `content.person.name.first_name`.
|
For instance, if we want to get `Content-Type` in response headers, then we can specify `headers.content-type`; if we want to get `first_name` in response content, we can specify `content.person.name.first_name`.
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ content.person.cities.1
|
|||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
extract_binds:
|
extractors:
|
||||||
- content_type: headers.content-type
|
- content_type: headers.content-type
|
||||||
- first_name: content.person.name.first_name
|
- first_name: content.person.name.first_name
|
||||||
validators:
|
validators:
|
||||||
|
|||||||
+4
-4
@@ -120,7 +120,7 @@ To fix this problem, we should correlate `token` field in the second API test ca
|
|||||||
app_version: 2.8.6
|
app_version: 2.8.6
|
||||||
json:
|
json:
|
||||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
@@ -142,7 +142,7 @@ To fix this problem, we should correlate `token` field in the second API test ca
|
|||||||
- {"check": "content.success", "comparator": "eq", "expected": true}
|
- {"check": "content.success", "comparator": "eq", "expected": true}
|
||||||
```
|
```
|
||||||
|
|
||||||
As you see, the `token` field is no longer hardcoded, instead it is extracted from the first API request with `extract_binds` mechanism. In the meanwhile, it is assigned to `token` variable, which can be referenced by the subsequent API requests.
|
As you see, the `token` field is no longer hardcoded, instead it is extracted from the first API request with `extractors` mechanism. In the meanwhile, it is assigned to `token` variable, which can be referenced by the subsequent API requests.
|
||||||
|
|
||||||
Now we save the test cases to [`quickstart-demo-rev-1.yml`][quickstart-demo-rev-1] and rerun it, and we will find that both API requests to be successful.
|
Now we save the test cases to [`quickstart-demo-rev-1.yml`][quickstart-demo-rev-1] and rerun it, and we will find that both API requests to be successful.
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ And then, we can revise our demo test case and reference the functions. Suppose
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
@@ -266,7 +266,7 @@ To handle this case, overall `config` block is supported in `ApiTestEngine`. If
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
app_version: 2.8.6
|
app_version: 2.8.6
|
||||||
json:
|
json:
|
||||||
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
sign: 19067cf712265eb5426db8d3664026c1ccea02b9
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extract_binds": [
|
"extractors": [
|
||||||
{
|
{
|
||||||
"token": "content.token"
|
"token": "content.token"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
app_version: '2.8.6'
|
app_version: '2.8.6'
|
||||||
json:
|
json:
|
||||||
sign: f1219719911caae89ccc301679857ebfda115ca2
|
sign: f1219719911caae89ccc301679857ebfda115ca2
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
- test:
|
- test:
|
||||||
name: get token
|
name: get token
|
||||||
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
|
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
|
|
||||||
- test:
|
- test:
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: ${get_sign_lambda($user_agent, $device_sn, $os_platform, $app_version)}
|
sign: ${get_sign_lambda($user_agent, $device_sn, $os_platform, $app_version)}
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
app_version: $app_version
|
app_version: $app_version
|
||||||
json:
|
json:
|
||||||
sign: $sign
|
sign: $sign
|
||||||
extract_binds:
|
extractors:
|
||||||
- token: content.token
|
- token: content.token
|
||||||
validators:
|
validators:
|
||||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extract_binds": [
|
"extractors": [
|
||||||
{"token": "content.token"}
|
{"token": "content.token"}
|
||||||
],
|
],
|
||||||
"validators": [
|
"validators": [
|
||||||
|
|||||||
Reference in New Issue
Block a user