Render random links in JMeter

Problem:

How to render randomly the web links available on a web page in Apache JMeter?

Explanation:

It is a common scenario in performance testing to browse the links or pages randomly available on a website. To simulate this scenario a performance tester needs to either hardcode the page URLs and add the logic to pick the links randomly or pass the URLs using a parameter. Both the cases require additional work of fetching all the available URLs/links on a webpage.

Another issue with the above approaches is the failure of the script in case of broken URL.

Solution:

To overcome this situation, JMeter provides “HTML Link Parser” PreProcessor which extracts all the HTML links available on the webpage and passes them randomly in successive requests. This pre-processor saves the extra efforts of:

  • Fetching the available URLs
  • Listing down the URLs in a file or hardcode them
  • Writing the logic to pass the URL randomly
HTML Link Parser in JMeter
Figure 01: HTML Link Parser

Example:

Let’s try to understand with an example. Consider, there is a scenario where you need to render the pages of a website randomly that means each virtual user will have to visit 5 random pages. Follow the below steps to create such a scenario in JMeter:

  • Open JMeter
  • Add a Thread Group under Test Plan
  • Then, add a View Results Tree listener under Thread Group
  • Add a Transaction Controller (named Webtour Pages) under Thread Group
  • Add an HTTP Request sampler (named 01 Webtour Home Page) under Transaction Controller
  • Provide the URL and other inputs in HTTP Request sampler
HTML Link Parser
Figure 02: HTML Link Parser
  • Add another HTTP Request sampler (named 02 PerfMatrix – Random Link 1) under Thread Group
  • Provide ‘.*’ as a value in “Path” attribute of HTTP Request sampler
HTML Link Parser
Figure 03: HTML Link Parser
  • Add HTML Link Parser pre-processor under this HTTP Request sampler 
HTML Link Parser
Figure 04: HTML Link Parser
  • Similarly, add 4 more HTTP Request samplers and HTML Link Parser pre-processors under those samplers
HTML Link Parser
Figure 05: HTML Link Parser
  • Execute the test and see the result in the View Result Tree listener
HTML Link Parser
Figure 06: HTML Link Parser

Note: JMeter passes the random links to the subsequent request where HTML Link Parser is added. But it is not necessary that these links are unique.

Video


Leave a Reply

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