Postman - Consider Timeout as test failure

I am using Postman v5.5.3 and trying to run a collection of requests with tests and report the results.

I would like a TIMEOUT to be considered a test failure. This is not happening right now.

I have 2 asserts as:

pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});

pm.test(“Response time is less than 1000ms”, function () {
pm.expect(pm.response.responseTime).to.be.below(1000);
});

If I set the Postman XHR timeout to 10000 ms and the Collection Test Runner encounters a timeout, it does not consider this a failed test.

It seems that timeouts short-circuit the test stack and immediately drop out.

If there a way to “test for timeouts” so that timeouts show as test failures in the Collection Test Runner Test Results?

1 Like

Hey @DSect. Sorry for the delayed response.
The use case you suggested is not currently supported by the app because the test scripts run only if the request returned a valid response, in case of a timeout this condition doesn’t hold true and as you mentioned, it immediately drops out.

This is done since the tests are generally based on the response returned by the request but I understand that there can be cases where this behavior might be required. I’ll mark it as a feature request internally and might consider this based on its feasibility in future releases.

Meanwhile, here is a small hacky workaround that you can try. If you have certain requests that are known to timeout, then set an environment variable with a boolean flag specifying its behavior, say timedOut = true, then in the test script, update the environment variable to false, and check for its value in the subsequent request. If the request times out, then the value of the environment variable would not change in the subsequent request since the test script wouldn’t be executed and you can infer that the request timed out and perform actions accordingly. Needless to say, if the request times out, the value of the environment variable would be updated and you can handle that accordingly.

I hope this helps. Feel free to reach out in case of additional queries.