In this paper, the method of setting parameters for finishing JMeter
There are several ways to set parameter values: 1. Using the function in JMeter to get the value of the parameter, __random,__threadnum,__csvread,__stringfromfile, the specific invocation method is as follows:
${__random (,,)},$,${__csvread (,)},${__stringfromfile (,,,)}.
See the use of the JMeter function, you can find the JMeter function on the Function assistant pop-up box by using the menu "options"-> "Function Assistant dialog box."
Where the first parameter of the ${__random (,,)} method is the lower bound of the random number, the second parameter is the upper bound of the random number, and the third parameter is the variable name that stores the random number; ${__csvread (,)} The first parameter in the method is the file name, and the second parameter is the column in the file (the number of columns starts from 0); The first parameter in the ${__stringfromfile (,,,)} method is the file name, and the ${__stringfromfile (,,,)} method does not specify which column in the file is read, so ${__stringfromfile (,,,)} Only files that contain one column can be read. 2. User-defined variables
2.1 Add "Configure symbol"-> "user-defined variable"
2.2 "Name" to enter the variable name, here to login as an example, define two variables username and password. Values can be entered directly into a value, can also be read from a CSV or dat file by a jmeter function __csvread,__stringfromfile, and you can set parameters by prefixing the method with random numbers.
When a parameter value is a prefix plus a number, you can set the parameter value with the prefix name plus ${__random (,,)} or $. If a user named Perf_0 to perf_1000 is prepared before the logon test, the user name can be set to Perf_{__random (0,1000,)}.
When the value of the parameter is not regular and the amount is not too large, you can read from the file by ${__csvread (,)},${__stringfromfile (,,,), such as saving the user name and password in the User.csv file, user.csv the following:
oriana,123456
Admin,admin
dandan,123456
Because there are two columns of data in the User.csv file, only the ${__csvread (,)} function, the value after the username parameter is set to the ${__csvread (user.csv,0)},password parameter, is set to ${__csvread ( user.csv,1)}. 3. read from CSV file
This method can be used when the value of the parameter is not regular and the amount is not too large.
The following are specific practices:
3.1 Create a CSV file, the content is the value set of the parameter, each parameter occupies a column, the first row begins to write the parameter value, do not write the argument name
3.2 Add a "configuration symbol"-> "CSV Data set Config" to the test plan or thread group
3.3 FileName to fill in the full path of the CSV file in step 2.1 (when the CSV file is in the bin directory, just give the filename)
3.4 The variable name in the virable names, separated by commas if there are multiple variables in the CSV file
4. Get from the database
This method can be used when the value of the parameter is not regular and the quantity is large.
The following are specific practices:
4.1 Download MySQL JDBC "Http://dev. mysql.com/get/downloads/connector-j/mysql-connector-java-5.1.12.zip/from/http:// ftp.jaist.ac.jp/pub/mysql/"
4.2 After extracting the downloaded zip package, place the Mysql-connector-java-5.1.12-bin.jar in the JMeter Lib directory
4.3 Add "configuration symbol"-> "JDBC Connection Configuration" to set the following parameters:
Database url:jdbc:mysql://host:port/db (such as Jdbc:mysql://localhost:3306/testlink
JDBC Driver Class:com.mysql.jdbc.Driver
Username: User name to connect to database (such as root)
Password: Connect the password to the database
4.4 Add "Sampler"-> "JDBC Request" and enter the query statement in SQL query as follows:
Select CONCAT ("[",
Group_concat (
CONCAT ("{username: '", Login, "'"),
CONCAT ("{password:", password), "'}"), "]" as JSON from users
4.5 Add the "Back Processor"-> "Regular expression Extractor" to the JDBC request in 4.4 to extract the username and password in 3.4 to set the parameters for the regular expression extractor:
Reference name: User
Regular expression: Username: ' (. +?) ' \{password: ' (. +?) '
Template: $1$$2$
When used, the USER_G1 is the username, and the USER_G2 is the password for the corresponding username; more regular expression extraction methods see JMeter Regular Expression Extractor 5. The regular expression is extracted from the response data of the preceding request, and the specific operation see JMeter Regular expression Extractor
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.