One day, a student asked a question and felt it was necessary to sort out an article~
Because of the project, suppose we want to achieve the following requirements: get user information from the user table of the database, and pass it all as parameters to the login request, and complete the login operation separately.
01, Jmeter connects to the database
1、添加JDBC Connection Configuration
(Right-click test plan-->Configuration element-->JDBC Connection Configuration)
2. Configure database connection information, where
DataBase URL:
jdbc:mysql://192.168.88.130:3306/dataname?useUnicode=true&characterEncoding=utf-8
1) 192.168.88.130:3306 is the address and port number of the database; dataname is the name of the database
2) useUnicode=true&characterEncoding=utf-8 specifies the character encoding and decoding format utf-8
JDBC Driver Class :
com.mysql.jdbc.Driver This is the driver of the mysql database
Username: the login user name of the database
Password: the password of the database
3. Import the mysql driver package
Download the mysql driver package (
mysql-connector-java-5.1.7-bin.jar),
Put it in the lib directory of jmeter
Select the test plan and add the mysql driver package
02, add Jdbc request
Add jdbc request and set variables
1. Add thread group --> right click thread group --> add jdbc request, and make settings
2. Add Debug PostProcessor to view the acquisition of the variable phone value, add view result tree and run; get the following results.
It shows that the jdbc request and variable settings initiated by jmeter are normal
03. Read the user information of the library cyclically
Read the user information of the library cyclically and pass it to the next login request
The next step is to think about how to pass the user's mobile phone number obtained from the database search as a parameter to the next login request.
Need to refer to the ForEach controller here
1. Add the ForEach controller (right-click the thread group --> Logic controller --> ForEach controller), and first try the following settings
Enter the prefix of the variable: phone;
According to the variables set by the previous jdbc request, the values we want to take are phone_1, phone_2, phone_3..., so enter phone here
Start index for loop:0;
The index of the variable loop start, the start index of the first element +1
End index for loop:6;
The index of the end of the variable loop.
So here are the values phone_1, phone_2,..., phone_6
Output variable name: t_phone;
Variables used to replace the request under the loop
2. Add a login request under the ForEach controller and make a variable reference
3. After running, check the results, successfully obtain the first 6 user phone numbers from the library, and successfully log in respectively
For the above processing, you need to check the library yourself to find out how many users there are in total, and then set the End index for loop value of the ForEach controller (set to the total number of users), and then all users in the library can log in by parameter transfer;
Question: Can jmeter automatically learn the number of users in the database table, and then log in by looping the values?
Of course, you can use jdbc request to find out the number of users, and then directly set the End index for loop value of the ForEach controller.
Practice:
a. Add a jdbc request to query the total number of users in the user table and set the variable count
b. Set the End index for loop value of the ForEach controller
c. Run and view the result successfully
Then share some of my favorite information below, I hope it can help everyone
This information is organized around [software testing]. The main content includes: python automated testing exclusive video, Python automated detailed information, a full set of interview questions and other knowledge content. For friends of software testing, it should be the most comprehensive and complete preparation warehouse. This warehouse has accompanied me through a lot of bumpy roads, and I hope it can also help you. Pay attention to WeChat public account: Programmer Erhei, you can get it directly