I'm new to Postman and I am trying to automate usage of these two requests.
The first one is a POST request which returns a JSON with a single key:value pair ("id") in it
The second one is a POST request which just returns 200 OK
So far I've managed to save "id" from the 1st request's response to an environment variable.
However, I still need to do the following:
After sending 1st request, wait about 30 seconds, put "id" from first request in the URL of 2nd request, then send 2nd request.
To wait 30 sec use setTImeout in prerequest script:
setTimeout(()=>{},30000)
This will wait for 30000 second
Now to send the id url you can directly add it to url as {{id}} or in prerequest script add :
pm.request.addQueryParams({key:"id",value:pm.variables.get("id")})
if you want to run the request again and again till you get 200:
add this to test section of request 2
if (pm.response.code !== 200) {
setTimeout(()=>{postman.setNextRequest(pm.info.requestName)},5000)
}
Note: there is a automatic delay between request option in postman you can use that also.
Also setNextRequest works only if you run using newman or colection runner
In the below image, you can find a delay option before you try to run postman.
This option is used to add a delay between requests running in the runner.
You can check my video to learn more about postman runner and request chaining.
Postman Runner and Request Chaining Explained in Detail
Related
I want to return the dynamic response from the postman mock server.
When mock URL hits in the postman, we get request body and from request body I want to fetch the field value and return the value to response.
mock URL : {{url}}/customer
RequestBody:
{
"Id": 47896,
"name": userName
}
I want to send the Id value in the Response Body:
{
"Id":47896
}
We are creating the random Id value in our project and we hit mock URL with that value in request body.
Every time the id value will be different after calling the mock URL. we are processing on the Id value if it mismatch then we throw an error.
Anyway to process the request body?
In the postman documentation, I didn't find any conclusive solution.
There is a limitation you can use dynamic value only in postman app not in newman .
https://github.com/postmanlabs/newman/issues/2565
In postman app you can :
Set response in mock server as :
{
"id":{{id}}
}
Choose environment for mock server :
click edit and choose and environment.
Enable persist variable value settings
Note that this will update both initial and current value with the value you will set as pm.environment.set("name",valu") in your script.
Now set environment variable id through pre-reuest script:
pm.environment.set("id",5)
output
Note:
You should send request two times, first time for the environment to sync with cloud
and second to get updated response , so try to send a dummy request before the actual request .
IN old app it was working fine now it looks like you need two request.
I have the proxy supported by Postman running. I'm using this to capture requests from integration tests.
I can see the requests in the history tab, but request details do not include response data, such as http code, response body etc.
If I click send, i.e. repeat the request with Postman, then this data is displayed.
I'm really confused here, since Postman is the proxy and is able to capture the request and response both, why on earth it won't bother displaying the response data, and only display details of the request?
How do I display the response to captured requests from another process??
To provide further details: I'm using the proxy, not the interceptor because I'm making calls to localhost and interceptor won't capture those.
Here is what the UI looks like, with the giant question mark showing the empty response section :)
The entries in the history tab are generated by integration tests making calls to a development server running on localhost.
If I repeat the particular (currently selected) request by clicking the send button, it'll display the json response happily.
Postman is the latest version (as of the date and time of this post) running under WSL2 with Ubuntu 20.04
Since version 8.9, Postman now allows you to capture responses along with requests.
I am trying to write automated tests with Postman. I am new to postman automation world so sorry if the question will seem dumb.
In the api that I need to test when I send a request I immediately receive a response with a transactionID, no matter transaction succeeded or not. Along with my request I send a CallbackURL to the server where I expect the actual transaction result to be called back. The server will do a PUT request back to the CallbackURL that I have provided with the transactionID and the actual response or error.
So the question is, can I have such kind of scenarios in my postman tests?
I guess I should run a web server and expose an endpoint which will expect a PUT request and I should get the body of this PUT request in my tests to check it, and respond back to it with success.
In other words, within my script I need to perform the following actions:
Do a request to the server passing a callback URL
check the immediate response from the server and keep the returned transactionID
Have a webserver run with an endpoint that I passed as a callback URL
Expect a request to that endpoint with transactionID and actual response
Check that the response is what I actually expected
Respond to the request with success
I was thinking about Postman Mock server, but seems it is not designed for such usage.
I also think may be I can run some JS Webserver (may be nodeJS) inside the postman Sandbox...
Actually I am very new to postman testing and I am really confused about this kind of issue. Is it even possible to do this with postman or I need something else?
There are some features provided by POSTMAN which can help you to resolve your problem
When you do request to server passing callback URL it gives you transactionID in response. Save that transactionID in environment variable or global variable. Same you can do it for callbackURL.
Eg. pm.environment.set("transactionID", transactionID);
Then you can do the second request where you passed callback URL and transactionID which you have already.
In short in POSTMAN there are features like
Set global and environment variable which helps to pass some values fetched from response to another request.
call other request on success of first request
eg. postman.setnextRequest({{requestname}});
If you can mentioned your problem statement little bit in details it will be easy to answer in better way.
Hope This Will Help You
Is there any way to access the response and request properties of the last run postman call using pm api's. In other words, does postman keep any historical log which is accessible till at least the last request.
Something like:
pm.lastResponse.body or pm.lastRequest.Url
You can save the response from the last call to an environment variable and get it on the next one
http://blog.getpostman.com/2014/01/27/extracting-data-from-responses-and-chaining-requests/
I made an application using Qt/C++ that reads some values every 5-7 seconds and sends them to a website.
My approach is very simple. I am just reading the values i want to send and then i make an HTTP POST to the website. I also send the username and password to the website.
The problem is that i cannot find out if the request is successful. I mean that if i send the request and server gets it, i will get an HTTP:200 always. For example if the password is not correct, there is no way to know it. It is the way HTTP works.
Now i think i will need some kind of a protocol to take care the communication between the application and the website.
The question is what protocol to use?
If the action performed completes before the response header is sent you have the option of adding a custom status to it. If your website is built on PHP you can call header() to add the custom status of the operation.
header('XAppRequest-Status: complete');
if you can modify the server side script you could do the following
on one end :
You can make the HTTP post request via ajax
and evaluate the result of the ajax request.
On the serve side
On the HTTP request you do your process and if everything goes accordingly you can send data back to the ajax script that called it.
solves your problem .. ?