JMeter and Taurus Training (2/3)

Melissa Huerta Dev
WomenWhoCode Silicon Valley
9 min readOct 22, 2020

Last month Rachna Bafna, Sr. Performance Engineer, led 10 training sessions in which she spoke about Load Testing & Performance Engineering using JMeter and Taurus tools, in this article we’ll cover the second part, session 4 to session 6.

In previous sessions, installation and HTTP Request creation were covered. If you haven’t read about it, check this article first.

Now we will learn how to parameterize using CSV Dataset config using controllers as Once Only Controller! ✍🏽

  • Parameterization: parsing the information of the body from the test data, that could be a script or an external file.

👩🏽‍💻 Activity: Create a new HTTP Request according to the API

☞ Open a new JMeter Test and create a thread group.

☞ Under the thread group, create a HTTP Request and add a HTTP Header Manager.

Steps to add a ‘HTTP Header Manager’

☞ Then add a “View Results Tree” to the Thread Group, so you can view the results when the test is executed.

Tree structure after creating the HTTP Header Manager

To do this task, we will use a json API “Create Post”

☞ API provided: here, on the HTTP Request, you must fill this data:

HTTP Request for creating a post using an API.
HTTP Request body structure.

☞ Save your Test Plan and run it.

You can see the results in Results Tree > Body

👩🏽‍💻 Activity: Use csv files

Working in the same exercise.

☞ Add “CSV Data Set Config” to the thread group.

Steps to add ‘CSV Data Set Config’

☞ Create a csv file and add it to your “CSV Data Set Config”

Since, the API for creating a post only accepts 2 values, the csv file for this example should follow this format<title>,<body_content>

csv file format
  • Filename: indicate the location and the name of the csv to import.
  • Variable names: indicate the name of the properties of the object, for creating a post with the API provided, will be ‘tittle’ and ‘body’.
  • Ignore first line: in case your csv has the headers included (“title,body”), in this exercises we are not including the headers in the file so we shouln’t ignore the first line.
  • Recycle on EOF: setting this to true will re-read the file provided after it hits to the end of file, e.g if you run a test of N users, being N a greater number than the amount of test values you provided, then it is recommended to set this to True.
  • Stop thread on EOF: setting this to true will make the test stop whenever it reaches the end of file.
CSV Data Set Config parameters

☞ Change the number of threads to run inside “Thread Group” (e.g. 25), change the values in Body Data inside the “HTTP Request” and run the test!

☞ You should get something like this:

Results Tree

👩🏽‍💻 Activity: Create a Once Only Controller

This is used to group the requests we want to execute only once (e.g login process). Every request inside “Once Only Controller” will execute one per thread created.

☞ Create a “Once Only Controller” and add a “Create Post” request to it.

Steps to add ‘Once Only Controller’
Tree structure after adding ‘Once Only Controller’

☞ In “Thread Group” set: Number of thread = 1 and Number of loops = 4. Now run the test plan!

Setting Thread Group properties

You’ll get this results 👇🏽👇🏽

Results Tree
  • Correlation: extracting a id or value from a request and pass it to another following request.

For the next activity, we will use the request files we got by recording them using the “Orange HR” page and Blaze Meter, you can see the instructions on the past article here.

We will go over correlation using regular expression extractor! ✍🏽

👩🏽‍💻 Activity: Correlate HTTP requests

☞ Open the file obtained after recording with Blaze Meter.

☞ Disable all the requests but “authentication”

Steps to disable a group of HTTP requests

☞ Create a new request for the login process, this request goes before the authentication and it will be the one we are going to use to do the correlation.

  • Protocol: https
  • Server Name or IP: opensource-demo.orangehrmlive.com
  • Path: /index.php/auth/login
Login Request parameters

☞ Run the test and see the results! Remember to add “View Results” first. You’ll notice that the ‘LOGIN’ test worked but not the following now, this is because the session token is not the same for both of them.

You can compare the token values going to the results of ‘LOGIN’ and searching “csrf” and also reviewing the ‘auth’ parameters.

Token value got after running the LOGIN request.
Token given in the AUTH request.

As you see, both tokens are different.

How can we solve this? By correlation! 🔔

☞ Add a “Regular Expression Extractor” to the ‘LOGIN’ request.

Steps to add ‘Regular Expression Extractor’

☞ Add these parameters to the “Regular Expression Extractor”

  • Name of variable: csrf , actually you can name it differently
  • Regular expression: _csrf_token" value="(.*?)"

If you want to deep more about how to get the token syntax, watch this part of the session.

  • Template: $1$ , for this exercise, we will use only one group
  • Match No: 1, if you search in the response of the LOGIN request, you’ll get 2 findings when you search csrf, we are going to use the first one. Also, you can use -1 if you prefer to capture both values.
  • Default value: NotFound , we will get this value if there is an error.
Regular Expression Extractor Parameters

☞ Change the value of the token in the AUTH request to ${csrf}

AUTH request Parameters

☞ Run the test! You’ll see the test passed.

👏🏼 Now you know how to make correlations between requests! 😊

👩🏽‍💻 Activity: Create and add a function

For this task, we will use the first sample (Create Post with and API)

☞ Open the file

☞ Add userId to the Body Data in the HTTP Request ‘Create Post’, if we leave it like this, every time it runs will keep the same userId, of course we want this value to be dynamic, for that we are going to use a function.

Add ‘userId’ to Body Data

☞ Click on the “Function Helper”

☞ Select the “counter” function, set FALSE if you prefer to use a global counter, then click on “Generate & Copy to clipboard

Function ‘counter’ Parameters

☞ Copy it to the Body Data in the HTTP Request ‘Create Post’

Add ‘__counter’ function to Body Data

☞ Run your tests and voilá! 👏🏼 You’ll see the Request Body had incremented the values in userId

Note: Visit this video if you want to check about JSR223

👩🏽‍💻 Activity: Create a Report

☞ First, let’s add an ‘Aggregate Report’ in the ‘Thread Group’We go over assertions, aggregate report and timers in this session. ✍🏽

In some cases, our tests will return a 200 HTTP status, which indicates a success in our request and.. it means that it reached the url, but not necessary that our test is 100% OK.

You can disable ‘HTTP Cookie Manager’ and run the test, those are supossed to fail but it returns like a successful test and a 200 status.

What should be do?

We should be more specific when indicating the response we want to get.

e.g. using again our “Orange HR” sample, if after the login we want to go to the ‘Dashboard’ page, we must expect to get the text on that site, it could contain an specific values as the title “Dashboard”. We are going to use assertions for this.

  • Assertion is a process where you verify expected result.

👩🏽‍💻 Activity: Create an assertion

For this task, we will use the “Orange HR” sample, because it has more request but you can use your own if you feel more like to do that.

☞ Enable the HTTP request for ‘Dashboard’

Enabling HTTP Requests related to ‘Dashboard’

☞ Add a Response Assertion to a HTTP Request ‘Dashboard’

Adding a Response Assertion

☞ Set the expected response. We are going to use ‘text response’ because we want to check if we get the word Dashboard.

Response Assertion Parameters

☞ Run the tests, you’ll see that everything passed.

☞ Disable ‘HTTP Cookie Manager’ and run the tests, this time you’ll see that they failed, like they are supposed to. ✅

Assertion result

👩🏽‍💻 Activity: Create a Report

☞ First, let’s add an ‘Aggregate Report’ in the ‘Thread Group’

Adding an ‘Aggregate Report’

☞ Set these values in the ‘Thread Group’.

In case you are testing with more users, the ramp-up period set will be divided by those number of users (e.g 10 sec and 2 users, every 5 sec 1 user will be inserted in the test)

‘Thread Group’ Parameters

☞ Run the test. You’ll this information in your report. ✅

The values more important to look at are 90% Line, 95% Line and 99% Line.

Aggregate Report with results

👩🏽‍💻 Activity: Timer

This activity will help you to get the amount of throughput your system can handle.

☞ First, let’s add a ‘Constant Throughput Timer’ in the ‘Thread Group’

Steps to add a ‘Constant Throughput Timer’

☞ Set the time, e.g to 20 seconds and RUN the test.

You’ll get some results like these:

Aggregate Report with results

Good! ✅

Every time you run the test, it will try to decrease the throughput amount, it is recommended that you start testing with few amount of threads and increase after you get results.

In those sessions, Rachna taught us how to to take advantage of Jmeter and become better at testing and reading the results of it. In the sessions she also covered some Q&A, watch the videos for more info. 😉

‘This blog is a summary of a serie of event sessions run by the WomenWhoCode Silicon Valley on July 28, 2020. You can view the recording of the event below.

JMeter and Taurus Training Sessions by Rachna Bafna

🙋‍🙋🏽‍♀️ View and register for our upcoming events at http://bit.ly/siliconvalley_events

--

--