Print API response in "Test results" tab in Postman - postman

I'm using Postman automate an API with Newman.But the response body of the API call is not showing in the newman.
var body = JSON.parse(responseBody);
tests["Response Body ", body] = true;
I have tried the above code,but even after successful API call the response is not printing in the "Test results" tab.
the output of above is showing as,
PASS [object Object]
Any suggestions to print the API response will be of great help.
Thanks in advance!

I assume you're using the cli reporter with Newman, you could just add a console.log(pm.response.json()) statement to the Tests tab.
That should print out the response body on the console during the Newman run.
If you wanted something to show you all the details of the Newman run in a separate report, you could also use a different reporter, like this HTML one ;)
https://www.npmjs.com/package/newman-reporter-htmlextra

Related

Latest changes to Postman tests doesn't reflect in Newman

I'm noticing that any changes to tests in Postman isn't reflected when running in Newman.
Example:
In Postman, I change the following text from '200ms' to '100ms'
console.log("Hello World!");
pm.test("C6 Verify response time is less than 100ms", function () {
pm.expect(pm.response.responseTime).to.be.below(100);
Postman screenshot
But in Newman, it is still getting '200ms'
GET https://reqres.in/api/users?page=2 [200 OK, 2.06KB, 172ms]
┌
│ 'Hello World!'
└
√ C6 Verify response time is less than 200ms
Newman screenshot
Is there a way to clear the cache or something?
So that Newman gets the latest test changes from Postman?
Postman doesn't store/sync collection and environment with the exported json file. You have to do it manually. Export collection and environment as json file if you want the new changes to get reflected in nemman
Update:
as you are using public url link you have to update the link manually as the link won't get updated automatically:

Is it possible to POST parameters when running the "Collection runner" in POSTMAN

Problem is that I'm trying to change the settings of the website with POST and would like to confirm that the settings changed with a new GET request after the change, but as I'm running the collection it's just running the tests but not the POST itself, POST does not have any response so there's nothing to check there.
I hope that I was clear enough explaining my problem.
Thanks Guys!
If I'm understanding this correctly:
You have two requests and want to run the GET immediately after the POST. This can simply be done by using environment variables and SetNextRequest.
Be careful of entering an infinite loop because Collections run top down; if your GET request was before the POST request. It may be better to duplicate your GET request and place it below the POST.
A Post to {{base_url}}/website
Within the Pre-request Script set your new settings to your environment
pm.environment.set("setting1", "newValue");
Within the Body if your sending raw json for example use that variable
{
"setting1": "{{setting1}}"
}
Postman still runs the Test section you don't need a pm.test it's essentially a Post-request Script. Tell Postman to run the GET request next:
postman.setNextRequest("Get Website Settings");
From your Get request within Tests section validate the setting is correct
pm.test("Setting has been updated to" + {setting1}, function() {
var actualSetting = pm.response.json().setting1;
pm.expect(actualSetting).is.eql({setting1});
});

How can I return hyperlinked text in a Lexresponse?

So I am building a lex chatbot and I am trying to return a response with hyperlinked text. I have the chatbot sitting on a front end but I cant seem to find a way to return responses with hyperlinks. Heres what I have so far
https://imgur.com/N6Bp2fX
https://imgur.com/zbnUsrH
Now Ive read that the responses from lex are formatted to where the chatbot is sitting. For example, in the chatbot test window on the Amazon site, returning hyperlinks is impossible, but skype automatically hyperlinks URLs. But I have mine sitting on a browser but I still cant get a hyperlinked response in the bot.
Would love if anyone could help me out! Thanks in advance!
The test console window of Lex does not support html rendering. You can instead deploy your chatbot to a channel like facebook or slack, and it will be rendered correctly.
You can use the custom markup option to send a response in the following json format to format it by your client.
{
"text": "Check out the following link",
"type":"hyperlink",
"links":[{
"linkText":"Google",
"url":"https://google.com"
}]
}
Lex can return any response that you want, but it's the responsibility of chat client to parse that response and show accordingly.
So you need to write your logic to parse hyperlink and show them.
In your case you can send response from Lex like : Please visit [link]www.google.com[\link].
Then you can write your logic to show the text in anchor tag <a> in your chat window so that it is parsed as hyperlink.
Hope it helps.

How to access the true RAW request body from post man on a pre-request script?

I'm trying to authenticate myself against an API. This API uses the raw body from the request to create the hash that it will use to authenticate against my token.
For testing purposes, I'm using postman with a pre request script to create the hash. Everything works fine, with one exception:
In the code tab I have this
however if on the pre request script I dump the value of the request body I get by using request.data I obtain
The problem is, its not exactly the same string, then the value retrieved by request.data creates a hash with a different body that the server uses to create its hash (the server uses the one beautified with line endings and tabs). This is the script where I use the request body content:
So unless someone have an idea of how to retrieve the json body exactly on the format it was written, pretty much seems I cant use postman for this
thanks!
EDIT: I don't know if this existed 5 years ago when the original Question was posted, but it's available in PostMan 8.12.2 at least.
When you have a request open in Postman, show the "Code" pane at the right by clicking the </> button seen in the right-hand toolbar.
Then in the dropdown header for code type, choose "HTTP".
The line numbers in the HTTP snippet are significant -- in my screenshot, the last four displayed lines are concatenated into line 6 of the actual HTTP.
just changed the post body tab to
new post body
and it went just fine. Not really the best solution i was expecting, but does the job :)

How can I view responses in Postman Collection Runner?

I am using the Postman Collection Runner to run the same request multiple times using iterations. My tests work as expected, but I'm not able to see the individual responses for each request.
Is it possible to view the responses for requests in the Postman Collection Runner?
In the latest version of Postman you can see all the data from the collection run for each individual request.
In the Collection Runner, Click on the request name and all the details of the request and response can be viewed.
More information can be going on the Debugging using the Request & Response body section of this page
This might help somebody, I tried
pm.test(responseBody, true)
and this printed the response in run summary.
Let me add more details about the shadowcharly solution.
Your results may be viewed if you assign responseBody variable to tests array (in Tests tab)
tests["body"] = responseBody
and export it as json (on the interface you only see the zero/one results if test passed or not).
It's not very useful but this is the only way I've found.
If you are repeating exactly the same query, you could use the test name to show the result:
tests['Test to see value of key Key'+ keyValue] = testResult....
You will have a different test for each value received, not exactly a log, but works fantastic ;)
I know this is old, but postman has added a feature in the collection runner.