Inable to see my error response in newman HTML report

hi,

I have a validation script that should check if the array is empty and then stop running the collection and display the error message but I don’t see the error message displayed in Newman or Collection Runner and
I am not able to see the assertions in the Newman HTML report and in the collection runner instead there is a message

Any idea why it happening?
I am expecting to see the assertions from the script and if it is failing then it should show me why its failing

const Library_search_validate_response_NotEmpty = () => {
    try {
        // Get the API response as JSON
        const jsonData = pm.response.json();

        // Assert that vehicles is not an empty array
        pm.expect(Array.isArray(jsonData.vehicles) && jsonData.vehicles.length > 0, 'Vehicles array should not be empty').to.be.true;

        // Assert that segments is not an empty array
        pm.expect(Array.isArray(jsonData.segments) && jsonData.segments.length > 0, 'Segments array should not be empty').to.be.true;

        // Assert that itineraries is not an empty array
        pm.expect(Array.isArray(jsonData.itineraries) && jsonData.itineraries.length > 0, 'Itineraries array should not be empty').to.be.true;

    } catch (error) {
        // Log the error message
        console.error('Error occurred while processing the response:', error.message);

        // Stop the collection run
        postman.setNextRequest(null);

        // Add a custom variable to Newman environment to capture the error
        pm.environment.set('Error_Message', `Error occurred while processing the response: ${error.message}`);
    }
};
// Set the function as a global variable
pm.globals.set('Library_search_validate_response_NotEmpty', Library_search_validate_response_NotEmpty.toString());

Hey @technical-engineer16 :wave:

I can see that you have a bunch of pm.expect() statements but these are not in a pm.test() function. It’s correctly reporting that you have no tests.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.