public class JmeterDsl extends Object
This class contains factory methods to create DslTestElement instances that allow
specifying test plans and associated test elements (samplers, thread groups, listeners, etc.). If
you want to support new test elements, then you either add them here (if they are considered to
be part of the core of JMeter), or implement another similar class containing only the specifics
of the protocol, repository, or grouping of test elements that you want to build (eg, one might
implement an Http2JMeterDsl class with only http2 test elements' factory methods).
When implement new factory methods consider adding only as parameters the main properties of the
test elements (the ones that makes sense to specify in most of the cases). For the rest of
parameters (the optional ones), prefer them to be specified as methods of the implemented
DslTestElement for such case, in a similar fashion as Builder Pattern.
| Modifier and Type | Method and Description |
|---|---|
static DslBoundaryExtractor |
boundaryExtractor(String variableName,
String leftBoundary,
String rightBoundary)
Builds a Boundary Extractor which allows using left and right boundary texts to extract
different parts of a sample result (request or response).
|
static DslConstantTimer |
constantTimer(Duration duration)
Builds a Constant Timer which pauses the thread with for a given duration.
|
static DslCsvDataSet |
csvDataSet(String csvFile)
Builds a CSV Data Set which allows loading from a CSV file variables to be used in test plan.
|
static DslCsvDataSet |
csvDataSet(TestResource resource)
Same as
csvDataSet(String) but easing usage of test resources. |
static DslDebugPostProcessor |
debugPostProcessor()
Builds a Debug post processor which is helpful to collect debugging information from test plans
executions.
|
static DslDummySampler |
dummySampler(String responseBody)
Builds a JMeter plugin Dummy Sampler which allows emulating a sampler easing testing other
parts of a test plan (like extractors, controllers conditions, etc).
|
static DslDummySampler |
dummySampler(String name,
String responseBody)
Same as
dummySampler(String) but allowing to set a name on the sampler. |
static DslForEachController |
forEachController(String varsPrefix,
String iterationVarName,
BaseThreadGroup.ThreadGroupChild... children)
Builds a For each controller that iterates over a set of variables and runs a given set of
children for each variable in the set.
|
static DslForEachController |
forEachController(String name,
String varsPrefix,
String iterationVarName,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#forEachController(String, String, ThreadGroupChild...) but allowing to set a
name which defines autogenerated variable created by JMeter containing iteration index. |
static ForLoopController |
forLoopController(int count,
BaseThreadGroup.ThreadGroupChild... children)
Builds a Loop Controller that allows to run specific number of times the given children in each
thread group iteration.
|
static ForLoopController |
forLoopController(String count,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#forLoopController(int, ThreadGroupChild...) but allowing to use JMeter
expressions for number of loops |
static ForLoopController |
forLoopController(String name,
int count,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#forLoopController(int, ThreadGroupChild...) but allowing to set a name which
defines autogenerated variable created by JMeter containing iteration index. |
static ForLoopController |
forLoopController(String name,
String count,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#forLoopController(String, ThreadGroupChild...) but allowing to set a name
which defines autogenerated variable created by JMeter containing iteration index. |
static HtmlReporter |
htmlReporter(String reportsDirectory)
Builds an HTML Reporter which allows easily generating HTML reports for test plans.
|
static HtmlReporter |
htmlReporter(String reportsDirectory,
String name)
Builds an HTML Reporter which allows easily generating HTML reports for test plans.
|
static DslAuthManager |
httpAuth()
Builds an Auth manager which simplifies configuration for automatic authentication of HTTP
requests.
|
static DslCacheManager |
httpCache()
Builds a Cache manager at the test plan level which allows configuring caching behavior used by
HTTPRequest samplers.
|
static DslCookieManager |
httpCookies()
Builds a Cookie manager at the test plan level which allows configuring cookies settings used
by HTTPRequest samplers.
|
static DslHttpDefaults |
httpDefaults()
Builds an HTTP request defaults element that allows setting default values used by HTTP
samplers.
|
static HttpHeaders |
httpHeaders()
Builds an HTTP header manager which allows setting HTTP headers to be used by HTTPRequest
samplers.
|
static DslHttpSampler |
httpSampler(Function<DslJsr223PreProcessor.PreProcessorVars,String> urlSupplier)
Builds an HTTP Request sampler to sample HTTP requests with a dynamically calculated URL.
|
static DslHttpSampler |
httpSampler(String url)
Builds an HTTP Request sampler to sample HTTP requests.
|
static DslHttpSampler |
httpSampler(String name,
Function<DslJsr223PreProcessor.PreProcessorVars,String> urlSupplier)
Same as
httpSampler(Function) but allowing to set a name to the HTTP Request sampler. |
static DslHttpSampler |
httpSampler(String name,
String url)
Same as
httpSampler(String) but allowing to set a name to the HTTP Request sampler. |
static DslIfController |
ifController(PropertyScriptBuilder.PropertyScript condition,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#ifController(String, ThreadGroupChild...) but allowing to use Java type safety
and code completion when specifying the condition. |
static DslIfController |
ifController(String condition,
BaseThreadGroup.ThreadGroupChild... children)
Builds an If Controller that allows to conditionally run specified children.
|
static InfluxDbBackendListener |
influxDbListener(String influxDbUrl)
Builds a Backend Listener configured to use InfluxDB to send all results for easy tracing,
historic, comparison and live test results.
|
static DslJsonExtractor |
jsonExtractor(String variableName,
String jmesPath)
Builds a JSON JMESPath Extractor which allows using a JMESPath to extract part of a JSON
response.
|
static DslJsr223PostProcessor |
jsr223PostProcessor(DslJsr223PostProcessor.PostProcessorScript script)
Same as
jsr223PostProcessor(String) but allowing to use Java type safety and code
completion when specifying the script. |
static DslJsr223PostProcessor |
jsr223PostProcessor(String script)
Builds a JSR223 Post Processor which allows including custom logic to process sample results.
|
static DslJsr223PostProcessor |
jsr223PostProcessor(String name,
DslJsr223PostProcessor.PostProcessorScript script)
Same as
jsr223PostProcessor(String, String) but allowing to use Java type safety and
code completion when specifying the script. |
static DslJsr223PostProcessor |
jsr223PostProcessor(String name,
String script)
Same as
jsr223PostProcessor(String) but allowing to set a name on the post processor. |
static DslJsr223PreProcessor |
jsr223PreProcessor(DslJsr223PreProcessor.PreProcessorScript script)
Same as
jsr223PreProcessor(String) but allowing to use Java type safety and code
completion when specifying the script. |
static DslJsr223PreProcessor |
jsr223PreProcessor(String script)
Builds a JSR223 Pre Processor which allows including custom logic to modify requests.
|
static DslJsr223PreProcessor |
jsr223PreProcessor(String name,
DslJsr223PreProcessor.PreProcessorScript script)
Same as
jsr223PreProcessor(String, String) but allowing to use Java type safety and
code completion when specifying the script. |
static DslJsr223PreProcessor |
jsr223PreProcessor(String name,
String script)
Same as
jsr223PreProcessor(String) but allowing to set a name on the preprocessor. |
static DslJsr223Sampler |
jsr223Sampler(DslJsr223Sampler.SamplerScript script)
Same as
jsr223Sampler(String) but allowing to use Java type safety and code completion
when specifying the script. |
static DslJsr223Sampler |
jsr223Sampler(String script)
Builds a JSR223 Sampler which allows sampling any Java API or custom logic.
|
static DslJsr223Sampler |
jsr223Sampler(String name,
DslJsr223Sampler.SamplerScript script)
Same as
jsr223Sampler(String, String) but allowing to use Java type safety and code
completion when specifying the script. |
static DslJsr223Sampler |
jsr223Sampler(String name,
String script)
Same as
jsr223Sampler(String) but allowing to set a name on the sampler. |
static JtlWriter |
jtlWriter(String directory)
Builds a Simple Data Writer to write all collected results to a JTL file.
|
static JtlWriter |
jtlWriter(String directory,
String fileName)
Builds a Simple Data Writer to write all collected results to a JTL file.
|
static DslOnceOnlyController |
onceOnlyController(BaseThreadGroup.ThreadGroupChild... children)
Builds a Once Only Controller that allows running a part of a test plan only once and only on
the first iteration of each thread group.
|
static PercentController |
percentController(float percent,
BaseThreadGroup.ThreadGroupChild... children)
Builds a Percent Controller to execute children only a given percent of times.
|
static PercentController |
percentController(String percent,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#percentController(float, ThreadGroupChild...) but allowing using JMeter
expressions (eg: ${PERCENT_VAR}) in percent parameter. |
static DslRegexExtractor |
regexExtractor(String variableName,
String regex)
Builds a Regex Extractor which allows using regular expressions to extract different parts of a
sample result (request or response).
|
static DslResponseAssertion |
responseAssertion()
Builds a Response Assertion to be able to check that obtained sample result is the expected
one.
|
static DslResponseAssertion |
responseAssertion(String name)
Same as
responseAssertion() but allowing to set a name on the assertion, which can be
later used to identify assertion results and differentiate it from other assertions. |
static ResponseFileSaver |
responseFileSaver(String fileNamePrefix)
Builds a Response File Saver to generate a file for each response of a sample.
|
static DslViewResultsTree |
resultsTreeVisualizer()
Builds a View Results Tree element to show live results in a pop-up window while the test
runs.
|
static RpsThreadGroup |
rpsThreadGroup()
Builds a thread group that dynamically adapts thread count and pauses to match a given RPS.
|
static RpsThreadGroup |
rpsThreadGroup(String name)
Same as
rpsThreadGroup() but allowing to set a name on the thread group. |
static DslRuntimeController |
runtimeController(Duration duration,
BaseThreadGroup.ThreadGroupChild... children)
Builds a Runtime Controller that stops executing child elements when a period of time expires.
|
static DslRuntimeController |
runtimeController(String seconds,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#runtimeController(Duration, ThreadGroupChild...) but allowing to use JMeter
expressions for the duration. |
static DslSetupThreadGroup |
setupThreadGroup()
Builds a setup thread group which allows tuning settings before setting its children.
|
static DslSetupThreadGroup |
setupThreadGroup(BaseThreadGroup.ThreadGroupChild... children)
Builds a thread group that allows running logic before other thread groups.
|
static DslSetupThreadGroup |
setupThreadGroup(String name)
Same as
setupThreadGroup() but allowing to set a name on the thread group. |
static DslSetupThreadGroup |
setupThreadGroup(String name,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#setupThreadGroup(ThreadGroupChild...) but allowing to set a name on the thread
group. |
static DslTeardownThreadGroup |
teardownThreadGroup()
Builds a teardown thread group which allows tuning settings before setting its children.
|
static DslTeardownThreadGroup |
teardownThreadGroup(BaseThreadGroup.ThreadGroupChild... children)
Builds a thread group that allows running logic after other thread groups.
|
static DslTeardownThreadGroup |
teardownThreadGroup(String name)
Same as
teardownThreadGroup() but allowing to set a name on the thread group. |
static DslTeardownThreadGroup |
teardownThreadGroup(String name,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#teardownThreadGroup(ThreadGroupChild...) but allowing to set a name on the
thread group. |
static DslTestPlan |
testPlan(DslTestPlan.TestPlanChild... children)
Builds a new test plan.
|
static TestResource |
testResource(String resourcePath)
Allows easy usage of test resources like the ones in
src/test/resource in maven
projects. |
static DslDefaultThreadGroup |
threadGroup()
Builds a new thread group without any thread configuration.
|
static DslDefaultThreadGroup |
threadGroup(int threads,
Duration duration,
BaseThreadGroup.ThreadGroupChild... children)
Builds a new thread group with a given number of threads & their duration.
|
static DslDefaultThreadGroup |
threadGroup(int threads,
int iterations,
BaseThreadGroup.ThreadGroupChild... children)
Builds a new thread group with a given number of threads & iterations.
|
static DslDefaultThreadGroup |
threadGroup(String name)
Same as
threadGroup() but allowing to set a name on the thread group. |
static DslDefaultThreadGroup |
threadGroup(String name,
int threads,
Duration duration,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#threadGroup(int, Duration, ThreadGroupChild...) but allowing to set a name on
the thread group. |
static DslDefaultThreadGroup |
threadGroup(String name,
int threads,
int iterations,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#threadGroup(int, int, ThreadGroupChild...) but allowing to set a name on the
thread group. |
static DslThroughputTimer |
throughputTimer(double throughputPerMinute)
Builds a Constant Throughput Timer which paces samplers to limit the throughput.
|
static DslTransactionController |
transaction(String name,
BaseThreadGroup.ThreadGroupChild... children)
Builds a new transaction controller with the given name.
|
static DslUniformRandomTimer |
uniformRandomTimer(Duration minimum,
Duration maximum)
Builds a Uniform Random Timer which pauses the thread with a random time with uniform
distribution.
|
static DslVariables |
vars()
Builds a DslVariables that allows to easily initialize or update JMeter variables.
|
static DslWeightedSwitchController |
weightedSwitchController()
Builds a Controller which executes in each iteration choosing one child according to given
weights.
|
static DslWhileController |
whileController(PropertyScriptBuilder.PropertyScript condition,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#whileController(String, ThreadGroupChild...) but allowing to use Java type
safety and code completion when specifying the condition. |
static DslWhileController |
whileController(String condition,
BaseThreadGroup.ThreadGroupChild... children)
Builds a While Controller that allows to run specific part of the test plan while a given
condition is met in one thread iteration.
|
static DslWhileController |
whileController(String name,
PropertyScriptBuilder.PropertyScript condition,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#whileController(PropertyScript, ThreadGroupChild...) but allowing to set a
name which defines autogenerated variable created by JMeter containing iteration index. |
static DslWhileController |
whileController(String name,
String condition,
BaseThreadGroup.ThreadGroupChild... children)
Same as
#whileController(String, ThreadGroupChild...) but allowing to set a name which
defines autogenerated variable created by JMeter containing iteration index. |
public static DslTestPlan testPlan(DslTestPlan.TestPlanChild... children)
children - specifies the list of test elements that compose the test plan.DslTestPlanpublic static DslDefaultThreadGroup threadGroup(int threads, int iterations, BaseThreadGroup.ThreadGroupChild... children)
threads - specifies the number of threads to simulate concurrent virtual users.iterations - specifies the number of iterations that each virtual user will run of
children elements until it stops.
If you specify -1, then threads will iterate until test plan execution is interrupted (you manually stop the running process, there is an error and thread group is configured to stop on error, or some other explicit termination condition).
Setting this property to -1 is in general not advised, since you might inadvertently end up running a test plan without limits consuming unnecessary computing power. Prefer specifying a big value as a safe limit for iterations or duration instead.
children - contains the test elements that each thread will execute in each iteration.DslDefaultThreadGrouppublic static DslDefaultThreadGroup threadGroup(String name, int threads, int iterations, BaseThreadGroup.ThreadGroupChild... children)
#threadGroup(int, int, ThreadGroupChild...) but allowing to set a name on the
thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
#threadGroup(int, int, ThreadGroupChild...)public static DslDefaultThreadGroup threadGroup(int threads, Duration duration, BaseThreadGroup.ThreadGroupChild... children)
threads - to simulate concurrent virtual users.duration - to keep each thread running for this period of time. Take into consideration
that JMeter supports specifying duration in seconds, so if you specify a
smaller granularity (like milliseconds) it will be rounded up to seconds.children - contains the test elements that each thread will execute until specified
duration is reached.ThreadGrouppublic static DslDefaultThreadGroup threadGroup(String name, int threads, Duration duration, BaseThreadGroup.ThreadGroupChild... children)
#threadGroup(int, Duration, ThreadGroupChild...) but allowing to set a name on
the thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
#threadGroup(int, Duration, ThreadGroupChild...)public static DslDefaultThreadGroup threadGroup()
This method should be used as starting point for creating complex test thread profiles (like
spike, or incremental tests) in combination with holdFor, rampTo and rampToAndHold
DslDefaultThreadGroup methods.
Eg:
threadGroup()
.rampTo(10, Duration.ofSeconds(10))
.rampTo(5, Duration.ofSeconds(10))
.rampToAndHold(20, Duration.ofSeconds(5), Duration.ofSeconds(10))
.rampTo(0, Duration.ofSeconds(5))
.children(...)
For complex thread profiles that can't be mapped to JMeter built-in thread group element, the DSL uses Ultimate Thread Group plugin.
public static DslDefaultThreadGroup threadGroup(String name)
threadGroup() but allowing to set a name on the thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
threadGroup()public static DslSetupThreadGroup setupThreadGroup(BaseThreadGroup.ThreadGroupChild... children)
This is usually used to run some setup logic before the actual test plan logic. In particular logic that needs to be run within the context of JMeter test (eg: requires setting some JMeter property) or needs to be run from same machines as the test plan.
Check DslSetupThreadGroup for more details and configuration options.
children - test elements to be run before any other thread group.DslSetupThreadGrouppublic static DslSetupThreadGroup setupThreadGroup(String name, BaseThreadGroup.ThreadGroupChild... children)
#setupThreadGroup(ThreadGroupChild...) but allowing to set a name on the thread
group.
Setting a proper name allows to properly identify the requests generated in each thread group.
DslSetupThreadGrouppublic static DslSetupThreadGroup setupThreadGroup()
This method allows for example setting the number of iterations and threads to be used by the thread group, before setting children elements.
DslSetupThreadGrouppublic static DslSetupThreadGroup setupThreadGroup(String name)
setupThreadGroup() but allowing to set a name on the thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
DslSetupThreadGrouppublic static DslTeardownThreadGroup teardownThreadGroup(BaseThreadGroup.ThreadGroupChild... children)
This is usually used to run some clean up logic after the actual test plan logic. In particular logic that needs to be run within the context of JMeter test (eg: requires setting some JMeter property) or needs to be run from same machines as the test plan.
Check DslTeardownThreadGroup for more details and configuration options.
children - test elements to be run after any other thread group.DslTeardownThreadGrouppublic static DslTeardownThreadGroup teardownThreadGroup(String name, BaseThreadGroup.ThreadGroupChild... children)
#teardownThreadGroup(ThreadGroupChild...) but allowing to set a name on the
thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
DslTeardownThreadGrouppublic static DslTeardownThreadGroup teardownThreadGroup()
This method allows for example setting the number of iterations and threads to be used by the thread group, before setting children elements.
DslTeardownThreadGrouppublic static DslTeardownThreadGroup teardownThreadGroup(String name)
teardownThreadGroup() but allowing to set a name on the thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
DslTeardownThreadGrouppublic static RpsThreadGroup rpsThreadGroup()
Internally this element uses Concurrency Thread Group in combination with Throughput Shaping Timer.
Eg:
rpsThreadGroup()
.maxThreads(500)
.rampTo(20, Duration.ofSeconds(10))
.rampTo(10, Duration.ofSeconds(10))
.rampToAndHold(1000, Duration.ofSeconds(5), Duration.ofSeconds(10))
.rampTo(0, Duration.ofSeconds(5))
.children(...)
RpsThreadGrouppublic static RpsThreadGroup rpsThreadGroup(String name)
rpsThreadGroup() but allowing to set a name on the thread group.
Setting a proper name allows to properly identify the requests generated in each thread group.
rpsThreadGroup()public static DslTransactionController transaction(String name, BaseThreadGroup.ThreadGroupChild... children)
name - specifies the name to identify the transaction.children - contains the test elements that will be contained within the transaction.DslTransactionControllerpublic static DslIfController ifController(String condition, BaseThreadGroup.ThreadGroupChild... children)
condition - contains an expression that when evaluated to true tells the controller to run
specified children.children - contains the test plan elements to execute when the condition is true.DslIfControllerpublic static DslIfController ifController(PropertyScriptBuilder.PropertyScript condition, BaseThreadGroup.ThreadGroupChild... children)
#ifController(String, ThreadGroupChild...) but allowing to use Java type safety
and code completion when specifying the condition.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using #ifController(String, ThreadGroupChild...) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
PropertyScriptBuilder.PropertyScript,
#ifController(String, ThreadGroupChild...)public static DslWhileController whileController(String condition, BaseThreadGroup.ThreadGroupChild... children)
JMeter generates __jm__while__idx variable containing the iteration number (0 indexed),
which can be helpful in some scenarios.
condition - contains an expression that will be evaluated to identify when to stop
looping.children - contains the test plan elements to execute while the condition is true.DslWhileControllerpublic static DslWhileController whileController(String name, String condition, BaseThreadGroup.ThreadGroupChild... children)
#whileController(String, ThreadGroupChild...) but allowing to set a name which
defines autogenerated variable created by JMeter containing iteration index.name - specifies the name to assign to the controller. This variable affects the
JMeter autogenerated variable __jm__<controllerName>__idx which holds
the loop iteration number (starting at 0).condition - contains an expression that will be evaluated to identify when to stop
looping.children - contains the test plan elements to execute while the condition is true.DslWhileController,
#whileController(String, ThreadGroupChild...)public static DslWhileController whileController(PropertyScriptBuilder.PropertyScript condition, BaseThreadGroup.ThreadGroupChild... children)
#whileController(String, ThreadGroupChild...) but allowing to use Java type
safety and code completion when specifying the condition.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using #whileController(String, ThreadGroupChild...) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So, make sure that provided logic is thread safe.
JMeter generates __jm__while__idx variable containing the iteration number (0 indexed),
which can be helpful in some scenarios.
condition - contains java code that will be evaluated to identify when to stop looping.children - contains the test plan elements to execute while the condition is true.PropertyScriptBuilder.PropertyScript,
#whileController(String, ThreadGroupChild...)public static DslWhileController whileController(String name, PropertyScriptBuilder.PropertyScript condition, BaseThreadGroup.ThreadGroupChild... children)
#whileController(PropertyScript, ThreadGroupChild...) but allowing to set a
name which defines autogenerated variable created by JMeter containing iteration index.name - specifies the name to assign to the controller. This variable affects the
JMeter autogenerated variable __jm__<controllerName>__idx which holds
the loop iteration number (starting at 0).condition - contains java code that will be evaluated to identify when to stop looping.children - contains the test plan elements to execute while the condition is true.PropertyScriptBuilder.PropertyScript,
#whileController(PropertyScript, ThreadGroupChild...)public static ForLoopController forLoopController(int count, BaseThreadGroup.ThreadGroupChild... children)
Eg: if a thread group iterates 3 times and the Loop Controller is configured to 5, then the
children elements will run 3*5=15 times for each thread.
JMeter generates __jm__for__idx variable containing the iteration number (0 indexed),
which can be helpful in some scenarios.
count - specifies the number of times to execute the children elements in each thread
group iteration.children - contains the test plan elements to execute the given number of times in each
thread group iteration.ForLoopControllerpublic static ForLoopController forLoopController(String name, int count, BaseThreadGroup.ThreadGroupChild... children)
#forLoopController(int, ThreadGroupChild...) but allowing to set a name which
defines autogenerated variable created by JMeter containing iteration index.name - specifies the name to assign to the controller. This variable affects the
JMeter autogenerated variable __jm__<controllerName>__idx which holds
the loop iteration number (starting at 0).count - specifies the number of times to execute the children elements in each thread
group iteration.children - contains the test plan elements to execute the given number of times in each
thread group iteration.ForLoopController,
#forLoopController(int, ThreadGroupChild...)public static ForLoopController forLoopController(String count, BaseThreadGroup.ThreadGroupChild... children)
#forLoopController(int, ThreadGroupChild...) but allowing to use JMeter
expressions for number of loops
This method allows, for example, to extract from a previous response the number of times to execute some part of the test plan and use it in forLoop with something like
"${LOOPS_COUNT}".count - specifies a JMeter expression which evaluates to a number specifying the number
of times to execute the children elements in each thread group iteration..children - contains the test plan elements to execute the given number of times in each
thread group iteration.#forLoopController(int, ThreadGroupChild...)public static ForLoopController forLoopController(String name, String count, BaseThreadGroup.ThreadGroupChild... children)
#forLoopController(String, ThreadGroupChild...) but allowing to set a name
which defines autogenerated variable created by JMeter containing iteration index.name - specifies the name to assign to the controller. This variable affects the
JMeter autogenerated variable __jm__<controllerName>__idx which holds
the loop iteration number (starting at 0).count - specifies a JMeter expression which evaluates to a number specifying the number
of times to execute the children elements in each thread group iteration..children - contains the test plan elements to execute the given number of times in each
thread group iteration.ForLoopController,
#forLoopController(int, ThreadGroupChild...)public static DslForEachController forEachController(String varsPrefix, String iterationVarName, BaseThreadGroup.ThreadGroupChild... children)
This is usually used in combination with extractors that return more than one variable (like regex extractor with -1 index), to iterate over generated variables.
JMeter generates __jm__<iterationVarName>__idx variable containing the iteration number
(0 indexed), which can be helpful in some scenarios.
varsPrefix - specifies the variable prefix of the set of variables to iterate over.
This will be suffixed by underscore and the iteration index number (eg:
my_var_0) to get the actual variable and store its value in a variable
with name specified by iterationVarName.iterationVarName - specifies the name of the variable to store the value assigned to the
variable of current iteration. eg: the value of my_var_0 when first
iteration and my_var is set as varsPrefix.children - contains the test plan elements to execute for the given set of
variables.DslForEachControllerpublic static DslForEachController forEachController(String name, String varsPrefix, String iterationVarName, BaseThreadGroup.ThreadGroupChild... children)
#forEachController(String, String, ThreadGroupChild...) but allowing to set a
name which defines autogenerated variable created by JMeter containing iteration index.name - specifies the name to assign to the controller. This variable affects
the JMeter autogenerated variable __jm__<controllerName>__idx
which holds the loop iteration number (starting at 0).varsPrefix - specifies the variable prefix of the set of variables to iterate over.
This will be suffixed by underscore and the iteration index number (eg:
my_var_0) to get the actual variable and store its value in a variable
with name specified by iterationVarName.iterationVarName - specifies the name of the variable to store the value assigned to the
variable of current iteration. eg: the value of my_var_0 when first
iteration and my_var is set as varsPrefix.children - contains the test plan elements to execute the given number of times in
each thread group iteration.DslForEachController,
#forEachController(String, String, ThreadGroupChild...)public static DslOnceOnlyController onceOnlyController(BaseThreadGroup.ThreadGroupChild... children)
Eg: if a thread group iterates 3 times and contains few samplers inside the Once Only Controller, then children elements will run 1 time for each thread.
children - contains the test plan elements to execute only one time on first iteration of
each thread group.DslOnceOnlyControllerpublic static DslRuntimeController runtimeController(Duration duration, BaseThreadGroup.ThreadGroupChild... children)
This can be very useful to implement some time based logic like refreshing a token after certain time while doing http requests (runtimeController + whileController).
The controller executes each child sequentially until there are no more children to execute or the time has expired.
Child elements execution is not interrupted, the controller just checks on each child execution ending if the time has expired, and if so, don't execute the rest of its child elements.
duration - defines de duration after which no further child elements will be executed (on
each iteration). Take into consideration that JMeter supports specifying
duration in seconds, so if you specify a smaller granularity (like
milliseconds) it will be rounded up to seconds.children - contains the child elements to execute.DslRuntimeControllerpublic static DslRuntimeController runtimeController(String seconds, BaseThreadGroup.ThreadGroupChild... children)
#runtimeController(Duration, ThreadGroupChild...) but allowing to use JMeter
expressions for the duration.seconds - defines a JMeter expression that evaluates to a number of seconds the runtime
controller will execute child elements for.children - contains the child elements to execute.#runtimeController(Duration, ThreadGroupChild...),
DslRuntimeControllerpublic static PercentController percentController(float percent, BaseThreadGroup.ThreadGroupChild... children)
Internally, this uses a JMeter Throughput Controller with executions percentage configuration.
percent - defines a number between 0 and 100 that defines the percentage of times to
execute given children elements.children - holds test plan elements to execute when for the given percent of times.PercentControllerpublic static PercentController percentController(String percent, BaseThreadGroup.ThreadGroupChild... children)
#percentController(float, ThreadGroupChild...) but allowing using JMeter
expressions (eg: ${PERCENT_VAR}) in percent parameter.
This might be useful to set percents according to different profiles, for example, using different percents in production vs staging tests
percent - defines a JMeter expression that evaluates to a number between 0 and 100 that
defines the percentage of times to execute given children elements.children - holds test plan elements to execute when for the given percent of times.public static DslWeightedSwitchController weightedSwitchController()
Internally this uses BlazeMeter Weighted Switch Controller plugin.
DslWeightedSwitchControllerpublic static DslHttpSampler httpSampler(String url)
url - specifies URL the HTTP Request sampler will hit.DslHttpSamplerpublic static DslHttpSampler httpSampler(Function<DslJsr223PreProcessor.PreProcessorVars,String> urlSupplier)
This method is just an abstraction that uses a JMeter variable as URL and calculates the variable with a jsr223PreProcessor, added as first child of the HTTP Request Sampler.
WARNING: As this method internally uses
#jsr223PreProcessor(PreProcessorScript), same limitations and considerations apply.
Check its documentation. To avoid such limitations you may just use
httpSampler(String) instead, using a JMeter variable and
jsr223PreProcessor(String) to dynamically set the variable.
urlSupplier - specifies URL the HTTP Request sampler will hit.DslHttpSampler,
#jsr223PreProcessor(PreProcessorScript)public static DslHttpSampler httpSampler(String name, String url)
httpSampler(String) but allowing to set a name to the HTTP Request sampler.
Setting a proper name allows to easily identify the requests generated by this sampler and check its particular statistics.
httpSampler(String)public static DslHttpSampler httpSampler(String name, Function<DslJsr223PreProcessor.PreProcessorVars,String> urlSupplier)
httpSampler(Function) but allowing to set a name to the HTTP Request sampler.
Setting a proper name allows to easily identify the requests generated by this sampler and check its particular statistics.
WARNING: As this method internally uses
#jsr223PreProcessor(PreProcessorScript), same limitations and considerations apply.
Check its documentation To avoid such limitations you may just use
httpSampler(String, String) instead, using a JMeter variable and
jsr223PreProcessor(String) to dynamically set the variable.
httpSampler(Function)public static HttpHeaders httpHeaders()
HttpHeaderspublic static DslHttpDefaults httpDefaults()
In general, prefer using Java variables or custom builder methods to abstract common logic for samplers which allows for easier debugging, readability and traceability. In some cases though it might be shorter/simpler to just use and httpDefaults element.
public static DslCookieManager httpCookies()
DslCookieManagerpublic static DslCacheManager httpCache()
DslCacheManagerpublic static DslAuthManager httpAuth()
DslAuthManagerpublic static DslVariables vars()
This internally uses User Defined Variables when placed as test plan child and JSR223 Samplers otherwise.
DslVariablespublic static DslJsr223Sampler jsr223Sampler(String script)
script - contains the script to be use while sampling. By default, this will be a groovy
script, but you can change it by setting the language property in the returned
post processor.DslJsr223Samplerpublic static DslJsr223Sampler jsr223Sampler(String name, String script)
jsr223Sampler(String) but allowing to set a name on the sampler.
The name is used in collected samples to easily identify their results and as logger name which allows configuring log level, appender, etc., for the sampler.
jsr223Sampler(String)public static DslJsr223Sampler jsr223Sampler(DslJsr223Sampler.SamplerScript script)
jsr223Sampler(String) but allowing to use Java type safety and code completion
when specifying the script.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using jsr223Sampler(String) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
DslJsr223Sampler.SamplerScript,
jsr223Sampler(String)public static DslJsr223Sampler jsr223Sampler(String name, DslJsr223Sampler.SamplerScript script)
jsr223Sampler(String, String) but allowing to use Java type safety and code
completion when specifying the script.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using jsr223Sampler(String) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
DslJsr223Sampler.SamplerScript,
jsr223Sampler(String)public static DslDummySampler dummySampler(String responseBody)
Usually you would replace an existing sampler with this one, to test some extractor or test plan complex behavior (like controllers conditions), and once you have verified that the rest of the plan works as expected, you place back the original sampler that makes actual interactions to a server.
By default, this sampler, in contrast to the JMeter plugin Dummy Sampler, does not simulate response time. This helps speeding up the debug and tracing process while using it.
responseBody - specifies the response body to be included in generated sample results.DslDummySamplerpublic static DslDummySampler dummySampler(String name, String responseBody)
dummySampler(String) but allowing to set a name on the sampler.
Setting the name of the sampler allows better simulation the final use case when dummy sampler is replaced by actual/final sampler, when sample results are reported in stats, logs, etc.
DslDummySampler,
dummySampler(String)public static DslJsr223PreProcessor jsr223PreProcessor(String script)
This preprocessor is very powerful, and lets you alter request parameters, jmeter context and implement any kind of custom logic that you may think.
script - contains the script to be executed by the preprocessor. By default, this will be
a groovy script, but you can change it by setting the language property in the
returned post processor.DslJsr223PreProcessorpublic static DslJsr223PreProcessor jsr223PreProcessor(String name, String script)
jsr223PreProcessor(String) but allowing to set a name on the preprocessor.
The name is used as logger name which allows configuring log level, appender, etc., for the preprocessor.
jsr223PreProcessor(String)public static DslJsr223PreProcessor jsr223PreProcessor(DslJsr223PreProcessor.PreProcessorScript script)
jsr223PreProcessor(String) but allowing to use Java type safety and code
completion when specifying the script.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using jsr223PreProcessor(String) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
DslJsr223PreProcessor.PreProcessorScript,
jsr223PreProcessor(String)public static DslJsr223PreProcessor jsr223PreProcessor(String name, DslJsr223PreProcessor.PreProcessorScript script)
jsr223PreProcessor(String, String) but allowing to use Java type safety and
code completion when specifying the script.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using jsr223PreProcessor(String) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
DslJsr223PreProcessor.PreProcessorScript,
jsr223PreProcessor(String)public static DslRegexExtractor regexExtractor(String variableName, String regex)
This method provides a simple default implementation with required settings, but more settings are provided by returned DslRegexExtractor.
By default, when regex is not matched, no variable will be created or modified. On the other hand when the regex matches it will by default store the first capturing group (part of expression between parenthesis) of the first match for the regular expression.
variableName - is the name of the variable to be used to store the extracted value to.
Additional variables <variableName>_g<groupId> will be created for
each regular expression capturing group (segment of regex between
parenthesis), being the group 0 the entire match of the regex. <variableName>_g variable contains the number of matched capturing groups
(not counting the group 0).regex - regular expression used to extract part of request or response.DslRegexExtractorpublic static DslBoundaryExtractor boundaryExtractor(String variableName, String leftBoundary, String rightBoundary)
This method provides a simple default implementation with required settings, but more settings are provided by returned DslBoundaryExtractor.
By default, when no match is found, no variable will be created or modified. On the other hand, when a match is found, it will by default store the first match.
variableName - is the name of the variable to be used to store the extracted value to.leftBoundary - specifies text preceding the text to be extracted.rightBoundary - specifies text following the text to be extracted.DslBoundaryExtractorpublic static DslJsonExtractor jsonExtractor(String variableName, String jmesPath)
This method provides a simple default implementation with required settings, but more settings are provided by returned DslJsonExtractor.
By default, when no match is found, no variable will be created or modified. On the other hand, when a match is found, it will by default store the first match.
variableName - is the name of the variable to be used to store the extracted value to.jmesPath - specifies the JMESPath to extract the value.DslJsonExtractorpublic static DslDebugPostProcessor debugPostProcessor()
This element is particularly helpful to collect JMeter variables and debug extractors during or after a test plan execution.
Created Debug post processor is configured by default to only include JMeter variables, which covers most common usages and keeps memory and disk usage low.
DslDebugPostProcessorpublic static DslJsr223PostProcessor jsr223PostProcessor(String script)
This post processor is very powerful, and lets you alter sample results, jmeter context and implement any kind of custom logic that you may think.
script - contains the script to be executed by the post processor. By default, this will
be a groovy script, but you can change it by setting the language property in the
returned post processor.DslJsr223PostProcessorpublic static DslJsr223PostProcessor jsr223PostProcessor(String name, String script)
jsr223PostProcessor(String) but allowing to set a name on the post processor.
The name is used as logger name which allows configuring log level, appender, etc., for the post processor.
jsr223PostProcessor(String)public static DslJsr223PostProcessor jsr223PostProcessor(DslJsr223PostProcessor.PostProcessorScript script)
jsr223PostProcessor(String) but allowing to use Java type safety and code
completion when specifying the script.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using jsr223PostProcessor(String) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
DslJsr223PostProcessor.PostProcessorScript,
jsr223PostProcessor(String)public static DslJsr223PostProcessor jsr223PostProcessor(String name, DslJsr223PostProcessor.PostProcessorScript script)
jsr223PostProcessor(String, String) but allowing to use Java type safety and
code completion when specifying the script.
WARNING: This only works when using embedded jmeter engine (no support for saving to
JMX and running it in JMeter GUI, or running it with BlazeMeter). If you need such support
consider using jsr223PostProcessor(String) instead.
Take into consideration that the provided script is invoked from as may threads as defined in thread group. So make sure that provided logic is thread safe.
DslJsr223PostProcessor.PostProcessorScript,
jsr223PostProcessor(String, String)public static DslResponseAssertion responseAssertion()
JMeter by default uses repose codes (eg: 4xx and 5xx HTTP response codes are error codes) to determine if a request was success or not, but in some cases this might not be enough or correct. In some cases applications might not behave in this way, for example, they might return a 200 HTTP status code but with an error message in the body, or the response might be a success one, but the information contained within the response is not the expected one to continue executing the test. In such scenarios you can use response assertions to properly verify your assumptions before continuing with next request in the test plan.
By default, response assertion will use the response body of the main sample result (not sub samples as redirects, or embedded resources) to check the specified criteria (substring match, entire string equality, contained regex or entire regex match) against.
DslResponseAssertion for all available options.DslResponseAssertionpublic static DslResponseAssertion responseAssertion(String name)
responseAssertion() but allowing to set a name on the assertion, which can be
later used to identify assertion results and differentiate it from other assertions.name - is the name to be assigned to the assertionDslResponseAssertion for all available options.responseAssertion(String)public static JtlWriter jtlWriter(String directory)
This is just a handy short way of generating JTL files using as filename the template:
<yyyy-MM-dd HH-mm-ss> <UUID>.jtl
If you need to have a predictable name, consider using jtlWriter(String, String)
instead.
directory - specifies the directory path where jtl files will be generated in. If the
directory does not exist, then it will be created.jtlWriter(String, String),
JtlWriterpublic static JtlWriter jtlWriter(String directory, String fileName)
This is particularly helpful when you need to control de file name to do later post-processing on the file (eg: use CI build ID in the file name).
directory - specifies the directory path where jtl file will be generated. If the
directory does not exist, then it will be created.fileName - the name to be used for the file. File names should be unique, otherwise
the new results will be appended to existing file.public static ResponseFileSaver responseFileSaver(String fileNamePrefix)
fileNamePrefix - the prefix to be used when generating the files. This should contain the
directory location where the files should be generated and can contain a
file name prefix for all file names (eg: target/response-files/response-
).ResponseFileSaverpublic static InfluxDbBackendListener influxDbListener(String influxDbUrl)
influxDbUrl - is the URL to connect to the InfluxDB instance where test results should be
sent.InfluxDbBackendListenerpublic static HtmlReporter htmlReporter(String reportsDirectory)
This is just a handy short way of generating html reports following naming template
<yyyy-MM-dd HH-mm-ss> <UUID>
If you need to have a predictable report name, consider using
htmlReporter(String, String) instead.
reportsDirectory - specifies the directory where HTML reports are generated. If the
reportsDirectory does not exist, then it will be created.htmlReporter(String, String),
HtmlReporterpublic static HtmlReporter htmlReporter(String reportsDirectory, String name)
This is particularly helpful when you need to control de report directory name to do later post-processing on it (eg: use CI build ID in the report directory name).
reportsDirectory - specifies the directory where HTML reports are generated. If the
reportsDirectory does not exist, then it will be created.name - the name to be used for the report directory. Names should be
unique, otherwise the report generation will fail after test plan
execution.HtmlReporterpublic static DslViewResultsTree resultsTreeVisualizer()
This element is helpful when debugging a test plan to verify each sample result, and general structure of results.
DslViewResultsTreepublic static DslConstantTimer constantTimer(Duration duration)
duration - specifies the duration for the timer to wait.public static DslUniformRandomTimer uniformRandomTimer(Duration minimum, Duration maximum)
The timer uses the minimum and maximum durations to define the range of values to be used in the uniformly distributed selected value. These values differ from the parameters used in JMeter Uniform Random Timer element to make it simpler for general users to use. The generated JMeter test element uses as "constant delay offset" the minimum value, and as "maximum random delay" (maximum - minimum) value.
EXAMPLE: wait at least 3 seconds and maximum of 10 seconds
uniformRandomTimer(Duration.ofSeconds(3), Duration.ofSeconds(10))
minimum - is used to set the constant delay of the Uniform Random Timer.maximum - is used to set the maximum time the timer will be paused and will be used to
obtain the random delay from the result of (maximum - minimum).DslUniformRandomTimerpublic static DslThroughputTimer throughputTimer(double throughputPerMinute)
The timer adds variable pauses to test plan execution to limit the throughput by checking time between timer executions.
throughputPerMinute - specifies the target samples per minute.DslThroughputTimerpublic static DslCsvDataSet csvDataSet(String csvFile)
This allows to store for example in a CSV file one line for each user credentials, and then in the test plan be able to use all the credentials to test with different users.
By default, the CSV data set will read comma separated values, use first row as name of the generated variables, restart from beginning when csv entries are exhausted and will read a new line of CSV for each thread and iteration.
E.g: If you have a csv with 2 entries and a test plan with two threads, iterating 2 times each, you might get (since threads run in parallel, the assignment is not deterministic) following assignment of rows:
thread 1, row 1 thread 2, row 2 thread 2, row 1 thread 1, row 2
csvFile - path to the CSV file to read the data from.DslCsvDataSetpublic static DslCsvDataSet csvDataSet(TestResource resource)
csvDataSet(String) but easing usage of test resources.resource - test resource to use as input file for the CSV data set.csvDataSet(String)public static TestResource testResource(String resourcePath) throws IllegalArgumentException
src/test/resource in maven
projects.resourcePath - path to locate the resource. For example, in a maven project to create a
resource to file "src/test/resources/csvs/my-csv.csv" you need to
use testResource("csvs/my-csv.csv").IllegalArgumentException - when no file can be located for provided resource pathTestResourceCopyright © 2023. All rights reserved.