Buse Kaya
Buse Kaya

Reputation: 95

How to send mail for the every failed HTTP Request Sampler in JMETER?

I planned to create a Test Plan in my JMeter like below

Test Plan Thread Group

HTTP Request Sampler 1
HTTP Request Sampler 2
HTTP Request Sampler 3
HTTP Request Sampler 4
HTTP Request Sampler 5
HTTP Request Sampler 6
HTTP Request Sampler 7
HTTP Request Sampler 8

If Controller condition
${__groovy(vars.get("JMeterThread.last_sample_ok").equals("false"),)}

SMTP Sampler

I would like to run the test 24/7. If one (or more) HTTP Request Sampler returns an error for whatever reason, then execute the SMTP sampler and send an email to me.

I want to check the condition for every sampler 1-8. But now if HTTP Request Sampler 4 and HTTP Request Sampler 8 is failed, JMeter only sends an email for HTTP Request Sampler 8.

If none of the HTTP Request Sampler returns an error, I want to send an email to me. Please help.

Thanks.

Upvotes: 0

Views: 208

Answers (1)

Dmitri T
Dmitri T

Reputation: 168082

JMeter executes Samplers upside down therefore given you have your If Controller only after HTTP Request Sampler 8 - it will check only HTTP Request Sampler 8 result, previous failures will be silently ignored.

The solutions are in:

  1. Copy and paste your If Controller to appear after each and every HTTP Request sampler you want to check
  2. Basically the same as point 1 but using Module Controller instead of copying and pasting the If Controller
  3. Replace this If Controller and SMTP Sampler combination with a single JSR223 PostProcessor, the condition you have already and the code to send a email can be found i.e. in Send Email.groovy file. PostProcessors act according to JMeter Scoping Rules so a single instance will be applied to all Samplers on its level.

Upvotes: 0

Related Questions