Jmeter association and regular

Associate

1. Association definition

Save the dynamic return value of a certain request as a variable for later requests that need to use the value

2. The reason for the association

The server or database verifies the validity of the value

3. Which values ​​should be associated

3.1 Database interaction (read and write)

insert ---association--the fields that establish the relationship--this piece of data belongs to who and who operated and when did it (business verification)

Insert data, the ID of this data will be returned

update

update table set x =? where xxid=?? and and

Associate the condition ID behind where

delete

delete table set x =? where xxid=?? and and

select. . . . .

key. xxid. Or. int==number

Relational database, there is a network relationship between tables and tables

Non-relational database,

INSERT INTO table name VALUES (value 1, value 2,...)

INSERT INTO table_name (column 1, column 2,...) VALUES (value 1, value 2,...)

INSERT INTO Persons (LastName, Address) VALUES ('Wilson','Champs-Elysees')

3.2 Non-database

Where to find ---- last step interactive request

Typical usage scenarios: timestamp, verification code (picture, mobile phone, email) session token

Features: strange

Example: Taobao shopping process

1. Registration------parameterized mobile phone number/email associated verification code, token

2. Login------parameterized mobile phone number association

4. Jmeter association method

Prerequisite: Visit http://ws.webxml.com.cn/WebServices/WeatherWS.asmx

We can get the interface of the web service of weather forecast without encryption. These interfaces are all available, the following scenarios are examples.

4.1 Boundary extractor

Note: The boundary extractor and the http request can be in the same directory or in a subdirectory. Let’s prioritize the subcategory.

As shown below, this is all possible

Right-click Add-Post Processor-Regular Expression Extractor under the request you want to associate

I describe a usage scenario here

The following are examples of HTTP GET requests and responses. The placeholders displayed need to be replaced with actual values.

GET /WebServices/WeatherWS.asmx/getRegionProvince? HTTP/1.1 Host: ws.webxml.com.cn

HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <ArrayOfString xmlns="http://WebXml .com.cn/"> <string>string</string> <string>string</string> </ArrayOfString>

Return result:

<?xml version="1.0" encoding="utf-8"?>

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml .com.cn/">

<string>Heilongjiang,3113</string>

<string>Jilin, 3114</string>

<string>Liaoning, 3115</string>

<string>Inner Mongolia, 3116</string>

<string>Hebei, 3117</string>

<string>Henan, 3118</string>

<string>Shandong, 3119</string>

<string>Shanxi,31110</string>

<string>Jiangsu,31111</string>

<string>Anhui,31112</string>

<string>Shaanxi,31113</string>

<string>Ningxia,31114</string>

<string>Gansu,31115</string>

<string>Qinghai,31116</string>

<string>Hubei,31117</string>

<string>Hunan, 31118</string>

<string>Zhejiang,31119</string>

<string>Jiangxi, 31120</string>

<string>Fujian, 31121</string>

<string>Guizhou, 31122</string>

<string>Sichuan, 31123</string>

<string>Guangdong,31124</string>

<string>Guangxi, 31125</string>

<string>Yunnan,31126</string>

<string>Hainan, 31127</string>

<string>Xinjiang,31128</string>

<string>Tibet, 31129</string>

<string>Taiwan, 31130</string>

<string>Beijing,311101</string>

<string>Shanghai,311102</string>

<string>Tianjin,311103</string>

<string>Chongqing, 311104</string>

<string>Hong Kong,311201</string>

<string>Macau,311202</string>

<string>Diaoyu Islands, 311203</string>

</ArrayOfString>

Edit boundary extractor

case1, we want to extract the city id of Chongqing

The configuration is as follows:

Apply to: Main sample only

Response field body to be checked

Reference name: cityid

Left border: <string>Chongqing,

Right margin: </string>

Matching numbers (0 means random)

Default value

Here to talk about matching numbers and default values

Matching number: when there are multiple results, 0-take a random result, 1-take the first one of the result list, 2-take the second one of the result list, and so on

Default value: when there is no result, return a default value for the variable

In order to verify that our extracted variables are correct, we need to add a [Debug Sampler] to debug our script

Our final script structure is as follows:

jmeter Debug Sampler

Debug Sampler

The Debug Sampler is mainly used to see whether the variables we set can normally get the values ​​we set

We don’t care about the two properties of JMeter properties and System properties. The default is false. They are some of the built-in properties of jmeter. Generally, they will not change. The key point is the middle one.

JMeter variables: Variables in jmeter. If this item is true, this component will print out the value of all jmeter variables in its range, so we can print out the value of the variable at the current position through it to debug the program.

After adding the Debug Sampler, we need to add the view result tree to view the specific variable data.

Here you see the variable we just added

4.2 Regular Expression Processor

Right-click Add-Post Processor-Regular Expression Extractor under the request you want to associate

The debugging script structure is as follows:

4. Regular expressions

Metacharacter

. Any character except newline

\w

\d matches numbers

Qualifier

* Repeat zero or more times (preferably get more)

+ Repeat one or more times (preferably get more)

? Repeat zero or one time

*"(Greedy) repeat zero or more times

For example, "aaaaaaaa" matches all a in the string. Regular: "a*" will output all the characters "a"

"+" (lazy) repeated one or more times

For example, "aaaaaaaa" matches all a in the string. Regular: "a+" will get all a characters in the character. The difference between "a+" and "a*" is that "+" is at least once and "*" can be 0 times ,

"?" (possession) repeated zero or one time

For example, "aaaaaaaa" matches a in the string. Regular: "a?" will only match once, that is, the result is only a single

Character a

"{n}" repeated n times

For example, from "aaaaaaaa" to match the string a and repeat 3 times the regular: "a{3}" The result is to get 3 a words

Symbol "aaa";

"{n,m}" repeat n to m times

For example, the regular "a{3,4}" will match a 3 or 4 times, so the matching characters can be three "aaa" or

Four "aaaa" regulars can be matched

"{n,}" repeated n times or more

The difference with {n,m} is that there will be no upper limit on the number of matches, but it must be repeated at least n times, such as regular "a{3,}" a must be repeated at least 3 times

"*?" Repeat as many times as possible, but as few as possible

For example, the regular "a.*?b" of "acbacb" will only get the first "acb", which could have been all

But after adding the qualifier, it will only match as few characters as possible, and the result of "acbacb" with the fewest characters is

"acb"

"+?" Repeat 1 or more times, but repeat as little as possible

Same as above, just repeat at least 1 time

"??" Repeat 0 or 1 times, but repeat as little as possible

Such as "aaacb", regular "a.??b" will only get the last three characters "acb"

"{n,m}?" Repeat n to m times, but repeat as little as possible

For example, "aaaaaaaa" regular "a{0,m}" because it is at least 0 times, so the result is empty

"{n,}?" Repeat more than n times, but repeat as little as possible

For example, "aaaaaaa" regular "a{1,}" is at least once, so the result is "a"