JMeter – Size Assertion
Size Assertion in JMeter is typically used when we want to verify the size of the entire response or a specific portion of the response, such as the header or code. This claim aids in locating the throughput-related problem. A simple instance where size assertion can be added is while a file is being downloaded.
How is ‘Size Assertion’ added?
You can take the actions listed below:
- Choose the ‘Sampler’ element whose response size has to be verified.
- Do right-click on the sampler.
- Place your cursor over ‘Add’.
- Place your pointer over “Assertions”
- Select “Size Assertion”
What are the ‘Size Assertion’ input fields?
There are the following input fields for “Size Statement”:
Name: to specify the name of the assertion.
Leave any comment random.
Apply to: Definition of search parameters.
Main example and subsamples: Use this option if the request is redirected so that the response is the sum of the size of the original and redirected requests and responses, allowing a comparison with the expected response size.
If we only want to confirm the response size of the primary sample, we can use this option.
Subsamples Only – This option should be chosen when the request is redirected and response size comparison is only required for the subsample (redirect) technique.
JMeter variable Name to use: To validate the size of the JMeter variable.
Specify the part of the response to validate the size using the Response Size field for the test option.
Full Response: Includes the size of the response body and header, and the total is compared to the size specified in the “Size to assert” field as the desired size.
Only the response header size is compared to the size specified by the response audience.
Response Code: The specified size assertion is compared to the size of the response code, which is approximately 3 bytes.
Response Message: The size of the response message is compared to the specified size assertion.
Size to be confirmed: The expected response size must be entered in the ‘Size in bytes’ field. The actual response size is then compared to the expected size using the condition entered in the Comparison Types field.
Multiple Comparisons: To compare actual and expected response sizes, JMeter offers every comparison method imaginable, including equal to (=), not equal to (!=), greater than (>), less than (), greater than or equal to ( >=), and less than or equal to (=).
Main guidelines
The size claim is compliant with the scoping policy, so if we add it at the transaction level, it will apply to all samples included in that transaction.
You must specify the expected size in bytes.
The value of the expected size can be parameterized.
In the test plan, you can specify a global size declaration that applies to all samplers.