In JMeter, Size Assertion is mainly used when we want to validate the size of the full response or some part of the response like header, code etc. This assertion helps to identify the throughput related issue. A simple scenario where you can add size assertion is a file downloading scenario.
How to add ‘Size Assertion’?
You can follow the below steps:
- Select the ‘Sampler’ element whose response size needs to be validated.
- Right-click on the sampler
- Hover the cursor on ‘Add’
- Hover the cursor on ‘Assertions‘
- Click ‘Size Assertion’
What are the input fields of ‘Size Assertion’?
‘Size Assertion’ has the following input fields:
- Name: To provide the name of the assertion.
- Comments: To provide arbitrary comments (if any)
- Apply to: To define the search scope.
- Main sample and sub-samples: In case, the request is redirected then use this option, so that the response will be the sum of both main and re-directed request-response size and can be compared with the expected response size.
- Main sample only: This option can be selected when we want to validate the response size of the main sample only.
- Sub-samples only: When the request is re-directed and the response size comparison is needed only for the sub-sample (re-directed) method then this option needs to be selected.
- JMeter Variable Name to use: To validate the size of JMeter variable.
- Response Size Field to Test: This option is used to specify the part of the response whose size needs to be validated.
- Full Response: It includes both response header as well as response body size and the sum is compared with the expected size figure given in ‘Size to Assert’ field.
- Response Hearders: Only the size of the response header is compared with the given size.
- Response Code: The size of the response code (around 3 bytes) is compared with the given size assertion.
- Response Message: The given size assertion is compared with response message size.
- Size to Assert: The expected size of the response needs to be provided in the ‘Size in bytes’ field which is compared with the actual response size using given condition in ‘Types of Comparison’ field.
- Types of Comparison: JMeter provides all the possible comparison method like equal to (=), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=) and less than or equal to (<=) to compare the actual and expected response size.
Some Key Rules:
- Size assertion follows scope policy means if we add size assertion at transaction level then the assertion is applicable to all the samplers under the same transaction.
- Expected size must be given in bytes.
- Expected size value can be parametrized.
- You can define Global Size Assertion under the test plan which will be applicable to all the samplers.