How to render randomly the web links available on a web page in Apache JMeter?
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 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 a broken URL.
To overcome this situation, JMeter provides an “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
Let’s try to understand with an example. Consider, there is a scenario where you need to render the pages of a website randomly which 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 the Transaction Controller
- Provide the URL and other inputs in HTTP Request sampler
- Add another HTTP Request sampler (named 02 PerfMatrix – Random Link 1) under Thread Group
- Provide ‘.*’ as a value in the “Path” attribute of the HTTP Request sampler
- Add HTML Link Parser pre-processor under this HTTP Request sampler
- Similarly, add 4 more HTTP Request samplers and HTML Link Parser pre-processors under those samplers
- Execute the test and see the result in the View Result Tree listener
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.
You may be interested:
- Performance Testing Tutorial
- Performance Engineering Tutorial
- Micro Focus LoadRunner Tutorial
- NeoLoad Tutorial