How can execute specific Thread Group in Jmeter with command? - jmeter

I want to run any specific Thread Group with Command in windows. I have tried with using properties file but got failed. Now need help for executing any specific thread group selecting from command prompt.

You can easily achieve this using Taurus tool. It is a wrapper around JMeter (and several other performance testing tools) which provides an easy way of configure (or create) and run a JMeter test using simple YAML syntax.
For instance if you need to disable Thread Group B the relevant configuration would be something like:
---
execution:
scenario:
script: test.jmx
modifications:
disable: # Names of the tree elements to disable
- Thread Group B
enable: # Names of the tree elements to enable
- Thread Group A
References:
Modifications for Existing Scripts
Navigating your First Steps Using Taurus

If Thread group's Number of Threads is set to 0 it won't execute.
Based on that, you can set for each thread group Number of Threads with __property with default 0 per group number, e.g. for Thread group 1:
${__property(group1,,0)}
so if you execute in command prompt jmeter -Jgroup3=1 ... - if you want only thread group 3 be executed with 1 thread/user (other groups will have 0 users and won't get executed)

Related

JMeter - if controllers on thread group

Is it anyway I can have an if controller above a thread group, like:
TestPlan
-> If controller
----> Thread Group
I.e I just want to execute the if controller once so I can avoid unnecessary execution in the Thread Group?
You can add to Thread group in Number of Threads field get value from property, as:
${__P(GroupANumberOfThreads,0)}
So if you don't have property, for example don't send -JGroupANumberOfThreads=1 in CLI mode Thread group won't get executed
There are following options:
Put everything inside the Thread Group under the If Controller, this way no Samplers will be executed if the condition is not met, but the Thread Group will be still started and all threads will kick off
Set number of threads in the Thread Group to 0, it can be done using __if() function (member of JMeter Custom Functions plugin bundle, can be installed using JMeter Plugins Manager)
You can also consider running your JMeter test using Taurus tool as the wrapper, Taurus provides possibility to completely disable arbitrary test element (including thread groups) using simple declarative YAML syntax

Is it possible to run a portion of the script via command line?

Is it possible to run a portion of the script via command line in JMeter?
Here is what I am trying to do. I have multi-thread groups in a script. Let's say one is Stepping Thread Group and another one is tear down thread group for the same samplers, CSV files etc. Everything is the same. Now I want to run sometimes only thread group and sometimes only Stepping Thread Group.
I know we can do it from the GUI by disabling the thread group, but I want to do it from the command line to avoid manual steps. Is it possible?
Just define number of threads for both Thread Groups using __P() function, like:
For Stepping Thread Group:
${__P(stepping.threads,1)}
For tearDown Thread Group
${__P(teardown.threads,1)}
Whenever you want to disable certain Thread Group from command-line non-GUI mode - just set the number of threads for the specific thread group to 0 via -J command-line argument
i.e.
jmeter -Jstepping.threads=50 -Jteardown.threads=0 -n -t ... - will run the Stepping Thread Group with 50 virtual users and will not run the tearDown Thread Group
and
jmeter -Jstepping.threads=0 -Jteardown.threads=1 - will not run the Stepping Thread Group and will run the tearDown Thread Group with 1 virtual user
Alternative solution would be running your JMeter test using Taurus tool as the wrapper. Taurus provides Modifications for Existing Scripts functionality so you will be able to enable/disable arbitrary Test Elements using simple declarative YAML syntax like:
---
execution:
scenario:
script: test.jmx
modifications:
disable: # Names of the tree elements to disable
- jp#gc - Stepping Thread Group (deprecated)
enable: # Names of the tree elements to enable
- tearDown Thread Group
See Navigating your First Steps Using Taurus article for more information.

Get number of threads (defined via BlazeMeter) in a thread group from the setup thread group (jmeter)

I have a JMeter test plan which performs a simple action once. When I upload the test to BlazeMeter, I can then choose the number of threads I want for my thread group and run the test.
The problem I am having is that my test setup needs to know how many threads the thread group will have. To make things clearer, here is a simple representation of the test plan:
setUp Thread Group
needs to know the number of threads in the below thread group
Thread Group
The number of threads for this thread group is determined via BlazeMeter test configuration
Within the non-setup thread group, I can dynamically get the number of threads assigned via BlazeMeter, but I can't find any way of getting this number from within the setup thread group.
Any ideas?
You can do it using the following Groovy code:
def numberOfThreads = ctx.getThreadGroup().getNumThreads()
Demo:
The approach is environment-agnostic so you can use it anywhere. It may be more handy to use __groovy() function like: ${__groovy(ctx.getThreadGroup().getNumThreads(),)}
See Groovy Is the New Black article for more information on using Groovy scripting in JMeter tests.

JMeter - Thread Group

Is it possible to specify programmatically the number of threads from within the Thread Group?
My scenario: I need to run two Thread Groups. Each group will read files that specify the number of threads for that group to run. The groups should run concurrently.
Thanks
You can use properties.
For ex:
In the number of threads field, you can set like this
$(__P(usercount)}
When you run the test through command line, you can pass the value as shown here
jmeter -n -t test.jmx -Jusercount=10
Now the test will run for 10 users.
You can also use $(__P(usercount,5)}
That is, if the property value is passed to the test, then it will use it, otherwise, it will take the default value which is 5.

JMeter - Passing the number of threads to multiple thread groups

I have a file where I specify the number of threads for each Thread Group.
My goal is to run concurrently all Thread Groups with the number of threads read from the file.
My current algorithm: I have the first Thread Group in the Test Plan called Setup.
I read the data file to the local variables.
With the BeanShell Sampler, I convert those variables into the properties variables.
In each Thread Group, the number of threads is defined via the properties variable.
If I run the Thread Groups consecutively, there are no problems.
But I need to run them in parallel. I imagine that the Thread Group can try to run before the Setup group finishes reading the number of threads for that group. Then that group will never run.
I appreciate any thoughts and suggestions.
You can define the number of threads via JMeter properties in at least 2 more ways:
In user.properties file (the file is located in JMeter's "bin" folder, JMeter restart will be required to pick the properties up)
threads=100
Or you can do the same via -J command-line argument, i.e. start JMeter as:
jmeter -Jthreads=100 -n -t ....
In your Thread Groups you can refer the property via __P() function like:
${__P(threads)}
It is also possible to have "default" value which will be used in case of "threads" property will not be defined:
${__P(threads,50)}
References:
Full list of command-line options
Apache JMeter Properties Customization Guide
My current algorithm: I have the first Thread Group in the Test Plan
called Setup. I read the data file to the local variables. With the
BeanShell Sampler, I convert those variables into the properties
variables. In each Thread Group, the number of threads is defined via
the properties variable.
You could use Property File Reader. This will get loaded before any thread group starts. So you would not face any issue.
If you do not like Property File Reader, whatever you do - reading the data file and converting them into properties - do that in setUp Thread Group.
It will get executed before any thread group starts

Resources