How does JMeter simulate a real browser?

Just to have a knowledge of how to record the script for an application and execute the test; should not be enough for a performance tester. As described in the previous article, performance testing should be realistic rather than just a simple test. To implement this concept, a performance tester should know how does a testing tool work to make a real situation? When we talk about JMeter then definitely you should know ‘How does JMeter simulate real browser? to implement a realistic scenario. To understand this functioning of JMeter, you need to first understand what are the browser and request elements of JMeter:

  1. Browser
    1. Cache
    2. Cookie
  2. Request
    1. Request Header

What are they?

  1. Cache: Web browsers have Cache feature to reduce the traffic over the Internet and also reduce the usage of network bandwidth that makes communication between clients and servers faster.
  2. Cookie: Cookies are text files. Client system stores cookies for various information tracking purposes. Once a cookie is added to the response from the servlet and it is stored in the cache of the browser, then it is sent along with the next request. Thus, the server recognizes the user as the old user.
  3. Request Header: The request-header fields allow the client to pass additional information about the request and about the client itself, to the server. These fields act as request modifiers. Here is a list of some important request-header fields to use in the script as per the requirement:
    1. Accept-Encoding
    2. Accept-Language
    3. Authorization
    4. Proxy-Authorization
    5. Range
    6. Referer
    7. User-Agent, etc.

How does Apache JMeter simulate these features? 

To simulate the above features, JMeter has 3 config elements which are:

1. HTTP Cache ManagerIt simulates Cache feature of the browser. As you know that JMeter is not a browser, but JMeter has HTTP Cache Manager to mimic the browser behaviour and make your tests more realistic in terms of caching. “HTTP Cache Manager” is used to simulate the browser caching behaviour in JMeter by adding caching functionality to HTTP requests within its scope.

2. HTTP Cookie Manager: Cookies are handled in JMeter using “HTTP Cookie Manager”. Using this config element you can simulate browser activities. HTTP Cookies Manager does work in two ways:

  • Stores and sends: If an HTTP request and the response contains a cookie then Cookie Manager automatically stores that cookie and will use it for all future requests to that particular web site. In this way, it simulates the real browser. Each JMeter thread has its own “cookie storage area”. Also, one more good thing in JMeter is that you can store received Cookies in a JMeter thread variable. To save cookies as variables, define the property “CookieManager.save.cookies=true”. Just for a good practice you can provide cookies names are prefixed with “COOKIE_” before they are stored (this avoids accidental corruption of local variables). To revert to the original behaviour, define the property “CookieManager.name.prefix= ” (one or more spaces). If enabled, the value of a cookie with the name TEST can be referred to as ${COOKIE_TEST}.
  • Add Manually: You can manually add a cookie to the Cookie Manager. However, if you do this, the cookie will be shared by all JMeter threads.

3. HTTP Header Manager: JMeter provides HTTP header manager element to attach information like Accept-Language, Accept-Encoding, User-Agent, Referer etc. along with the request. It is not necessary to have a separate HTTP header manager with each request unless request needs a unique header. You can have one HTTP header manager at Thread level or none (as per request type).

Conclusion

Above mentioned 3 JMeter elements help to simulate a real web browser in the virtual world. You can get more details on individual JMeter elements by clicking on elements name.



Leave a Reply

Your email address will not be published. Required fields are marked *