John Fox
John Fox

Reputation: 927

getting Jmeter to report failure on error

Currently experimenting with swapping out a couple of powershell warm up commands for our web app to use jmeter test plans. The features look much improved and execute significantly quicker.

I am executing the test plans using the non-gui mode through octopus deploy. How can i get the task to quit reporting failure when it encounters a http error status code? I need the job to report as failure on encountering an error and mark the task as complete if any of my hosts return anything other than a http success code?

We are using DFS across 20+ hosts and the existing powershell works as a good check that everything has replicated and working before we bring the new instances live (using blue/green deployment).

Upvotes: 0

Views: 399

Answers (1)

Dmitri T
Dmitri T

Reputation: 168157

  1. Add JSR223 Assertion to your Test Plan at the same level as your HTTP Request samplers (or according to JMeter Scoping Rules if you want to apply them to certain requests only)
  2. Put the following code into "Script" area:

    if ((prev.getResponseCode() as int) > 399) {
        System.out.println('HTTP status code for URL: ' + prev.getUrlAsString() + ' was ' + prev.getResponseCode())
        System.exit(-1)
    }
    
  3. That's it, when you run your test and get HTTP Status code 400 or higher - the JSR223 Assertion will terminate the test and return non-zero exit status code

    enter image description here

    More information: Scripting JMeter Assertions in Groovy - A Tutorial

Upvotes: 1

Related Questions