public class DslRegexExtractor extends DslVariableExtractor<DslRegexExtractor>
By default, the regular extractor is configured to extract from the main sample (does not include sub samples) response body the first capturing group (part of regular expression that is inside of parenthesis) of the first match of the regex. If no match is found, then the variable will not be created or modified.
| Modifier and Type | Class and Description |
|---|---|
static class |
DslRegexExtractor.CodeBuilder |
static class |
DslRegexExtractor.TargetField
Used to specify the field the regular extractor will apply to.
|
DslScopedTestElement.Scope, DslScopedTestElement.ScopedTestElementCallBuilder<T extends org.apache.jmeter.testelement.TestElement>| Modifier and Type | Field and Description |
|---|---|
protected DslRegexExtractor.TargetField |
fieldToCheck |
protected String |
regex |
protected String |
template |
defaultValue, matchNumber, varNamescope, scopeVariableguiClass, name| Constructor and Description |
|---|
DslRegexExtractor(String varName,
String regex) |
| Modifier and Type | Method and Description |
|---|---|
protected org.apache.jmeter.testelement.TestElement |
buildTestElement() |
DslRegexExtractor |
defaultValue(String defaultValue)
Sets the default value to be stored in the JMeter variable when the regex does not match.
|
DslRegexExtractor |
fieldToCheck(DslRegexExtractor.TargetField fieldToCheck)
Allows specifying what part of request or response to apply the regular extractor to.
|
DslRegexExtractor |
matchNumber(int matchNumber)
Sets the match number to be extracted.
|
DslRegexExtractor |
template(String template)
Specifies the final string to store in the JMeter Variable.
|
scope, scopeVariable, setScopeTobuildConfiguredTestElement, buildTestElementGui, buildTreeUnder, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGuiclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildTreeUnder, showInGuiprotected String regex
protected String template
protected DslRegexExtractor.TargetField fieldToCheck
public DslRegexExtractor matchNumber(int matchNumber)
For example, if a response looks like this:
user=test&user=tester
and you use user=([^&]+) as regular expression, first match (1) would extract
test and second match (2) would extract tester.
When not specified, the first match will be used. When 0 is specified, a random match will be
used. When negative, all the matches are extracted to variables with name <variableName>_<matchNumber>, the number of matches is stored in <variableName>_matchNr, and default value is assigned to <variableName>.
matchNumber - specifies the match number to use.public DslRegexExtractor template(String template)
The string may contain capturing groups (regular expression segments between parenthesis)
references by using $<groupId>$ expressions (eg: $1$ for first group). Check JMeter
Regular Expression Extractor documentation for more details.
For example, if a response looks like this:
email=tester@abstracta.us
And you use user=([^&]+) as regular expression. Then $1$-$2$ will result in
storing in the specified JMeter variable the value tester-abstracta.
When not specified $1$ will be used.
template - specifies template to use for storing in the JMeter variable.public DslRegexExtractor defaultValue(String defaultValue)
When match number is negative then the value is always assigned to the variable name.
A common pattern is to specify this value to a known value (e.g.: <VAR>_EXTRACTION_FAILURE) and then add some assertion on the variable to mark request as failure when the match doesn't work.
When not specified then the variable will not be set if no match is found.
defaultValue - specifies the default value to be used.public DslRegexExtractor fieldToCheck(DslRegexExtractor.TargetField fieldToCheck)
When not specified then the regular extractor will be applied to the response body.
fieldToCheck - field to apply the regular extractor to.DslRegexExtractor.TargetFieldprotected org.apache.jmeter.testelement.TestElement buildTestElement()
buildTestElement in class BaseTestElementCopyright © 2024. All rights reserved.