Jake Zidow
Jake Zidow

Reputation: 533

JMeter Beanshell sampler that runs when HTTP Request Sampler fails

I need a Beanshell sampler that runs only when a specific HTTP Request Sampler fails. I want this so I can write certain variables to the terminal console when this failure occurs during test execution.

I know I can save the http response to a file upon failures [using built in jmeter component Save Responses to File] and include variables in the name of the file saved, but this is too heavyweight for what I am trying to achieve.

Upvotes: 0

Views: 495

Answers (2)

riversidetraveler
riversidetraveler

Reputation: 418

Why not set up a beanshell sampler with an if condition that tests the result's HTTP status? The script would look something like this:

if (!ctx.getPreviousResult().getResponseCode().equals("200")) {
    log.info("Your log message here.");
}

Upvotes: 1

Paul Spehar
Paul Spehar

Reputation: 78

Check this out. Beanshell to save response to log on failure. Perhaps you can modify this concept to write variables to terminal instead of responses to file https://stackoverflow.com/a/13931040/7003774

Upvotes: 1

Related Questions