Jmeter parameter request instance

Source: Internet
Author: User

Jmeter parameter request instance

Jmeter parameter request instance

The request in jmeter can be parameterized. There are four parameterization methods:

1. CSV Data Set Config

2. Database

3. User-Defined variables

4. Use the function in jmeter to obtain the parameter value.

Method 1: CSV Data Set Config

1. Create a data.txt file with the following content:

101010100, Beijing

101010200, Haidian

101010300, Chaoyang

Request weather URL: GEThttp: // www.weather.com.cn/weather/101010100.shtml

2. Create

Thread group 2.1

2.2 add CSV Data Set Config

 

 

2.3 HTTP Request

 

 

Server name or IP: www.weather.com.cn

Protocol: http Method: GET

Path:/weather/${citycode=.shtml where $ {citycode} references citycode in CSV Data

2.4 Add assertion -- the asserted content is $ {city}, which references the city in CSV Data.

2.5 add monitoring-add view result tree and aggregate report

2.6 run and view results

Method 2: Database

Add:

1. thread group

2. JDBCConnection Configuration

3. The JDBC Request user ID is 2 and the Gender command is: select concat (name, sex) from UserInfo where userid = "2 ";

Concat connects the name and password to facilitate regular expression extraction.

4. Regular Expression Extractor

 

 

Enter the regular expression:

Apply to: Default

Field to be checked: select the subject. Generally, select the subject, that is, the page subject information that the server returns to jmeter.

Reference name: the name of the defined parameter, which can be referenced later.

Regular Expression: the part enclosed in () in a regular expression is extracted.

Template: $1 $ indicates only one group of data, $1 $2 $ indicates that there are two groups of data

Matching number: 0 indicates a random value. 1 indicates all values. Normally, enter 0.

Default Value: If the parameter does not get a value, it is given a value by default for it to get

5. For the results returned by the above-level database Request, add a view result tree. After the JDBC Request returns the correct result, create an HTTP Request and reference the parameter name retrieved by the postprocessor. the reference method is $ {name}

Name sex

Liming female

 

 

7. Add a view result tree for the HTTP request. After running the tree, view the result.

 

 

Method 3: User-Defined variables

1. Add an HTTP request to reference User-Defined variables $ {searchword} and $ {ts}

 

 

2. Add User-Defined variables (add-Configuration Original-custom variables)

 

 

3. Run the command to view the result.

 

 

Method 4: Use the built-in functions of Jmeter to obtain the parameter value.

Functions that can generate values in Jmeter include :__ Random (,) ,__ threadNum ,__ CSVRead (,) ,__ StringFromFile (,,,)

The function call methods are as follows:

1) _ Random (,): $ {__ Random (param1, param2, param3)}, param1 is the lower limit of a Random number, and param2 is the upper limit of a Random number, param3 is the variable name for storing random numbers. It is optional. Therefore, you can also call this function like this: _ Random (param1, param2, param3), and then take the value of param3.

2) _ threadNum: $ {__ threadNum}. This function has no parameters and is used to obtain the number of the currently running thread.

3) _ CSVRead (,): $ {__ CSVRead (param1, param2)}. param1 is the file name, param2 is the column in the file (the number of columns starts from 0 ). For detailed operations, see descriptions of csv data extraction.

4) _ StringFromFile (,): $ {__ StringFromFile (param1, param2, param3)}, param1 is the file name, And param2 and param3 are optional items: param2-storage result variable, param3-file start column. The usage of this function is found on the Internet, from:

1. function: $ {_ StringFromFile (file name. 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, for example, $ {_ StringFromFile (e: user. dat)}, read the user from the edisk. data in the dat file

4. Read a row from the file each time.

5. If I have multiple user files and want to read them together, the file names are user1 user2. Function write: $ {_ StringFromFile (user #. dat,)}, read the user1 and user2 files from the default directory

6. If you want to read a file multiple times, you can write it as: $ {_ StringFromFile (user. dat, 2)}. user1 reads the file twice.

]

[Note] for the use of Jmeter functions, you can use the Jmeter function Assistant dialog box: click "option" of Jmeter ", select the "function Assistant dialog box" (or press the shortcut key "Ctrl + F") and select all functions in the "select a function" drop-down box, in the "value" column of the function parameter list, fill in the corresponding parameter values and click "generate" to copy the generated function string for use. Use Function assistant to generate function _ Random strings.

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.