In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
The regular expression extractor in the JMeter post processor is also the most commonly used component, which is very simple, convenient and powerful.
* * Boundary Extractor element has been added to jmeter4.0 to replace the regular expression extractor, and it is simpler and more convenient to use. * *
Recently, when I was adjusting the script, I had a deeper understanding of it, and found that every seemingly ordinary component of jmeter did a very good job, worthy of careful study. I would like to summarize my personal experience and share it with you.
Application scenarios:
In a thread group, the B request needs to use the data returned by the A request, that is, the association. If the response result of the previous request is used as the parameter of the next request, the post processor needs to be used for the response message of the A request. The most convenient and commonly used one is the regular expression extractor.
Regular expression extractor:
Allows the user to extract the required value from the request or response of a sampler request in scope through a regular expression, generate a template string, and store the result in a given variable name.
Description of each configuration item:
Apply to: scope (the assertion range of the returned content). In general, it is fine to keep it by default.
1. Main sample and sub-samples: the sampler acting on the primary node and the sampler corresponding to the child node
2. Main sample only: the sampler that only works on the primary node. Default option
3. Sub-samples only: sampler that only acts on child nodes
4. JMeter Variable: acts on the jmeter variable (you can enter the variable name of jmeter in the input box) to extract the desired value from the specified variable value.
Field to check: the scope of the response message to check
1. Subject: the body of the response message, which is the most commonly used
2. Body (unescaped): the body is the response body content that replaces all html escape characters. Note that context is not taken into account when dealing with html escape characters, so incorrect transformations may be made, so it is not recommended to use them.
3. Body as a Document: extract text from different types of files. Note that this option affects performance.
4. Response Headers: response header (if you use the Chinese version of Jmeter, you will see that this item is the message header. This is a Chinese translation problem, and English shall prevail)
5. Request Headers: request information header
6. URL: request url
7. Response Code: response status code, such as 200,404, etc.
8. Response Message: response information
* you can see that the extraction features in various scenarios have been provided here, which is very comprehensive!
Reference name (Reference Name):
The name of the Jmeter variable, which stores the extracted results
That is, the value, field, and variable name to be referenced in the next request. The reference method in the following text is ${reference name}.
Regular expression (Regular Expression):
The response result is parsed using a regular expression, and () parentheses indicate part of the value in the extracted string, followed by the extracted boundary content.
For the basic usage of * * regular expressions, please refer to the official description of regular expressions, which will be described in more detail below.
Template (Template): extraction mode for regular expressions
If the regular expression has more than one extraction result, the result is in the form of an array, template $1 $, $2 $, and so on, indicating that the parsed value is assigned to the variable; match from 1, and so on.
If there is only one result, it can only be $1 $
Match digits (Match No):
The result of regular expression matching data can be seen as an array indicating how to take a value: 0 represents a random value, a positive number n represents the nth value (for example, 1 represents the first value), and a negative number indicates the extraction of all eligible values.
Default value:
The default value when matching fails; it is usually used for subsequent logical judgments, usually a combination of English capitals with a specific meaning, such as ERROR, etc.
The following focuses on the matching rules and precautions of regular expressions:
1. Here are the common regular expression operators
Second, greed and non-greed
When it comes to regular expressions, we have to talk about two matching patterns: greed and non-greed.
1. Greedy and non-greedy patterns are two different expression matching behaviors. Greedy patterns match as much as possible on the premise of successful matching of the whole expression, while non-greedy patterns match as few matches as possible on the premise of successful matching of the whole expression.
2. As an example, suppose you have the following response result (only part of it is intercepted):
"code": "0", "msg": "request successful", "bizSeqNo": "1804242UD01154300109392900987311", "result": {"bizSeqNo": "1804242UD01154300109423800987316", "transactionTime": "20180424094239"
3. Now extract the value of bizSeqNo:
"bizSeqNo": "(. *)": greedy mode. The extraction result is: 1804242UD01154300109392900987311 "," result ": {" bizSeqNo ":" 1804242UD01154300109423800987316 "," transactionTime ":" 20180424094239 "
"bizSeqNo": "(. *?)": non-greedy mode. The extraction result is: 1804242UD01154300109392900987311
You can experience the difference for yourself.
III. Advanced matching problem
1. How to get the array results?
If there are multiple matching results, you will get an array. To extract the contents of the array, call ${bizSeqNo _ 1}, ${bizSeqNo _ 2}. If you want to get the number of matching results, use ${bizSeqNo _ matchNr}. If you want to randomly select one, just set the matching number to 0 and call it with ${bizSeqNo}.
2. How to get the unique matching result?
If you want to avoid getting multiple results above, you need to pay attention to writing the regular expression as a non-greedy pattern, or adding the front and back boundaries of the regular expression so that the results match uniquely.
Finally, let me tell you a little trick:
During debugging, the result tree and Debug PostProcessor can be viewed to help analyze the results.
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.