Wednesday, 29 January 2020

HTTP Request Sampler

HTTP request sampler is most commonly used to send various type of request to server. You can add this request under Thread Group. Now let us see how we can configure the request.



1. Server Name or IP - First thing we need to specify here is the website url to which we want to send the request.
2. Method - We need to specify the method fo request such as GET,POST,DELETE etc
3. Protocol is http/https and port number if applicable. We need to also specify exact url path.
4. If it is required to send payload along with request then there are 3 options to do so such as Parameters, json body data and fole upload.
5.We can also specify how we want to deal with redirects.

In case of advance config we can configure elements given below -



1. Implementation - HTTPClient4 /Java / as per HHT Request Default.
2. Timeout - Wait for connection or response time outs.
3.If we want to store embedded resources we can check "Retrieve All Embedded Resources".
4. If we want to connect to proxy server for sending the request then we can configure that in Advanced section.

Jmeter Configuration Elements

In this post we will learn about few of the most commonly used configuration elements.

HTTP Request Defaults -

For each HTTP request samplers which we mention in the test script there are chances that some fields like protocol and server IP is common for all the requests. In this case instead of mentioning the same in all HTTP Requests we can define this in HTTP Request Default.




HTTP Header Manager -

This element lets you add or override HTTP Request header. The headers specified here will be added for all samplers under its scope.Add the header as given below and this header is applicable for all the samplers under its scope.




 HTTP Cache Manager -

Web driver uses caching to reduce traffic over internet by storing the resources for subsequent runs.To mimic this behavior we can use HTTP cache manager .First time when we hit the url jmeter script store the resource file. The file contains last modified date and time information on the basis of which  cache manager checks weather the resources are updated or not and if the resources are updated then it downloads the updated resource file.
      If Clear cache option is checked then after each iteration cache will be cleared. By default 5000 elements are stored in cache. If Use Cache control option is checked  and if the request is GET request and timestamp is in future, then the sampler returns response from the cache. 

 


HTTP Cookie Manager -

Many web applications store some information as cookie and this jmeter element is used to store the cookies and use the information later during test runs. Each jmeter thread contains cookie storage space, if we are testing application where cookie is sued for storing information for perticular sessions then each jmeter thread will have its own session.
        Cookies can be added manually as shown in below figure which are called as user defined cookies. If clear cookies on each iteration option is checked then for each iteration cookies will be removed.