0
votes

I'm running a test in Jmeter. that test sends in the end the status of the test - "success" or "fail". I've created a 'user defined variable' that is named 'subject' and assigned it with value 'success'. within the http requests I've put 'BeanShell Assertion' that assigns the 'subject' variable with 'failure' if the test failed:

if( (ResponseCode != null) && (ResponseCode.equals ("200") == false))
{
    //Failure=true;
  vars.put("subject","failure");

} 

now, in the SMTP sampler I'm sending ${subject} as the subject of the mail.

the sampler doesn't recognise the variable (it is empty). any ideas?

2
Have you tried this with a BeanShell post processor? - Mendhak
yes. the BeanShell Assertion does work. I checked it. the point is that if the 'subject' variable is not changed (to 'failure) - the default value (success) is not set. I've tried both "success" (with apostrophes) and success (without them) - user2880391

2 Answers

0
votes

Can you show the screenshot of your Test Plan? I'm particularly interested in where Beanshell Assertion lives.

JMeter Assertions have their scope, i.e. given the following test structure:

  • Sampler 1
    • Assertion
  • Sampler 2

Assertion will be applied to Sampler 1

In case of the following test plan:

  • Sampler 1
  • Sampler 2
  • Assertion

Assertion will be applied to both Sampler 1 and Sampler 2

Nothing is wrong with your code, it should be setting "subject" variable in case of non "200" response code.

By the way, there is a pre-defined JMeter variable - ${JMeterThread.last_sample_ok} - which returns "true" if previous sampler was successful and "false" in the other case. It is better to use it in combination with the If Controller as Beanshell has known performance issues and can become a bottleneck in case of heavy loads.

0
votes

The problem was that when using the 'Beanshell Assertion' I didn't pass it the variable - ${subject}, so when the test succeeded it was like the variable was never assigned.