jMeter Notes from Udemy course “Learn jMeter from Scratch”
I
completed this Udemy course to get a different perspective of Jmeter
and evaluate features that I hadn’t used previously.
The course delivered
on my objectives, although the quality was poor.
Pros:
Good
coverage of Jmeter features in a practical QA context
The
instructor responds to Q&A and The examples worked
Good
coverage for ‘new to Jmeter’ users
Cons:
Slow
pace
Lack of editing where the instructor was troubleshooting
and searching menus on the fly. Certain cuteness factor,
though.
Section on REST and SOAP obsolete and should be updated
or removed.
Here are my course notes
Sections 1 and 2 Setup, test websites and recording
Setup on Windows
Prerequsite is
Java SE or some version of java. Run java -version in a command
window to see if it is there. If not download and install the
latest java sdk like jdk-14.0.1_windows-x64_bin.exe
“C:\Program
Files\Java\jdk-14.0.1\bin” should be in your system path
environment variable. Run “path” in a command window to
see it is there.
Download Apache Jmeter
Install the jMeter plugins (referenced below)
Test websites
Don’t
do load testing on public websites. It is not ethical and public
sites will either block repeated access from the same ip address or
be negatively affected.
Here are some sites that have been made
available specifically for test automation development, including
load testing.
https://blazedemo.com/ povided by blazemeter.com a jmeter-based load testing paas /saas company
https://the-internet.herokuapp.com , for example https://the-internet.herokuapp.com/login for login testing
http://www.newtours.demoaut.com/ Testing site provided by Mercury International
Another option
is to set up a local apache webserver app by downloading from
Webtours
. Requires a free account.
Note:
To allow Test Script
Recorder to work with local Webtours, you may have to set these
Firefox properties in
about:config
Network.captive-portal-service.enabled" from
TRUE to FALSE Network.proxy.allow_hijacking_localhost from FALSE to
TRUE
Section 2 walks through recording a simple test in Firefox with jMeter’s built in Test Script Recorder, after setting network proxy from System to Manual. It also demonstrates the Blazemeter Chrome plugin. Note that the Blazemeter plugin recording requires a registration with Blazemeter and is not used in any subsequent sections.
Section 3 Thread Group and Listeners
Thread Group is a container for Controllers and Samplers and represents a number of threads or users simultaneously accessing the target system.
Listeners are
elements that display a visualization of a running and completed
test. Without one or more listeners there is no indication that a
test is running.
The most basic listener is View Results Tree,
which lists the request and response of each sampler and shows an
icon representing a status code of success or error.
Other key listeners
are:
Aggregate Report: Shows statistics for the entire run
Graph Report: Shows several metrics for each sample in a run
Section 4 Plug in Manager and Additional Thread Group options
The Plug In Manager
must be added to jMeter from a link here.
A
useful plug-in example is Custom Thread Groups
Concurrency
Thread Group has More granularity for ramp-up than the base thread
group.
Ultimate Thread Group can assign a staged ramp up time, hold time and ramp down time
Section
5 HTTP Cookie Manager
A Config Element of type Cookie
Manager is added to store a session cookie and pass it to subsequent
sampler requests. Typically the session cookie is required to be
passed in a login request or other sensitive request.
Section
6 Assertions
Assertions can be added to samples or
controllers to validate a response for more than a status
code.
Standard assertions for an HTML response are Response
Assertion, Size Assertion and Duration Assertion.
Other
Assertion types cover JSON, Xpath, Bean shell etc.
Assertions
can be viewed in an Assertion Results Listener
Section 7 Demo local web application
This section
describes downloading an apache webserver app, Webtours,
that runs a local testing website.
An account is required, it
seems to be benign.
To allow Test Script
Recorder to work with local Webtours, you may have to set these
Firefox properties in
about:config
Network.captive-portal-service.enabled" from
TRUE to FALSE Network.proxy.allow_hijacking_localhost from FALSE to
TRUE
Section 8
Controllers
Controllers organize samplers and
permit iterative and conditional execution
Transaction
Controllers group samplers and permit parameters to be applied at a
group level.
Interleave Controllers group transaction
controllers and alternate which controller is run.
Runtime
controller will continuously run it’s contents for a specified
period of time.
Recording Controller will hold all samplers
created by a Test Script Recorder and is the default Target
Controller
Section
9 Timers
Timers can be added to more closely emulate
actual user load.
For example a Random timer can be added to
moderate a sampler request from 50 requests in 1 second to 50
requests in 5 seconds.
Or a Constant Throughput Timer can
generate delays to cap the maximum samples per minute that are
executed.
Section 10 Regular Expression Extractor
Use Case: Script is
recorded with User A credentials and the script needs to run with
credentials passed as variables.
Add a Regular Expression
Extractor with a variable name and a regex like .+? enclosed in ()
Section
11 Data Driven Testing
jMeter can read input values
from an external .csv file
Add a Data Element of type CSV Data Set Config to the Thread Group. No header in the csv.
Add variable
names for the fields in a comma-separated list
In the sampler’s parameter list add the variable in the form ${variable-name}
The variable is then passed in the sampler, replacing a hard-coded value that may have been collected by the script recorder
Section 12 Handling Dynamic Responses and Correlation
Example of capturing the Session ID with a Regular Expression Extractor
An example of using
the Regular Expression Extractor is capturing the session ID on
navigating to a home page in a new session.
A common login
pattern is to pass a session id as a hidden parameter along with
username and password.
When load testing multiple logins in
jMeter the session ID for each login must be captured and passed to a
variable.
Section
13 non-gui mode and reporting
jMeter can be run in an
admin-mode command shell.
<path to jMeter.bat> jMeter -n -t < path to jmx file> -i <path to write result .jml file?
-n non-gui
-t test case file (.jmx)
i result file (.jml)
The .jml results file can be viewed as a spreadsheet
Alternative
result reporting:
Taurus
is a graphical results tool
Blazemeter
is a commercial paas company that provides cloudbased load testing
infrastructure that
includes a graphical reporting tool
Section 14 Jmeter distributed mode.
Whereas
jMeter tests are developed on standalone systems, Distrubuted systems
generally used for production testing where the number of threads
(users)
is in the 100’s or 1000’s
Basic
Architecture of a
distributed system
Steps:
at 1 master and 1 or more slave machines exist on the same subnet and all have the same version of jMeter
On
the
Master and each
Slave
disable SSL
for RMI in jmeter properties to workaround network configuration for
demo purposes only.
#
Set this if you don't want to use SSL for RMI
server.rmi.ssl.disable=true # change from false to true
Start the Slave machine(s) with jmeter-server.bat. Note the ip address(es)
On the Master update the the ip address of the slaves in jmeter.properties
Edit the list of remote hosts in jmeter-properties, commenting out
the default localhost IP (127.0.0.1)
# Remote Hosts - comma
delimited
#remote_hosts=127.0.0.1
remote_hosts=192.168.1.66
On the Master machine open a test and select run -> remote start and select the ip address of the slave or start all.
On
the slave machine the
command window will
display “Starting the test ...” and “Finished the
test ...”
The jMeter instance on the master will show the listener results for tests run on the slave machines.
Section 15 Beanshell scripting
BeanShell is a scripting language that can run in the Java Runtime Environment. In jMeter it provides a programmic capability for tasks such as passing a dynamically randomized variable.
Monitor Beanshell output in jMeter Options -> Log Viewer.
Beanshell Hello World and jMeter variable api
example.
https://jmeter.apache.org/api/index.html
A random unique value can be generated by the “epoch time’ method or by adding a Random Variable sampler.
A BeanShell PostProcessor can be used to evaluate the response code of the previous iteration.
Section 16 Selenium Integration
A java-based Selenium project compiled to a jar can be run within Jmeter. First copy the jar to \apache-jmeter-”ver”\lib\junit\. Then in a thread group of a jMeter project add a jUnit Request sampler.
The sampler will read the Classnames and their Test Methods of all jar files in the junit folder.
Select the Classname and Test Method from the dropdowns.
In the Thread Group set the Number of Threads and any other
parameters and run.
Jmeter will execute the tests from the
jar file and report results to listeners as for a jmeter-hosed
project.
A
limitation of this method is that a separate browser will be opened
for each thread and this can limit the number or threads that can be
run.
A solution is to use the HtmlUnit , a headless java-based web browser integrated with Selenium.
Section 17 REST API load testing
This section of the Udemy course is obsolete and not worth listening
to.
The summary is that a REST API can be load tested from a
HTTP Request sampler where the fields are entered manually as opposed
to from a Test Script Recorder.
Below is an example using
openweathermap.org where a free API key can be requested
Section
18 Monitoring Server Performance
Demo
using
the commercial java profiler tool YourKit.