Class DslJsonExtractor
- 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<DslJsonExtractor>
-
- us.abstracta.jmeter.javadsl.core.postprocessors.DslJsonExtractor
-
- All Implemented Interfaces:
DslTestElement,DslTestPlan.TestPlanChild,DslPostProcessor,BaseSampler.SamplerChild,MultiLevelTestElement,BaseThreadGroup.ThreadGroupChild
public class DslJsonExtractor extends DslVariableExtractor<DslJsonExtractor>
Allows extracting part of a JSON response using JMESPath or JSONPath to store into a variable.By default, the extractor is configured to use JMESPath and to extract from the main sample (does not include sub samples) response body the first match of the JMESPath. If no match is found, then variable will be assigned empty string.
- Since:
- 0.28
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslJsonExtractor.CodeBuilderstatic classDslJsonExtractor.JsonQueryLanguageSpecifies the query language used to extract from JSON.-
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 Stringqueryprotected DslJsonExtractor.JsonQueryLanguagequeryLanguage-
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 DslJsonExtractor(String varName, String query)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.jmeter.testelement.TestElementbuildTestElement()DslJsonExtractordefaultValue(String defaultValue)Sets the default value to be stored in the JMeter variable when no match is found.DslJsonExtractormatchNumber(int matchNumber)Sets the match number to be extracted.DslJsonExtractorqueryLanguage(DslJsonExtractor.JsonQueryLanguage queryLanguage)Allows selecting the query language to use for extracting values from a given JSON.-
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
-
query
protected String query
-
queryLanguage
protected DslJsonExtractor.JsonQueryLanguage queryLanguage
-
-
Method Detail
-
matchNumber
public DslJsonExtractor matchNumber(int matchNumber)
Sets the match number to be extracted.For example, if a response looks like this:
[{"name":"test"},{"name":"tester"}]and you use[].nameas JMESPath, 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 and usage.
-
defaultValue
public DslJsonExtractor defaultValue(String defaultValue)
Sets the default value to be stored in the JMeter variable when no match is found.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 be assigned to empty string.
- Parameters:
defaultValue- specifies the default value to be used.- Returns:
- the extractor for further configuration and usage.
-
queryLanguage
public DslJsonExtractor queryLanguage(DslJsonExtractor.JsonQueryLanguage queryLanguage)
Allows selecting the query language to use for extracting values from a given JSON.- Parameters:
queryLanguage- specifies the query language to use to extracting values. When no value is specified, JMESPath is used by default.- Returns:
- the extractor for further configuration and usage.
- Since:
- 1.12
- See Also:
DslJsonExtractor.JsonQueryLanguage
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
-