Search code examples
jsonapijmeterresponse

Jmeter extraction and using on If Controller


Is there's a way I can simulate this scenario, Example If there's a value extracted it will execute "TC1" Request, but If I extracted blank value it will execute "TC2".

Image1

Image2


Solution

  • The easiest method which provides maximum flexibility is using Switch Controller

    As per documentation:

    If the switch value is out of range, it will run the zeroth element, which therefore acts as the default for the numeric case. It also runs the zeroth element if the value is the empty string.

    If the value is non-numeric (and non-empty), then the Switch Controller looks for the element with the same name (case is significant). If none of the names match, then the element named "default" (case not significant) is selected. If there is no default, then no element is selected, and the controller will not run anything.

    So given the following Test Plan structure:

    • Switch Controller, switch value - your extracted variable
      • Simple Controller with an arbitrary name
        • TC2 sampler(s) as child(ren) of the Switch Controller
      • Simple Controller with name default
        • TC1 sampler(s) as chidr(ren) of the Switch Controller

    Demo:

    enter image description here

    More information: Running JMeter Samplers with Defined Percentage Probability