Words LoadRunner some functions, such as: parameterization, checkpoints, collection points, associations, JMeter also have these functions, but the function may be slightly weaker, today on the association to explain.
There are two ways to associate JMeter: The post processor-the regular expression extractor and the XPath Extractor.
First, Regular expression extractor
1. Adding regular expressions
Right-click on the previous request to get data to add a post processor--Regular expression extractor
explanation :
(1) Reference name : The name of the parameter to be referenced by the next request, such as filling in ActivityID, you can use ${activityid} to reference it.
(2) Regular expression :
Part of the () is to be extracted.
. matches any string. +: one or more times.: Don't be greedy, stop after you find the first match. Note: (. +?) [. \n]+ can match all characters, including line breaks.
(3) template : With $$ reference, if there are more than one regular expression in the regular expression (more than the parentheses in the east), it can be $2$$3$, and so on, representing the number of the parsed to the title. Example: $1$ represents the 1th value resolved to
(4) matching number : 0 for random values, 1 for all values, usually 0, if in LR, the value is an array, but also to deal with, LR11 version with a random function can not write large pieces of code to handle the array.
(5) Default value : If the parameter does not get a value, it defaults to a value to take it.
2. Illustrative examples of regular expressions
(1) Extract a single string:Suppose testers expect to match the following parts of a Web page: name = "file" value = "Readme.txt" > and extract Readme.txt. A regular expression that meets the requirements: Name = "file" value = "(. +?)" >. (): Encapsulates the matching string to return ...: matches any string. +: one or more times.: Don't be greedy, stop after you find the first match.
(2) Extracting multiple strings:Suppose the tester expects to match the following parts of the Web page: name = "file" value = "Readme.txt" > and extract the file and Readme.txt. A regular expression that meets the requirements: Name = "(. +?)" value = "(. +?)". Reference name: myref Template: $1$$2$ The value of the following variable will be set: Myref_g0:name = "file" value = "Readme.txt" MYREF_g1:fileMYREF_g2:readme.txt reference ${myref _G1}
3. Use the associated request
Such as:
4. Complete example : Case code
Second, XPath Extractor
The XPath extractor is another post processor,xpath extractor that can be used to extract the content of a page, similar to regular Expression extractor, It is just that the specified XPath path is not a regular expression, but a given extractor.
Taken from a previous request with XPath. This form is more appropriate for cases where XML fragments are returned. On the request to get data, right-click to add a post processor-->xpath Extractor. The reference name is the name of the parameter to be referenced by the next request, such as filling in the body, which can be referenced by ${body}.
XPath is typically used to return XML much more.
XPath Extractor's setup interface:
L Use Tidy?: When the page you want to work on is in HTML format, you must select this option and uncheck it when the page you want to work with is in XML or XHTML format (for example, RSS returns).
L Reference Name: The parameter that holds the extracted value.
L XPath Query: an XPath expression used to extract a value.
The default value for the parameter:
Three, summary of these two ways
Both the regular expression extractor and the XPath extractor can be used to extract specific text from a given page and save it in parameters, both of which have advantages and disadvantages.
The regular expression extractor can be used to extract any text of the page, and the extracted content is to match the text in the page content according to the regular expression;
XPath Extractor can extract any property that returns any element of the page.
By contrast,
If the text that needs to be extracted is a property value for an element on the page, it is recommended to use the XPath Extractor;
If the text that needs to be extracted is not fixed on the page or is not a property of the element, we recommend that you use the regular expression extractor.
"JMeter" associations-regular expressions and XPath