jmeter foundation series - association

   jmeter script contains a lot of requests, but most likely there is some connection between the request. That is associated with the connection between the contexts, obtained in response to the foregoing request, as later input, this different response from the foregoing, is processed differently.
  Such as login, obtain the login token, available through the association receive various requests will need to be the token as a parameter to normal access to the resource page.
  There are three ways jmeter associated, respectively, it is a regular expression extractor, Xpath Extractor Extractor and the JSON .

1, the regular expression extractor

The sampler (e.g., HTTP requests), select the post processor - extractor regular expression, can be used.
Below to extract the initial token, for example, under about how to extract the required information.

To add an HTTP request

jmeter foundation series - association

Click Run, in the result tree view response information. In this example, we need to extract the value of the data as a token
jmeter foundation series - association

Request in HTTP gettoken added regex extractor, fill the following information.
jmeter foundation series - association

 Explain:
 (1) the reference name: next request parameter name to a reference, such as filling token, if available $ {token} references it.
 (2) :( regular expressions) enclosed part is to be extracted. This section needs to learn how regular expressions, this does not elaborate.
 (3) Template: $$ with reference them, if there are a plurality of regular expressions (extracted by a plurality of brackets), such as $ 2 $ represents the analytical value of 2, in the regular expression $ 1 to $ represents parsed The first value.
 (4) match numbers: 0 represents a random value, a value representative of the entire, usually filled 0.
 (5) Default: If the parameter is not to get value, a value that defaults to take it.

Add a new request, which may be acquired as the above value token. Citation format is {token_g1}. g1 represents a value extraction (if a plurality of token, g2 denotes the second).
jmeter foundation series - association

Then click Run in the result tree can be seen, the same token parameter values ​​for the new request with previously acquired data value, indicating successfully extracted.
jmeter foundation series - association

2、Xpath Extractor

Another may be the XPath Extractor is used to extract the contents of a given page Post Processor (post processor), the XPath Extractor is used in a manner similar to a regular expression processor, but need specified in the regular expression is not Extractor but given XPath path of
jmeter foundation series - association
the element on the page as text extraction, Xpath Extractor relatively easy to use. Xpath can browser through F12, to obtain the required elements of expression.

3、JSON Extractor

JSON Extractor and Xpath Extractor is very similar, just listen to know the name. The result of response to JSON-formatted data, extracted with JSON Extractor will more convenient and elegant. Under the previous example shows how to use:

If a value needs to be extracted from the following url userType in response json results are displayed in the format, you can clearly see the hierarchy .
jmeter foundation series - association

Add JSON Extractor log on request, to the extraction of variable Variable names set name, JSON Path expresstions format
jmeter foundation series - association

If the response contains a plurality customerinfo url, to extract the second customerinfo inside userType, available $ .data.customerInfo [1] .userType extracted as an array.

Note: To check whether successfully extracted the required variables, you can add a debug sampler in the thread group, after the execution of the script, you can view the results of its tree
jmeter foundation series - association


Its scope of application methods have three kinds of association, we have mastered the use of these methods will be like a duck when writing test scripts.

如获取HTML等资源时,选择Xpath Extractor更便捷,可快速提取具体元素的属性值;
如响应格式为JSON,选择JSON Extractor无疑更方便;
若进行接口测试,请求的响应不是页面元素的形式,则应用正则表达式进行提取。

Rui Jiang Yunguan website link: https://www.eflycloud.com/home?from=RJ0035

Guess you like

Origin blog.51cto.com/13475644/2458046