A simple way to describe JMeter
is a tool that captures the way your web application interacts with the web and
assesses performance of your web application. Like other testing tools, it has
steps that in a combination carry out a particular test. JMeter offers logic
controllers to group your steps so that you can ascertain the way the steps
behave. One you get along with JMeter, using some of those logic controllers
will be inevitable. Here I will try to show how to use some of the logic controllers I often use.
1. Transaction
Controller: This helps you to group steps. Suppose you want to assess the
performance of a successful login action. And a successful login action
requires more than one HTTP requests. So you can group them in a transaction
controller as shown below.
Then add a Summary Report
listener to the thread group. Now if you run the test you will notice that a separate
assessment is being shown for transaction controller.
2. ForEach
Controller: ForEach controllers are very helpful to loop through an array. Suppose,
you are visiting a page that contains a list of some objects. You want to delete
some objects with names having a common prefix. And the delete operation
requires ID of an object being deleted. Now you can do the followings:
a. Identify the HTTP request that loads list of the objects.
Add a Regular expression extractor (post processors) that extracts IDs of the
objects you want to delete. You can configure the extractor as shown below
1.
Give a
name of the variable/array
2.
Enter regular expression that extracts the ID
3.
Add template to refer to group 1 within the
regular expression
4.
Add -1 to consider all values returned by the
regular expression
5.
Add a default value of the variable
b.
Add ForEach controller and place the delete step
within as shown below
1.
Give the reference name of previous step as ‘Input
variable prefix’ here
2.
Enter an ‘Output variable name’. This variable will
be referred in delete step.
c.
Refer to the ‘Output variable name’ as given
above in delete step as shown below
If you run the
test now, you will notice that the steps mentioned under ForEach Controller is
executed as many times as the IDs the regular expression extractor returns. You
can check this in a View Results Tree listener.
3. If
Controller: As the name suggests, it allows you to apply if else condition to
your tests. Suppose you have two different sets of steps to create two
different types of users. And you want your test to decide which set of steps
to execute depending on the value of a variable. You can do the followings
a. Group the sets of steps as mentioned above in
two different If Controllers. And add a ‘User Defined Variables’ config element
as shown below
b. Configure the If Controller as shown below
Here
the Condition asks If Controller to execute the steps only if value of the variable is "Type 1". Similarly you can configure the 2nd If Controller as shown
below.
I will show how to use the following controllers in my next post
- Include Controller
- Interleave Controller
- Loop Controller
- Module Controller
- Once Only Controller
No comments:
Post a Comment