Recently just finished a small project, similar to the classroom exam part of the function needs to test in a number of students login system, and perform the exam, to submit the paper such a process, began to consider using loadRunner, later found too heavy, so the use of Jmeter, light learning cost is low, two days to do in the results, Don’t sum up a lot of things are easy to forget, nonsense is not much, on the body (this article for intuitive, using many screenshots, loading slow please wait for harvest, (*^__^*) hee hee……) .

The main interface:



Jmeter Basic Settings:

The Options button allows you to switch languages

Engineering operation process:

The operation mode is explained by the following case, and the process of this case is as follows:

User Login -Token Check- Determine user roles – Obtain statistics – Obtain exam status – Obtain exam questions – Single choice Questions – Submit papers – Log out

Project Catalog:


Component is introduced

View result number



Aggregated report

Graphic results

 

Thread group

Adding a thread Group

You can right-click on the root node “Test Plan” to add thread groups and other components related to the Test Plan. For example, JDBC thread groups in this project’s directory tree are added this way.



Add the element

Right-click on thread groups, controllers, etc., to add related components under that node

These include: HTTP requests, logic controllers, pre – and post-handlers, assertions, timers, configuration elements, listeners, and more.

HTTP request default value

Sometimes the test project has some global fixed variables and parameters that need to be referenced in multiple places. To reduce the operation, you can add the default HTTP request value to the thread group or a parent node. For example, set the server name and port in the following figure. HTTP request interface under its name would not have to write 127.0.0.1:3001 / API/getUrl, but direct written/API/getUrl
Can;

“Parameters sent with the request”, if written, will carry this parameter with each request, which is not used much and will not be used in this case



JDBC Connection Configuration

You need to install a dependency jar package to connect to different databases. This section only explains how to install SQLite data. For other databases, check the official website or other blog articles:

Jar package installation method:

Copy the downloaded JAR package to the lib directory where JMeter is installed.


JDBC Configuration method


JDBC requests

After the database connection, some CRUD(add, delete, change and check) operation configuration is commonly used to query. This case needs to simulate user login to achieve a series of operations, so this is to query the relevant fields of the user table;


After you click Run, the obtained data can be viewed under the JDBC Request in the view result tree


Debuger Sampler

After being added, you can see the value of the variable under this object in the view result tree, which is equivalent to the view of variables in debug mode.



Circulation controller

In the case of circular requests, you need to set the number of loops. After obtaining the user information in the user table above, you can log in to the system with the user name and password in each row.


counter

Parameter subscripts need to be set during cyclic reference. For example, in the userList userList array obtained, the userName to be sent in the request for the second login is userList[2]. The third time userName= userList[3], each time different, using the counter can be implemented


HTTP Cookie manager

Sometimes we need to store cookie information on the browser, but there is no cookie in the interface request. At this time, we need to add the cookie manager on the parent node, which can automatically intercept the cookie information written by the server through setCookie, as shown below:

If the server writes user information to the cookie after the login/ Check request is sent, it is automatically carried in subsequent requests
Cookie information.


The HTTP request

The interface stress test is based on sending requests, as shown in the figure above. The login interface is used as follows:

(1) Send Parameters


(2) Pass parameters in the form of Body Data



The HTTP header

When transmitting parameters in Body Data mode, the HTTP header needs to be configured. The value of content-Type needs to be set according to the actual situation, as shown in the following figure:


In response to assert

In order to verify whether the request is correct or not, request assertion is generally set to verify whether the status code returned by the request is correct, as follows: the status code returned by the user after logging in is “errcode” :0. The result includes this content even if the request is approved.




JSON Extractor (JSON parser)

After an HTTP request is executed, it is often necessary to fetch certain fields in the return result, and later interface requests will rely on the previous interface result. In this case, you need to use a JSON parser (right-click HTTP and add -post-processor). The following is an example of the result returned after login:

{
 "errcode": 0."user": {"id": 6,"userName":"XXX0001"."pwd":"45b1017f751948aa"."desc":"{ \ "name \" : \ "zhao four \" and \ "birthday \" : \ "1991.03.111 \", \ "politicalStatus \" : \ "\", \ "nation \" : \ "\", \ "education \" : \ "\", \ "the health \" : \ \ "" ,\"company\":\"\",\"duty\":\"\",\"dutyStartTime\":\"\",\"dedicatedNet\":\"\",\"tel\":\"\" }"."roleApp": {"id": 4."name":"Students"},        "token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX25hbWUiOiJEWFRHMjAxODA4MDEyMDkiLCJ1dWlkIjoiYzY3NDhhMjAtYTVkYS0xMWU4LThmNG ItZDcxYzA5YzJhMTFlIn0.ofbHY9LbGQPiI9Hs3ZQHLM6WWYKmk4meNUFgu-YlRLI",}}Copy the code


The extracted token information is as follows.


The token information can then be referenced directly with ${token} in subsequent requests. In this case, the status code it returns is also taken, and only if the status code is correct will subsequent requests be executed.

If the controller

Some HTTP requests are based on whether the result of a variable matches, as in this case only
Errcode is 0. There are also previous user role judgment, only students will perform the test query and other operations, all need to use the controller.



This case has been explained to the end, other functions have not been used by bloggers, today to share here.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — the dividing line between a firm and not China — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

2018.08.23 New content

User-defined variables

Earlier we talked about HTTP request default values. This is just a way to avoid repeating the address and port of the request and fixing variables. A more convenient option is “User-defined variables” in this section, where users can set more global variables to be used in requests. Bloggers met today, for example, we will develop a good project launch test on the test machine, where you need to modify multiple places: user authentication service address + port, system service address + port, JDBC to access database location, even SQL statements can be on the user variables, modified at any time convenient to query the conditions of the user.

The usage is as follows:

“Right click – Add – Configure components – User-defined variables” to complete the addition.



${_loginIP} = ${loginIP} = ${loginIP} = ${loginIP} = ${loginIP} = ${loginIP} = ${loginIP} = ${loginIP} = ${loginIP} = ${loginIP}

Thank you for your reading, I hope you can have a hand slip point attention (in fact, is ready to play “I hope you have a harvest”), welcome to exchange, common progress!