Over the years I have taught myself a few simple tips & tricks in Jmeter and I thought it might be nice to share them here. Some are simple, some are a bit more complex but I hope all of them will be useful to reuse for anyone. Where possible I will see if I can add an actual JMX file to download for your ease of use.
Tip 1: Crawling URLs
A URL crawler can be used for several things such as:
- verifying all URL’s on the site
- mimicking random browse behaviour and thus generating random load on the server
Setting up a crawler involves a few steps. First off you will need a thread group, as you need it with everything. Within that thread group you place an HTTP Request going to your base-page, usually the homepage of the web application.
Then the fun part starts, now we add a While Controller with a simple condition added to it:
LAST - exit loop when last sample in loop fails. If the last sample just before the loop failed, don't enter loop.
You can also make it with an empty Condition, however I prefer using this one so that if your script didn’t already break on an error, it will absolutely break on an error before hitting the loop.
Within the While Controller we now place another HTTP Request, where the path is set to
Underneath the HTTP Request now add an HTML Link Parser.
You now should have a structure similar to this:
TestPlan |__ Thread Group |__ HTTP Request |__ While Controller |__ HTTP Request |__ HTML Link Parser
The Link Parser does nothing other than extract links from the received HTML.
Next up is adding an If Controller to ensure the link we just grabbed indeed is working and if not, send the crawler back to the base page (e.g. the home page you defined in the first HTTP Request).
As a child node underneath this If Controller you now need to hang yet another HTTP Request, which sends the user back to your initial homepage. When filling in URL’s etc. please keep in mind that you should just keep life simple and make URL’s either read from a CSV file or simply add them as a global variable in the Test Plan.
The entire plan now should look like this:
Please be careful in using this script, this might lead to an unintended Denial Of Service attack if ran uncontrolled and with high load!