Load Testing using JMeter [Regular Expression, CLI execution & HTML reports]

VinayakTitti-Technical QA
5 min readMar 11, 2020

--

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):

  1. To check the load test on all links. Ex:
  2. To find broken links from the application.
  3. To extract information to a variable and use later. ex: CSRF/XSRF
  4. 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

  1. 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:

https://artoftesting.com/jmeter-result-analysis

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

VinayakTitti-Technical QA
VinayakTitti-Technical QA

Written by VinayakTitti-Technical QA

Extensive international experience having worked in UK and Asia (India & Malaysia) in a wide variety of tools- Selenium, Appium, Protractor & Cypress.

No responses yet

Write a response