Then every Dev has to automate testing!!!

Tram Ho

The article stands from the dev’s point of view on the issue of performance testing

Question

In our dev life, we will surely encounter questions like: why know A’s code is slower than B’s code, after refactoring how to know new code is more efficient than old … To answer this problem we need to check check many things but one thing for sure to check is performance. In this article, I will use jmeter to test the performance of the app after performing a series of operations.

Doing

To perform the test I will divide it into main steps:

  • Record user actions with Blazemeter
  • Import to jmeter and edit jmeter
  • Kiểm TRA

Record user actions with Blazemeter

Setting

To use Blazemeter, I installed the extension on chrome at the link . After the installation is complete, the interface of Chrome will be as follows:

Use

After the installation is complete, we open the browser to the function to test. My function is as follows:

  • Open the survey link
  • Press the “OK” button
  • Fill in the survey
  • Press the “Next” button
  • Fill in the information
  • Press the “Finish” button

To record these actions you need to do is:

  • Turn on BlazeMeter
  • Enter the name of the function
  • Press the Record button (red circle button) and then perform the operations
  • When done, press the Stop button as shown
  • Open BlazeMeter again => Save => Check in jmter only After this step we will get a .jmx file

Import to jmeter and edit jmeter

Import

Open up jmeter and import the file above.

Although the above .jmx file has recorded the entire operation of that function, we will not be able to use it immediately. Because some of the params in the following requests are the results of the previous request, in other words, every time we test that parameter changes. The solution is to save them and call them in the following requests, not hard fix like the .jmx file above .

Config jmeter

This is the jmter interface after I imported the above .jmx file and tested it. Here is the first shock: Screenshot 2022-10-14 at 14.37.09.png Cause failed: after the first request, the system returns csrf_token , third-party-token ,… to use for the following requests. Whereas my csrf_token is of the request when I do the above but not of the request when doing the test.

In this article, I will introduce 2 methods to get the value in the request and save it to use for the following requests, that is: Regular Expression Extractor , JSON Extractor

Regular Expression Extractor

I use Regular Expression Extractor to get the value when the response is html. The value to get is in the title tag, meta , div … for example. To use it, do the following: Screenshot 2022-10-14 at 14.43.38.png

Here is the interface: I will explain the main items:

  • Name of created variable : enter the name of the variable that we want to use later
  • Regular Expression : Fill in the expression to get the information to get, in this example I want to get the csrf-token . This variable is in the content of the meta tag named csrf-token
  • Template : We enter $1$ , as I understand it is to return the first group, enter $1$ to get the first group.

How to use: To use the newly created csrf variable, we use the syntax: ${csrf} , For example:

JSON Extractor

I use JSON Extractor to get the value when the response is JSON. To use it, do the following: Screenshot 2022-10-14 at 14.55.02.png Here is the interface: Screenshot 2022-10-14 at 14.55.40.png For example, the response of the previous request returned in the form: {panel_id: 1, name: 'Panel_1'} , I will save the panel_id variable as shown above.

Using: Screenshot 2022-10-14 at 14.57.34.png I added the panel_id variable to http_request as shown above

Test

Depending on your function, there is a way to get your own variable value. You just make each request one by one to see what the request is missing and add accordingly. Once it was fixed I used Aggregate Report to check the performance. And here are the results, we pay attention to the Throughput column to compare between the tests:

Conclusion

  • Dev can also do automation testing
  • Jmeter is stronger than we (dev) think
Share the news now

Source : Viblo