0
votes

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.

2

2 Answers

1
votes

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

1
votes

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.");
}