JMETER - How can I pass 2 condition in a while loop on Jmeter

How can I pass 2 condition in a while loop on Jmeter. The conditions are

  1. The request should run in loop till "Pass" response comes.
  2. While loop should run only for 1 minute.

Condition 1 is working fine. However condition 2 is unable to implement.

I have tried running the While Loop inside a Runtime Controller. But the issue is, if the response "Pass" comes before 1 min, the rest of the test stops. Tried other way round (Runtime inside While Loop) leading to numerous execution of the request, even after receiving "Pass" response.

Will appreciate any leads on this. Thanks

Upvotes: 0

Views: 1659

Answers (2)

Janesh Kodikara
Janesh Kodikara

Reputation: 1821

This could be another solution.

You can achieve the desired outcome with the following components.

  1. Runtime Controller
  2. If Controller
  3. Flow Control Action

enter image description here

  1. Set the Runtime (duration) in the Runtime Controller
  2. Set the first condition you already have in While Controller in the If Controller
  3. Click the Break Current Loop to exist from the Run Time controller

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168092

  1. Add a JSR223 Sampler just before the While Controller and store the current time into a JMeter Variable using the following code:

    SampleResult.setIgnore()
    vars.putObject('whileLoopStart', System.currentTimeMillis())
    
  2. Use the following __groovy() function as the While Controller's condition:

    ${__groovy(!vars.get('your_variable').equals('Pass') && ((System.currentTimeMillis() - vars.getObject('whileLoopStart')) < 60000),)}
    

This way the While Controller will run until:

  • either your_variable is not equal to Pass
  • or 60 seconds pass
  • whatever comes the first

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

Upvotes: 1

Related Questions