Jmeter Parameterized Request Instance

Source: Internet
Author: User


Jmeter Parameterized Request Instance

Requests in JMeter can be parameterized in 4 ways:
1.CSV Data Set Config
2. Database
3. User-defined variables
4. Get the parameter value using the function in JMeter

The first way: CSV Data Set Config

1. Create a data.txt file that reads as follows:
101010100, Beijing
101010200, Haidian
101010300, Chaoyang
The URL for requesting the weather is: GET http://www.weather.com.cn/weather/101010100.shtml

2. Create

2.1 Thread Groups

    • 2.2 Adding CSV Data Set Config

2.3 HTTP Requests


Server name or IP:www.weather.com.cn
The protocol is: the HTTP method is: GET
Path is:/weather/$ {citycode}. s h T m L where ${citycode} is a reference to CSV data in Citycode


    • 2.4 Add assertion--the assertion content is ${city}, is a reference to the CSV data in the city
    • 2.5 Add monitoring--add view results tree and aggregated report
    • 2.6 Running and viewing results


    • Second approach: Database
    • See JMeter Test MySQL DB instance,
Add:1. Thread Groups 2.JDBC Connection configurati on3.JDBC request User ID 2 username and Gender command is: SELECT Concat (name,sex) from UserInfo where userid= "2";where concat is to connect the name and the password, and then the regular expression is easily extracted .
    • 4. Regular Expression Extractor



fill in the regular expression:
  1. Note: whatever
  2. Apply to: Default
  3. Fields to check: selection of subjects, general selection body, that is, the page body information returned to JMeter by the server
  4. Reference name: The name of the parameter defined, which can be referenced at a later step
  5. Regular Expressions: The part in the regular Expression () is to be extracted.
  6. Template: $1$ represents only one set of data, $1$$2$ represents two sets of data
  7. Matching numbers: 0 for random values, 1 for all values, and 0 for general cases
  8. Default value: If the parameter does not get a value, it defaults to a value that allows it to take
5. For the results returned from the previous level database request, Add the View results tree, the JDBC request is returned correctly, and then new HTTP requests, referring to the parameters taken out by the post processor name, reference mode ${name} name Sexliming Female




7. Add View results tree for HTTP requests, run, view results


 The Third Way: User-defined variables   1. Add HTTP request, reference user-defined variable ${searchword} and ${ts}      


 2. Add user-defined variables (Add-config-original-custom variables)




3. Run the View results






Fourth: get parameter values using JMeter's own function
functions that can produce values in JMeter are: __random (,,), __threadnum,__csvread (,), __stringfromfile ( ,,,)The functions are called by the following methods:
1) __random (,,), the way to get the value: ${__random (param1,param2, param3)},param1 is the lower limit of the random number, param2 is the upper limit of the random number, PARAM3 is the variable name to store the random number, is optional. Therefore, you can also call this function: _random (PARAM1,PARAM2,PARAM3), and then take the value of PARAM3.
2) __threadnum, get the value of the way: ${__threadnum}, this function does not have any parameters, it is used to get the current running thread number.
3) __csvread (,), the way to get the value: ${__csvread (PARAM1,PARAM2)},param1 is the file name, and PARAM2 is the column (the number of columns starts from 0). See the CSV Data Extraction section for details on how to do this.
4) __stringfromfile (,,,), how to get the value: ${__stringfromfile (PARAM1,PARAM2,PARAM3)},param1 is the file name, param2, param3 is optional: param2- The variable that stores the result, the param3-file starts the column, the network finds a little use of this function, from:


1. Function: ${_stringfromfile (filename. dat)}
2. The format of the external file must be. dat
3. The default read location is/bin, you can also set the file storage path, such as: ${_stringfromfile (E:user.dat)}, from the E-drive to read the data in the User.dat file
4. Every time you read a line in a file
5. If I have multiple user files and want to read them together, the filenames are User1 user2. Function write: ${_stringfromfile (user#.dat,,1,2)}, read User1 and User2 files from the default directory
6. If a file wants to read multiple times, it can be written as: ${_stringfromfile (User.dat,,, 2)},user1 file read 2 times
]


"description" about the function of JMeter, you can use the JMeter Function Assistant dialog box: Click the JMeter "Options", select "Function Assistant Dialog" (or use the shortcut key "Ctrl+f"), in the "Select a feature" drop-down box to select the function you have, In the function parameter list "value" this column, fill in the corresponding parameter value, click the button "Generate", you can copy the generated function string to use. Use the function helper to generate the function __random string as follows:

Jmeter Parameterized Request Instance

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.