Load Testing using JMeter [Regular Expression, CLI execution & HTML reports]
In this article, let’s see how to create a JMeter test plan using Regular Expression Extractor to extract all links and validate response, command-line execution to reduce resource usage & generate detailed HTML reports [Best Practises].
1. Regular Expression Extractor:
When comes to load test a web application, sometimes we face a requirement to extract all links and validate the response. Regular Expression Extractor is a useful feature comes with JMeter to overcome it.
Usage of Regular Expression Extractor (REE):
- To check the load test on all links. Ex:
- To find broken links from the application.
- To extract information to a variable and use later. ex: CSRF/XSRF
- etc.,
Note: In this article, Regular Expression Extractor has been used in the short form as REE.
Test Plan:
To create a basic test plan please refer to below article https://medium.com/@Alibaba_Cloud/performance-testing-using-apache-jmeter-d136c6011b0e
For the demo purpose, I have used the Mercury Tours site http://newtours.demoaut.com/mercurywelcome.php

- Add Regular Expression Extractor:
After setup the basic test plan from the above article, add REE by following below steps:
Steps:
a. Go to Thread Group
b. Add HTTP Request sampler
c. Add REE from Post Processors

After add REE, add below config to it:
Name of created variable = inputVarRegular Expression: <a href="([^"]+)"Template: $1$Match No: -1Default value: fout
Template: choose the group you would like to extract from the regular expression. ‘$1$’ will extract group 1, ‘$2$’ will extract group 2, and so on. $0$ will extract the entire expression. For example, if you have the word “economics” in your response and you search for the regular expression “(ec)(onomics)” and apply template $2$$1$, then in the output variable you will receive “onomicsec”. If you apply template $0$, then in the output variable you will receive “economics”.
Match: If there is several character sequences, allows specifying, which variant exactly should be used. Important note. If you set “Apply to” to “Main sample and sub-samples” and specify “Match ¹” = 3, than JMeter will select matching sequence from the 2nd sub-sample because 1st will be main sample. If zero is specified, JMeter will choose a match at random. If you specify negative number, e.g. “-2”
2. Add ForEach Controller:
After setup the regular expression config, add ForEach controller by following below steps:
Steps:
a. Go to Thread Group
b. Add ForEach Controller
c. Add below config



Execution:
After complete the above setup, execute the test plan and validate the results in View Results Tree
listener. All the links from Mercury tours site http://newtours.demoaut.com / was extracted and load tested and any broken links will be captured as the screenshot below.

2. CLI Execution:
One of the JMeter best practices is to execute all load tests using command line for better results and to minimize the CPU usage.
Note: Don’t use GUI mode for load testing !, only for Test creation and Test debugging.
For load testing, use CLI Mode always:
ex: jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
Steps:
a. Change directory to JMeter bin folder in cmd-line/Terminal
cd /Users/xxxxxxxxx/apache-jmeter-5.2.1/bin
b. Execute cmd: enter the location path of testplan.jmx file
For mac:
./jmeter.sh -n -t /Users/testplan.jmx -l log.jtl
For Windows:
jmeter -n -t /Users/testplan.jmx -l log.jtl
c. After execution completed, to generate reports execute —
For mac:
./jmeter.sh -g /Users/xxxxxx/apache-jmeter-4.0/bin/log.jtl -o /Users/xxxxxx/jmeter/reports
For Windows:
jmeter -g /Users/xxxxxx/apache-jmeter-4.0/bin/log.jtl -o /Users/xxxxxx/jmeter/reports

HTML reports will be generated in the reports folder. If reports already exist in reports folder then need to delete and execute cmd.
Abbreviation:
- n: It specifies jmter to run in non-gui mode
-t: Name of JMX file that contains the test plan
-l: Name of JTL (jmeter text logs) file to log results
-g: Name of jmeter run log file
-o: Output file
3. Sample HTML Reports:
HTML reports will be generated to the reports folder as per given reports folder location:
jmeter -g /Users/xxxxxx/apache-jmeter-4.0/bin/log.jtl -o /Users/xxxxxx/jmeter/reports




Summary:
By using Regular Expression Extractor we can extract all links of dynamic websites such as blogs, news portals, social networks & e-commerce to validate the load testing response. And Command-line execution is one of the JMeter best practices to execute load testing on the terminal to reduce resource usage & generate reports.
Happy learning!!!
Reference links: