jmeterjmeter-plugins

Browser Cache simulation using JMeter


We have browser cache implemented in application where in when user logins to application and clicks a link, at the first API1 call the response is cached in browser at local storage. And on next API1 calls it fetches from Browser Cache instead of hitting server. Again when user closes the browser and launch new browser or session is expired the same process is repeated. First API1 call cached response at browser local storage and next API1 calls fetches from Browser Cache.

I have 10 concurrent users hitting this API for a duration of 1 hour. Session expires every 30 mins. How can i simulate above behavior's using JMeter. Appreciate if anyone can help on this.


Solution

  • Local Storage != browser cache, browser cache can be simulated using HTTP Cache Manager, for simulating operations which assume usage of the local storage you will need to have a real browser.

    As per Window.localStorage documentation:

    The localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.

    and the Document is:

    The Document interface represents any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree.

    As per JMeter project main page:

    JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).

    So the only way to implement your scenario is using real browser, for example you can consider using WebDriver Sampler which provides JMeter integration with Selenium browser automation framework, this way you will have Local Storage and ability to clear it when needed.

    WebDriver Sampler can be installed using JMeter Plugins Manager