The continueOnStepFailure
is a new keyword that was meant to be used when looking to validate results and not fail immediately on the first failure. The purpose was for assertions or validations so as much information can be validated when asserting results of tests.
To avoid its usage to be as a pure if condition for several steps (with unexpected consequences), the default behavior of * configure continueOnStepFailure = true
will only continue the execute if the fails happen in a match
step and once you disable the mechanism with * configure continueOnStepFailure = false
the test will fail (but still provide details for each step within the continueOnStepFailure
block). This is because match
is the recommended keyword for any sort of validations and is how you can leverage the powerful JSON assertions library etc.
It is also recommended to also explicity set * configure continueOnStepFailure = false
after the set of match
keywords so there are no unexpected behaviors after that conscious decision of continuing to evaluate keywords after a failure.
That being said there are ways to extend and configure the behavior of the continueOnStepFailure
beyond the default behavior. The keyword also takes a JSON input, instead of a boolean, that allows some more extensibility. E.g. the default behavior of the keyword can be represented as follows:
* configure continueOnStepFailure = { enabled: true, continueAfter: false, keywords: ['match'] }
This means the continueOnStepFailure
mechanism will be enabled, the scenario execution will not continue after the mechanism is disabled and it'll only accept failures if those happen in the match
keyword. Note that if you set continueAfter
to true the scenario will continue to execute the remaining steps but the scenario itself will still be marked as failed (with appropriate output in the report and typical failed behavior for any caller of that scenario). I highly discourage to set continueAfter
to true.
For your specific use case, the status
keyword is definitely within the boundaries of assertions that I've described. status 200
is just a shortcut for match responseStatus == 200
. Very likely we should add status to the default behavior, given that it's a match assertion. With the extended configuration in JSON you can do the following for your use-case:
When method Get
And configure continueOnStepFailure = { enabled: true, continueAfter: false, keywords: ['match', 'status'] }
Then status 200
And match response = read ('this:getCarAssertion')
And configure continueOnStepFailure = false
Some additional examples can be found in the unit tests in this pull request. For quick reference, this is how your Karate Test report will look like:
