1. Description
An HTTP request is sent, how to judge whether the executed task is successful? By checking the server response data, whether the expected data is returned, if so, the task is judged to be successful, otherwise the task fails.
Role: determine whether the request is successful
2. Steps
Step 1: Add "Response Assertion"
HTTP Request (right mouse button) ----> Add ----> Assert ----> Response Assertion
(1) Apply to (application scope) : Most of the check " main sample only " is enough, because we have one request, and there is only one request in essence. But when we send a request, we can trigger multiple server requests, similar to ajax , so there are main sample and sub-sample . In addition, for requests with redirection and "Follow redirection" is checked, then these two requests are sub- samples, and the redirected request (the second request) is main-sample.
(2) Response fields to be tested :
Response text : The server response text, generally normal http response, check this.
Response code: http response code, such as 101, 200, 302, 404, 501, etc. But when we want to verify http response codes such as 404, 501, etc., we need to check "ignore status". Because when the http response code is 400,500, jmeter defaults to this request and fails.
Response information: The response information corresponding to the http response code, for example: OK, Found
Response Headers: response headers in http
Request Headers: request headers in http
url sample: It is an assertion on the url of the sample. If the request is not redirected (302), then this is the request url. If there is a redirect (and follow the redirect), then the url contains the request url and the redirect url
Document(Text) : All Apache Tika supports server responses, including text responses, as well as PDF, Office, Audio, Video formats . So for normal http requests, don't choose this.
Ignore status : ignore status
(3) Pattern matching rules : include (if there is no information in the "pattern to be tested" in the returned information, the request fails; when the returned information contains the information in the "pattern to be tested", the request is successful )
(4) Mode to be tested : that is, the data value that needs to be verified.
Step 2 : Assert the result
HTTP request (right mouse button)---->Add---->Listener---->Assertion result
Assertion verification is performed on the response of the server , no configuration is required, and the results can be viewed after running