Use of common controls
table of Contents
1. Parameterization: Take search as an example to parameterize the search conditions
Two, regular expression extractor
3. Information header plus token
Four, processing Base64 encryption parameters
Five, processing SHA256 encryption parameters
Seven, set global variables when multiple thread groups
2. Use token to set global variables
Steps: "Add" -> "Logic Controller" -> "Transaction Controller"
Nine, add the controller only once
10. Add meeting point and synchronize timer
11. Add a fixed timer to simulate the operating time gap between new and old users
Twelve, set up the database test
1. Put the mysql driver in the jmeter4.0\lib\ext directory
2、添加JDBC Connection Configuration
1. Parameterization: Take search as an example to parameterize the search conditions
1. Add csv Data set config
Steps: "Add" -> "Configure Components" -> "CSV Data Set Config"
2. Set csv Data set config
step:
- Fill in Filename, data file storage path
- Fill in File encoding, generally UTF-8
- Fill in Variable Names, fill in parameter names, separated by commas
- Fill in Delimiter, the default is English comma
Description:
- Filename: file name, refers to the file directory where the information is saved, it can be a relative or absolute path (for example: D:\test.txt)
- File encoding: csv file encoding, optional
- Variable Names: parameter name, multiple parameters are separated by ",". Parameter format ${OA_VendingMachineNum} and ${Name}
- Delimiter: The delimiter in the csv file (use "\t" instead of the tab key) (in general, the delimiter is an English comma)
The parameters I defined in the file
3. After defining the parameters and parameter values, we need to quote them in the request, the format is as follows: ${defined parameter name}
Two, regular expression extractor
Token:”(.+?)”
3. Information header plus token
Four, processing Base64 encryption parameters
import sun.misc.BASE64Decoder;
String data = new sun.misc.BASE64Encoder().encode(("..."+"${password}"+"...").getBytes());
vars.put("base64password", data);
// ${password}: the string parameter to be encrypted, base64password: the encrypted string is stored in the ${base64password} parameter
Encrypted website: http://www.jsons.cn/
Five, processing SHA256 encryption parameters
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
//Perform summary calculation after splicing appName, time and token
String appName = "D-KGRY";
String token = "${token}";
String time = vars.get("time");
String str = appName + time + token;
String strSha256 = DigestUtils.sha256Hex(str);
vars.put("signsha256", strSha256);
Six, export the Excel file
import java.io. *;
byte[] result = prev.getResponseData();
String file_name = "D:\\MyData\\ex_mokg\\Desktop\\DMP project test\\test data\\data assets_mobile portrait_200304.xlsx";
File file = new File(file_name);
FileOutputStream out = new FileOutputStream(file);
out.write(result);
out.close();
Seven, set global variables when multiple thread groups
1. Get the token
2. Use token to set global variables
3. Call global variables
8. Add a transaction controller to cut the requests involved in the same operation step into the same transaction
Steps: "Add" -> "Logic Controller" -> "Transaction Controller"
Nine, add the controller only once
During the stress testing process, an interface needs to be added only once, such as a login interface.
10. Add meeting point and synchronize timer
Number of Simulated Users to Groupby: The number of threads released each time. If set to 0, it is equal to the number of threads set to the thread rent.
Timeout in milliseconds: how many seconds the specified number of people has not gathered to count as timeout .
11. Add a fixed timer to simulate the operating time gap between new and old users
Twelve, set up the database test
1. Put the mysql driver in the jmeter4.0\lib\ext directory
2、添加JDBC Connection Configuration
3. Add JDBC Request request
4. Add BeanShell assertion
String response = "";
String Str = "5";
String state = vars.getObject("name").get(0).get("state").toString();response=prev.getResponseDataAsString(); // Get the state of the database request response result through the variable name and state Field information
if(response=="")
{
Failure = true;
FailureMessage = "The system is not responding, no response data can be obtained!";
// Compare database content and response content, and use euqals method to determine whether they are consistent
}else if(!state.equals(Str))
{
Failure = true; // Set the assertion failure to true
// String Msg = "(0-wait, 2-run, 3-failure, 4-failure disable, kill, cancel, 5-success)\n";
String Msg = "\n";
String Msg1 = "The current status is:";
if (state.equals("0")) {
FailureMessage = Msg1 + state + "-waiting" + Msg;
} else if (state.equals("2")) {
FailureMessage = Msg1 + state + "-运行" + Msg;
} else if (state.equals("3")) {
FailureMessage = Msg1 + state + "-Failure" + Msg;
} else if (!state.equals("4")) {
FailureMessage = Msg1 + state + "-Failure to disable, kill, cancel" + Msg;
} else {
FailureMessage = Msg1 + state + "-其他" + Msg;
}
}
else
{
String stratdate = vars.getObject("name").get(0).get("date_latest_send").toString();
String enddate = vars.getObject("name").get(0).get("u_date").toString();
String sdate = ${sdate};
int i = stratdate.compareTo(sdate);
if (i < 0) {
// Set assertion failure to true
Failure = true;
String Msg = "The start time is less than the defined time, please confirm whether the job has been rerun";
FailureMessage = Msg + "(Operation start date:" + stratdate + ", operation completion date: "+ enddate + ")\n";
}
}
5. Add assertion result