Test Passes in Postman (200 Ok) but fails in Newman (404 Not Found)

Hi, I am writing a test script where I am using an environment variable, setting it to a constant value in pre-request script and finally, assigning it to my request body parameter.

Pre-request Script -
var code = "b0d159"; pm.environment.set("offeringCode", code)

Request Body -
{ "Service": "OfferingService", "Action": "createOffering", "Params": { "OfferingCode": "{{offeringCode}}", "Name": "{{offeringName}}", "Description" : null, "OrganizationID" : null}

Test Script (test that is failing) -
pm.test('response code is 200', function () { pm.response.to.be.ok; });

I am setting an already existing value (exists in db) to the variable, thus the request should return ā€œOverlapping offering codeā€ in response body.
While running the request/ collection from postman expected response comes with a 200 Ok status, however, Newman returns ā€œMissing Parameterā€ with a 404 Not Found status.
In Newman, the ā€œdetailā€ column for assertion error says - " response code is 200
expected response to have status reason ā€˜OKā€™ but got ā€˜NOT FOUNDā€™ at assertion:0 in test-script inside ā€œOverlapping Offering Codeā€

What could be the reason behind this?

Hey @fairouz05

Welcome to the community! :wave:

What is the command that youā€™re using to run the Collection in Newman?

Are you specifying an environment file in the run?

Yes, here is the command (after I give path to the folder where I have saved the collection.json and environment.json file )

newman run ā€œCreate Offering.postman_collection.jsonā€ -e ā€œAPI Demo Env Copy.postman_environment.jsonā€ --reporters cli,html --insecure

Thatā€™s seems odd, are you saving the request your editing before exporting the file to use with Newman?

Iā€™ve got to say it breaks my little heart that youā€™re not using htmlextra but not everyone has discovered it yet :grin:

Hey there, I found what went wrong using htmlextra! One of the environment variables was in wrong format which was causing the ā€œMissing Parameterā€ response, I included the right code in pre-request script and now it works! Thank you :slightly_smiling_face:

1 Like

Thatā€™s awesome!! So glad it lead you to the right place!!

Thanks for using the reporter :trophy:

1 Like

This was helpful for me as well htmlextra reports are quite detail. Thanks for this

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