Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter: In which scenario I can use "Main sample" or "Sub Sample" or both for Text Response in Response Assertion

I would like to know in which scenario I can use "Main sample" or "Sub Sample" or both for Text Response in Response Assertion.

I googled it but have not yet receive satisfactory answers yet.

Help appreciated.

like image 401
Anonymous Avatar asked Jan 29 '15 12:01

Anonymous


People also ask

What are main samples and sub samples in JMeter?

Main sample only is the most common setting, this way the assertion will be applied only to the response to samplers not to sub samples. Sub samples in case of HTTP requests mainly refers to embedded resources. JMeter variable is useful to assert if a post processor contains the right value.

What is main sample and sub sample?

A sample is a portion of the population. A subsample is a portion of the sample. Copy link CC BY-SA 4.0.

What is main sample in JMeter?

Samplers in JMeter allows JMeter to send different types of requests to a server. Samplers are the actual requests, JMeter sends to the web server under test. Each sampler (except Test Action) generates one or more sample results. The sample results have various attributes (success/fail, elapsed time, data size etc.)


2 Answers

According to JMeter Help,

This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.

Main sample only - assertion only applies to the main sample
Sub-samples only - assertion only applies to the sub-samples
Main sample and sub-samples - assertion applies to both.
JMeter Variable - assertion is to be applied to the contents of the named variable

In most cases, only main sampler has all required response data but nowadays because of ajax, jquery framework single request can spawn multiple sub-requests internally and each has its response data.

Thus In most cases searching in main samplers response is enough

enter image description here

enter image description here

But if you know or you found out that request has multiple sub-requests and response can be anywhere then you can choose "main samples and sub samples" radio button so that you wont miss sub requests.

enter image description here

like image 76
Nachiket Kate Avatar answered Oct 11 '22 06:10

Nachiket Kate


When you select 'Retrieve All Embedded Resources' the HTTP request you have it might generate sub samplers (for img, css, js files etc). You select the option in the Response Assertion accordingly based on the samplers where you expect your 'expected text' to be present.

  • Main Samples and Sub Samples: JMeter will check for the 'expected text' to be present in both main and sub samples and if any of the samplers do no have the text, it fails.
  • Main Sample Only: - JMeter will check for the 'expected text' only in the main sample. It fails if it is not found.
  • Sub Sample only: - JMeter will check for the 'expected text' only in all the sub samples. All the sub samplers are expected to have the text. Otherwise it fails.
like image 38
vins Avatar answered Oct 11 '22 07:10

vins