Variable extractors
A variable extractor extracts a string from the server response to the request and assigns the string to a variable. The variable extractor features two operating modes, simple and advanced. In simple mode, the user defines the string to be extracted; in advanced mode, the user can define more complex extractions using regular expressions.
- Definition (simple mode). Used to define the extractor.
- Variable name. The name of the variable automatically created to contain the value extracted.
- Extract the value from. Extract the value from either the body, the headers of the server response or the content of a NeoLoad variable. Extracting a variable from the content of another variable, allows extracting a content in several steps. First extract a part of the response based on a regular expression, then use another regular expression to extract a part of that.
The extractors are ordered and executed in the order they are defined. You can re-order the extractors using the arrow buttons.
Extracting using an XPath expression is only available for HTML and XML responses, as well as for SOAP, GWT, Adobe Flex/AMF, Oracle Forms, Java Serialization, RTMP, Siebel and Silverlight responses.- Starts with. The phrase in the server response appearing immediately before the value to be extracted.
- Followed by. The definition of the string main body. The extracted string is the concatenation of all the parts selected for extraction.
- Ends with. The phrase in the server response appearing immediately after the value to be extracted.
- Occurrence to extract in the page. If the definition is matched more than once, select the occurrence to be used. The default value is 1 (use the first occurrence) but you can choose to use a random occurrence or all occurrences (useful with loops).
If you choose to process all the matched occurrences, the following variables are automatically created:
- <VariableName>_matchNr - the number of occurrences found; can be 0.
- <VariableName>_n, where n = 1,2,3 and so on. - the strings as generated by the value template.
- <VariableName>_n_gm, where m=0,1,2 - the groups matching n.
- <VariableName> - always attached to the default value.
- <VariableName>_rand, random string from generated strings.
- <VariableName>_rand_gm, where m=0,1,2 - the groups matching rand.
- Value is encoded as. When this option is checked, a decoder is applied on the value before it is placed in the variable. You can choose between HTML, URL and Custom decoding.
Example with HTML: With the string start&end extracted from the server response, the value in the NeoLoad variable will be start&end if the option is checked, and start&end if the option is not checked.
- Edit decoder. When you have selected Value is encoded as "Custom", click this button to provide the decoding logic in JavaScript that you want to be used to decode the extracted value.
Information: When switching to advanced mode, the definition is automatically converted from simple to advanced.
- Definition (advanced mode). Extraction is carried out on the server response using a regular expression.
- Variable name. The name of the variable automatically created to contain the value extracted.
- Extract the value from. Extract the value from either the body of the server response, XML nodes using XPath expression, the headers of the server response or the content of a NeoLoad variable. Extracting a variable from the content of another variable, allows extracting a content in several steps. First extract a part of the response based on a regular expression, then use another regular expression to extract a part of it.
The extractors are ordered and executed in the order they are defined. You can re-order the extractors using the arrow buttons.
Extracting using an XPath expression is only available for HTML and XML responses, as well as for SOAP, GWT, Adobe Flex/AMF, Oracle Forms, Java Serialization, RTMP, Siebel and Silverlight responses.- Regular expression to match. The regular expression used to extract the value. Within the expression, the parts to be extracted must be enclosed in brackets (valid: value="(.+?)", invalid: value=".+?"). See Regular expressions.
- Occurrence to extract in the page. If the definition is matched more than once, select the occurrence to be used. The default value is 1 (use the first occurrence) but you can choose to use a random occurrence or all occurrences (useful with loops).
If you choose to process all the matched occurrences, the following variables are automatically created:
- <VariableName>_matchNr - the number of occurrences found; can be 0.
- <VariableName>_n, where n = 1,2,3 and so on. - the strings as generated by the value template.
- <VariableName>_n_gm, where m=0,1,2 - the groups matching n.
- <VariableName> - always attached to the default value.
- <VariableName>_rand, random string from generated strings.
- <VariableName>_rand_gm, where m=0,1,2 - the groups matching rand.
- Value template. The template used to construct the value. This is an arbitrary string containing special elements that refer to groups within the regular expression (a group is a dynamic portion of the regular expression set within brackets): $0$ refers to the entire text matching the expression, $1$ refers to group 1, $2$ refers to group 2, and so on. Using an illegal group will cause the extraction to fail and the value <NL-Illegal-groupIndex> will be set in the variable during the test. This typically arises when no brackets are specified in the regular expression to be matched.
- Value is encoded as. When this option is checked, a decoder is applied on the value before it is placed in the variable. You can choose between HTML, URL and Custom decoding.
Example with HTML: With the string start&end extracted from the server response, the value in the NeoLoad variable will be start&end if the option is checked, and start&end if the option is not checked.
- Edit decoder. When you have selected Value is encoded as "Custom", click this button to provide the decoding logic in JavaScript that you want to be used to decode the extracted value.
Information: When switching to simple mode, the last simple definition is used, since advanced-simple conversion is impossible.
- Stop extraction at the first match. This option allows considering the first value extracted for a looping request. When this option is selected, the variable extractor is stopped as soon as an extraction is done. The behavior is local to every Virtual User.
- Predictable randomization. When this option is selected, randomly generated values have comparable values for two identical tests. Randomization returns the same values set per Virtual User.
- Test. This tab allows testing the variable extractor. Enter the text corresponding to the server response in the text box. The value extracted from page field value contains the value extracted from the page.
- Errors. This panel allows specifying the action to take if the definition is not matched in the server response. Two choices are available:
- Set a default value for the variable.
- Treat as an assertion failure, thus causing the request to be error-flagged in the test results.
- Response content. The server response content. Only the text content (text/html, text/xml, and so on) is available.
- Automatic replacement. When a variable extractor is created, NeoLoad automatically searches the subsequent requests for the extracted value. If the value is found, NeoLoad proposes to replace it with the extracted variable. See Variable correlation.
Example of a variable extractor
- Extracting from the server response body. Given the following content Your order number Mr Smith is:12345 and that the string to be extracted is 12345 to be used in a subsequent request.
The Variable Extractor is defined with:
- Variable name: "MyVariable"
- Extract from: "Message body"
- Regular expression to be matched: "Your order number(.+)? is:([0-9]+);"
- Value template: "$2$" as it is the order number that must be extracted and not the name of the person.
- Occurrence within the page: "1"
- Use $1$ to obtain the name. ($0$ would return the complete matched text: "Your order number Mr Smith is:12345;")
- Default value: "-1" for example.
- Extracting from the server response header: The Variable Extractor is defined thus:
- Extract from: "Header"
- Regular expression to be matched: "MyHeader: (.*)"
- Occurrence within page: "1"
- Value template:"$1$"
Home