4 Ways to Parameterize JMeter

Source: Internet
Author: User

The JMeter test consists of two parameters, one in the URL, and one for the request to send.

Parameters in the URL, such as: Http://blog.da-fang.com/index.php/2010/06/01/jmeter parameter/, where "2010/06/01/jmeter parameter" is a URL parameter.
The parameter in the request, where only a GET request is used, for example: Http://blog.da-fang.com/?category=Web, where "category" is the parameter name and "Web" is its value.
For a POST request, after recording with JMeter, you can find it in the request "Send parameter with request" and "Send file with Request".

When you parameterize a jmeter script, use the parameter's local write format of $
For URL "http://blog.da-fang.com/index.php/2010/06/01/jmeter parameter/", in JMeter HTTP request blog.da-fang.com fill in "Server name or IP"; index.php/$/fill in the "path".
For the parameter Http://blog.da-fang.com/?category=Web in the request, blog.da-fang.com fill in the "Server name or IP" in the JMeter HTTP request;/fill in the "path" Parameter name category fill in the name of "Send parameter with request", the value of the parameter is filled in the corresponding "value".

There are several ways to set parameter values:

1. Use the function in JMeter to get the parameter value, __random,__threadnum,__csvread,__stringfromfile, the method is called 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 argument is the upper bound of the random number, and the third parameter is the variable name that stores the random number; The first parameter in the ${__csvread (,)} method is the file name. The second parameter is the column in the file (the number of columns starts at 0), the first parameter in the ${__stringfromfile (,,,)} method is the file name, and the ${__stringfromfile (,,,)} method does not specify which of the columns in the file to read, so ${__ stringFromFile (,,,)} can only read files that contain one column.

2. User-defined variables
2.1 Adding user-defined variables, configure symbols
2.2 "Name" Enter the name of the variable, here, as an example of login, define two variables username and password. Values can be entered directly or read from a CSV or DAT file via the JMeter function __csvread,__stringfromfile, and parameters can be set by prefix plus random number.
When the parameter value is a prefix plus a number, you can set the parameter value with the prefix name plus ${__random (,,)} or the method. If a user named Perf_0 to perf_1000 is prepared before the login test, the user name can be set to Perf_{__random (0,1000,)}.
When the parameter value is not regular and the amount is not too large, can be read from the file by ${__csvread (,)},${__stringfromfile (,,,)}, such as saving the user name and password in the User.csv file, the contents of User.csv are as follows:
oriana,123456
Admin,admin
dandan,123456
Because there are two columns of data in the User.csv file, you can only use the ${__csvread (,)} function, and the value after the username parameter is set to ${__csvread (user.csv,0)},password parameter is set to ${__csvread ( user.csv,1)}.

3. Read from the CSV file
You can use this method when the value of the parameter is not regular and the amount is not too large.
The following are the specific practices:
3.1 Create a CSV file, the contents of the parameter set of values, each parameter in one column, the first line begins to write the parameter value, do not write argument name
3.2 Add a "configuration Component", "CSV Data Set Config" in the test plan or thread group
3.3 filename 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 file name)
3.4 virable names fill in the variable name, separated by commas if there are multiple variables in the CSV file
4. Getting 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 the 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 "Configure symbol", "JDBC Connection Configuration", 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 the database (e.g. root)
Password: Password to connect 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 the users
4.5 Add the "Post processor" and "Regular expression extractor" in the JDBC request in 4.4 to extract the user name and password in 3.4 as an example set the parameters of the regular expression extractor:
Reference name: User
Regular expression: Username: ' (. +?) ' \{password: ' (. +?) '
Template: $1$$2$
When used, USER_G1 is the user name, USER_G2 is the password corresponding to the user name; more regular expression extraction methods see jmeter Regular Expression Extractor

5. Use regular expressions to extract the response data from the previous request, as described in jmeter Regular expression extractor


4 Ways to Parameterize JMeter

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.