0

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?

Shawn
  • 10,931
  • 18
  • 81
  • 126

1 Answers1

1

You can do it using the following Groovy code:

def numberOfThreads = ctx.getThreadGroup().getNumThreads()

Demo:

JMeter get number of threads in thread group

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(),)}

Groovy Function Number of Threads

See Groovy Is the New Black article for more information on using Groovy scripting in JMeter tests.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • That will return the number of threads in the setup thread group. I want the number of threads in the non-setup thread group. – Shawn Apr 19 '17 at 17:35
  • Your comment answers my question so I will mark your answer as accepted. Perhaps it would be best if you edited the comment into your answer. – Shawn Apr 19 '17 at 19:14
  • If you're interesting, I have also posted a follow-up question concerning the same problem in the case where the number of threads is defined in the thread group properties rather than in BlazeMeter: http://stackoverflow.com/questions/43504273/get-number-of-threads-in-a-thread-group-from-the-setup-thread-group-jmeter – Shawn Apr 19 '17 at 19:18