0

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.

Jake Zidow
  • 513
  • 1
  • 5
  • 9

2 Answers2

1

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

  • This is a good answer but it didn't print to console when the status code was a failure. Very close though so I upvoted. – Jake Zidow May 09 '19 at 00:03
  • have you tried the print statement with your variables? See 1 and 2 here: https://www.blazemeter.com/blog/using-beanshell-beginners-no-java-knowledge-required – Paul Spehar May 09 '19 at 15:18
  • Yes after adding the print statement, this did not work when status code was unsuccessful. – Jake Zidow May 10 '19 at 17:12
1

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