Search code examples
postmansaaspostman-collection-runner

Validate 'Could not resolve host' use case in Postman


I need to delete a tenant and make sure that the tenant is not accessible anymore. Is there a way to validate 'Could not resolve host' i.e. 'Error: getaddrinfo' in Postman as this error is the expected behavior?

When below curl command is executed in a terminal

curl https://invaliddomain1281738012732.com -v

Proper error message is displayed

curl: (6) Could not resolve host: invaliddomain1281738012732.com

But in postman, is there a way to add a test to validate this behavior? Postman Error: getaddrinfo


Solution

  • You won't be able to test the validity of the URL by calling it directly and writing a test on the result, from Postman's Learning Center:

    Tests will execute after the response is received, so when you click Send, Postman will run your test script when the response data returns from the API.

    A workaround to that is to query that URL directly from the Tests tab and assert the response there, e.g.:

    pm.test("address doesn't exist", function(){
        pm.sendRequest('https://invaliddomain1281738012732.com', (error, response) => {
            pm.expect(error.errno).to.eql("ENOTFOUND");
        });
    })