0
votes

I am trying to send the mail through jmeter for failed http request, I want to know the sampler details like name of http request? I have added if controller to check the assertion of previously running request sand send a mail if it fails.It gives me error message "Message from Jmeter thread # Test failed: code expected to match /200/" But I want to know the name of http request which has been failed so i can know specifically which request is failing?

1

1 Answers

1
votes

You can use JSR223 PreProcessor to get the previous sampler details using the following code:

def sampler = ctx.getPreviousSampler()

Example usage:

def previousSamplerName = ctx.getPreviousSampler().getName()
log.info("Failed sampler name: " + previousSamplerName)
vars.put("SamplerName", previousSamplerName) 

Demo:

JMeter PreProcessor get previous sampler name

If everything goes fine you will be able to access previous sampler name as ${SamplerName} in the SMTP Request sampler

  • ctx is a shorthand to JMeterContext class instance, see the JavaDoc for available methods and fields

  • vars is a shorthand to JMeterVariables class instance, it provides read/write access to all JMeter Variables in scope.

Also check out Groovy Is the New Black guide to get familiarized with using Groovy in JMeter tests.