Jmeter regular fetch request response data

Foreword

In testing, we often need to handle the data returned in response to a request, such as a lot of time cookie or token or Authorization authorization code is returned in the Response headers (response headers) in, then we will need to be extracted from, for other interfaces.

Today we mainly at learning how to respond to the data extracted by being in Jmeter in Response headers data.

The total for the interface:

All settings interface

Sending a request, the fetch response data

First, an HTTP request is provided, as follows:

HTTP request

Next, a view of a result tree, then perform obtain response data, i.e., the figure we need to extract the cookie data:

Response Data

Regular extraction response data

Next, we will set up a regular extractor (for extracting a cookie), an additional set a debug post-processing program (for viewing extraction results)

Regular extractor

Description:
1. reference name: the variable name, subsequent requests can be referenced by $ {name} to call
2. Regular expressions: according to the actual situation fill
3. Template: $$ represents the value of which require regular expression acquired 1 represents the first, -1 all, 0 represents a random
4. match numbers: 1 for the first, -1 all, 0 represents a random
5. default: If the match is not regular, the default values will be used

正则说明:
. 表示除“\r\n”之外的任意字符
* 表示匹配前面的子表达式任意次
+ 表示匹配前面的子表达式1次或多次
表示匹配前面的子表达式0次或1次
.*:贪婪匹配原则,即匹配到不能匹配为止
.*?:非贪婪匹配,即在匹配成功的情况下尽可能少的匹配

实例:存在字符串 7adbcfgfbesw ,要匹配7和b之间的字符
匹配1:使用 .* ,7开始之后,遇到第一个b不结束,继续找下一个b,直到不能匹配,即匹配到 adbcfgf
匹配2:使用 .*? ,7开始之后,遇到第一个b就结束了,即匹配到 ad

Debugging post-processing procedures

查看提取结果

Extraction results

以上就是本次的提取结果,在这里,如果需在后续请求使用,可通过 ${response_data} 来关联调用。

可能遇到的问题

假如,我们需提取 Set-Cookie 里的所有内容。此时,如果依然使用 .*? ,就会发现提取是不成功的,如下:

Response header data

Regular extractor

Extraction failed

要解决这个问题也很简单,我们修改正则表达式,使用 .* 贪婪匹配原则既可以。

Regular extractor

Successful extraction

Well, that's the content Jmeter regular extraction, extracting other data, such as token , the Authorization and other methods similar to the above, we can practice.

Guess you like

Origin www.cnblogs.com/wintest/p/11297827.html