JMeter - if controllers on thread group - jmeter

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

Related

Running Jmeter Test in multiple accounts parallelly

I have set of sampler under one Thread Group as
TestPlan
ThreadGroup
SimpleController
Login(HTTP Sampler)
FetchCSRFToken(HTTP Sampler)
LoopController(Count -> 5)
Testcase1(HTTP Sampler)
Testcase2(HTTP Sampler)
Testcase3(HTTP Sampler)
Now I got a requirement to run the above test cases in multiple accounts parallelly.
I googled and find out having Multiple Thread Group is a better idea since I suppose to run it parallelly and I have to pass CSRF token in all test cases header.
Is it possible to have two thread groups without duplicating the test cases inside Loop Controller of Thread Group-1 to Thread Group-2?
Kindly suggest if any other way as well.
If you want to avoid code duplication - just put the "shared" code under a Test Fragment and reference it using Module Controller(s) where required
In general a Thread Group should represent a logical/business group of users, if you just need to add more users doing the same actions - you can parameterize credentials, URLs, parameters, etc. so each thread will use different set of data on each iteration, the most commonly used approach for parameterization is CSV Data Set Config

How to get Sample count per thread in Jmeter5.1

Need to count samples generated in thread level. I am using 8 thread groups and each thread group contains multiple transaction controller and each transaction controller contains multiple requests. Problem is here that I am able to get the samples to count for each transaction controller but not for thread level.
I am using 8 ultimate thread group in my test plan for load test executing for 1hr.
You could consider adding __threadNum() function somewhere to your Sampler's name
The function will be evaluated in the runtime and resolved into current thread (virtual user) number.
This way you will be able to see how many Samplers did this or that thread execute in a listener of your choice, i.e. in Aggregate Report
Check out Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.

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.

Dependency among multiple thread groups in JMeter

I have set up a load test plan with multiple thread group, i.e. -
Registration (50% of the threads)
Place Order (10% of the threads)
Some more operations (remaining threads)
Herein if Registration thread does not succeeds than I don't want to execute remaining thread groups. In case of a single thread group I can use if controller and discard samples if one sample fails but how do I achieve it when I am using multiple thread groups.
JMeter Variables scope is limited to current Thread Group only, if you want to use If Controller basing on the condition which is set in another Thread Group - you should be using JMeter Properties instead (JMeter Properties scope is global for the whole JVM). See How to Use Variables in Different Thread Groups article for details on converting JMeter Variables into JMeter Properties.
You may also find InterThread Communication plugins useful when it comes to passing data between thread groups and setting up dependencies.
However, given your scenario you either need to pass the whole thread context (cookies, cache, whatever) which might be tricky so it would be much better putting all the samplers under the same Thread Group and use Throughput Controller, Switch Controller or Weighted Switch Controller, whatever matches your scenario the closest way. See Running JMeter Samplers with Defined Percentage Probability guide for more information.

Resources