1
votes

Is there a possibility to have variables that depend on the listener where there lay in? So I want to execute two samplers which are working with a JSR223 Assertion. I use a groovy code which asks for the value of the variable "name". If I execute Sampler A it should say "Tom" and if i execute Sampler B it should say "Paul". It has to be possible to execute both at the same time.

1

1 Answers

2
votes

You have sampler shorthand in the JSR223 Assertion which stands for this or that Sampler. So you can check its name by calling sampler.getName() function which will basically execute underlying AbstractTestElement.getName() method. The relevant code would look like:

if (sampler.getName().equals('Sampler A')) {
   log.info('Tom')   
}
else if (sampler.getName().equals('Sampler B')) {
    log.info('Paul')
}

You can set a JMeter Variable from Groovy code using vars shorthand which in its turn stands for JMeterVariables class instance like:

vars.put('foo', 'bar')

Once done you will be able to refer created variable as ${foo} where required - it will have the value of bar

Check out Scripting JMeter Assertions in Groovy - A Tutorial article for more details.