In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
The jmeter script contains many requests, and there is likely to be some correlation between the requests. Association is the connection between contexts, through the response of the previous request, as the input of the following text, so as to make different processing according to the different responses of the previous article.
, such as login, the token obtained when logging in can be obtained through association. Subsequent requests need to be transmitted with this token as a parameter to access page resources normally.
There are three ways to associate jmeter, namely, regular expression extractor, Xpath Extractor, and JSON Extractor.
1. Regular expression extractor
In the sampler (such as HTTP request), select the post processor, the regular expression extractor, and you can use it.
Let's take the extraction of the initial token as an example to describe how to extract the required information.
Add a HTTP request first
Click run to view the response information in the result tree. In this case, what we need to extract is the value of data as token
In HTTP gettoken's request, add a regular expression extractor and fill in the following information.
explained:
(1) reference name: the name of the parameter to be referenced in the next request. If you fill in token, you can reference it with ${token}.
(2) regular expression: the part enclosed by () is to be extracted. This section needs to understand the methods of regular expressions, and I won't go into details here.
(3) template: quoted with $$, if there are multiple regular expressions in the regular expression (extracted by multiple parentheses), such as $2 $, it represents the second value parsed to, and $1$ represents the first value parsed to.
(4) matching numbers: 0 for random values, 1 for all values, usually fill in 0.
(5) default: if the parameter does not get a value, it defaults to a value for it.
Add a new request that gets the above value as token. The reference format is {token_g1}. G1 represents the first value extracted (if there is more than one token,g2 for the second).
Then click run, and you can see in the result tree that the token parameter value in the new request is the same as the data value obtained earlier, indicating that the extraction is successful.
2 、 Xpath Extractor
XPath Extractor is another Post Processor (post processor) that can be used to extract the given content of a page. XPath Extractor is used in a similar manner to a regular expression processor, except that what is specified in the Extractor is not a regular expression, but a given XPath path.
Xpath Extractor is more convenient and easy to use when the extracted text is an element on the page. Xpath can get the expression of the desired element in the browser through F12.
3 、 JSON Extractor
JSON Extractor is very similar to Xpath Extractor, and you can tell by its name. For the data whose response result is in JSON format, it is more convenient and elegant to extract with JSON Extractor. The previous example shows how to use:
If you need to extract the value of userType from the url below, the response result is displayed in json format, and the hierarchical relationship can be clearly seen.
Add JSON Extractor,Variable names to the login request and set the name of the extracted variable in the following JSON Path expresstions format
If the response of the url contains more than one customerinfo, to extract the userType from the second customerinfo, you can extract it as an array of $.data.customerInfo [1] .userType.
Note: to check whether the required variables have been successfully extracted, you can add a debug sampler to the thread group. After executing the script, you can check the result tree to know.
Each of the three association methods has its own scope of application, and mastering these usage methods will be like a fish in water when writing test scripts.
For example, when obtaining resources such as HTML, it is more convenient to select Xpath Extractor, and you can quickly extract the attribute values of specific elements; if the response format is JSON, it is undoubtedly more convenient to select JSON Extractor; if you perform interface testing, the response of the request is not in the form of page elements, then regular expressions are used to extract it.
Ruijiangyun official website link: https://www.eflycloud.com/home?from=RJ0035
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.