Class DslRegexExtractor
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
-
- us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement<T>
-
- us.abstracta.jmeter.javadsl.core.postprocessors.DslVariableExtractor<DslRegexExtractor>
-
- us.abstracta.jmeter.javadsl.core.postprocessors.DslRegexExtractor
-
- All Implemented Interfaces:
DslTestElement,DslTestPlan.TestPlanChild,DslPostProcessor,BaseSampler.SamplerChild,MultiLevelTestElement,BaseThreadGroup.ThreadGroupChild
public class DslRegexExtractor extends DslVariableExtractor<DslRegexExtractor>
Allows extracting part of a request or response using regular expressions to store into a variable.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.
- Since:
- 0.8
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslRegexExtractor.CodeBuilderstatic classDslRegexExtractor.TargetFieldUsed to specify the field the regular extractor will apply to.-
Nested classes/interfaces inherited from class us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement
DslScopedTestElement.Scope, DslScopedTestElement.ScopedTestElementCallBuilder<T extends org.apache.jmeter.testelement.TestElement>
-
-
Field Summary
Fields Modifier and Type Field Description protected DslRegexExtractor.TargetFieldfieldToCheckprotected Stringregexprotected Stringtemplate-
Fields inherited from class us.abstracta.jmeter.javadsl.core.postprocessors.DslVariableExtractor
defaultValue, matchNumber, varName
-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement
scope, scopeVariable
-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
guiClass, name
-
-
Constructor Summary
Constructors Constructor Description DslRegexExtractor(String varName, String regex)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.jmeter.testelement.TestElementbuildTestElement()DslRegexExtractordefaultValue(String defaultValue)Sets the default value to be stored in the JMeter variable when the regex does not match.DslRegexExtractorfieldToCheck(DslRegexExtractor.TargetField fieldToCheck)Allows specifying what part of request or response to apply the regular extractor to.DslRegexExtractormatchNumber(int matchNumber)Sets the match number to be extracted.DslRegexExtractortemplate(String template)Specifies the final string to store in the JMeter Variable.-
Methods inherited from class us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement
scope, scopeVariable, setScopeTo
-
Methods inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
buildConfiguredTestElement, buildTestElementGui, buildTreeUnder, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGui
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface us.abstracta.jmeter.javadsl.core.DslTestElement
buildTreeUnder, showInGui
-
-
-
-
Field Detail
-
regex
protected String regex
-
template
protected String template
-
fieldToCheck
protected DslRegexExtractor.TargetField fieldToCheck
-
-
Method Detail
-
matchNumber
public DslRegexExtractor matchNumber(int matchNumber)
Sets the match number to be extracted.For example, if a response looks like this:
and you useuser=test&user=testeruser=([^&]+)as regular expression, first match (1) would extracttestand second match (2) would extracttester.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>.- Parameters:
matchNumber- specifies the match number to use.- Returns:
- the extractor for further configuration or usage.
-
template
public DslRegexExtractor template(String template)
Specifies the final string to store in the JMeter Variable.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:
And you useemail=tester@abstracta.ususer=([^&]+)as regular expression. Then$1$-$2$will result in storing in the specified JMeter variable the valuetester-abstracta.When not specified
$1$will be used.- Parameters:
template- specifies template to use for storing in the JMeter variable.- Returns:
- the extractor for further configuration or usage.
-
defaultValue
public DslRegexExtractor defaultValue(String defaultValue)
Sets the default value to be stored in the JMeter variable when the regex does not match.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.
- Parameters:
defaultValue- specifies the default value to be used.- Returns:
- the extractor for further configuration or usage.
-
fieldToCheck
public DslRegexExtractor fieldToCheck(DslRegexExtractor.TargetField fieldToCheck)
Allows specifying what part of request or response to apply the regular extractor to.When not specified then the regular extractor will be applied to the response body.
- Parameters:
fieldToCheck- field to apply the regular extractor to.- Returns:
- the extractor for further configuration or usage.
- See Also:
DslRegexExtractor.TargetField
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
-