Postman: Generating POST request body from GET response - swagger

I generate an API and Collection for my app by applying the steps on the following article: The hidden gem: Postman API and Documentation feature.
You may try by using a test endpoint e.g. https://petstore.swagger.io (user:test, pass:abc123).
Here is an example json body that I am trying to generate:
{
"name": "{{$randomLoremSentence}}",
"description": "{{$randomAdjective}}",
"productUuid": "{{productUuid}}",
"address": "{{$randomLoremSentence}}"
}
However, I am looking for a practical way for generating json body for Postman requests. Is there a proper way for this? Or do ı have to build each request manually? I think there must a a smarter way. Any idea?

The JSON response body is not created within POSTMAN, it is generated by the response from a web API HTTP request.
The API method that is executed determines the response.
Once you have determined the response and it's structure, you can then create the request and test script within a POSTMAN Collection.
It is easier to manually test each HTTP request with sample inputs then copy that into an existing Collection, then write the test scripts for each test case, template any input parameters into URL query strings or the
JSON request body with global or collection scoped variables.
After you have determined how to parameterize and template each request (and both the Test Script and Pre-request Script), you will then be able to
implement the test script to create assertions on the JSON response content using BDD expressions.
I recommend looking at the POSTMAN documentation at
https://learning.postman.com/docs/writing-scripts/test-scripts/
https://learning.postman.com/docs/writing-scripts/script-references/test-examples/
as it shows some really good examples on how to create a basic test, then automate it using JavaScript, Chai BDD language and the POSTMAN Collection Runner.
This is based on my experience with POSTMAN. I am not aware of any simple way
to automate request and test script creation from API Swagger definitions as every API method response could have any number of potential responses based on different inputs, so this (I believe) has to be constructed manually by the tester.

Related

Nim - How to access raw POST request body in prologue framework

I recently picked up Nim and am in the process of re-implementing an existing web-application of mine to get some experience in the language.
This web-application used JWT for authentication, with the typical split into an access-token and a refesh-token.
The old way my application did refresh, was by receiving the refresh token via a POST request. The request body of that POST request would just be a raw JSON string and my application would grab the string off of that body and do its magic. The string would look like this:
{"refresh":"<JWT TOKEN STRING>"}
I've run into an issue when I wanted to access that raw JSON string in Prologue. There doesn't seem to be a way to do this.
When looking at the context's request, neither the PostParams nor the FormParams contain anything, they're empty. I can't find anything in the documentation about JSON-request bodies either and nothing in the source code looks like it is what I would want.
Is there no way for me to access the raw request body? Am I forced to change the way I send my refresh token?
After some more skillfull searching through the documentation I stumbled upon the answer I desired. There is a body() proc that allows you to access the raw HTTP body.

Add the Auth2.0 within Jmeter from Postman to generate Token

Hi I have a collection in Postman which will not work unless i have a token and in order to
generate this token i have to add the following details per the image.
I want to add these same parameters within Jmeter so that my APIs will work... This is Auth 2.0 how can i add all those values within Jmeter...?
There is no single place where you can put these parameters in JMeter because OAuth 2.0 is a series of requests/responses so you need to implement all these requests which Postman makes under the hood with JMeter's HTTP Request samplers and perform the correlation of the dynamic parameters.
The requests can be even recorded using JMeter's HTTP(S) Test Script Recorder if you configure Postman to use JMeter as the proxy

batch url execution with redstone

I am creating a rest api with redstone and dart.
Now I need to create a way to send several commands of the api in one POST.
Edit (#Pacane): Yes, the idea is to have one endpoint that can parse several commands within the api. Each command is another endpoint(Route) that can be accessed singularly within the API.
My question is how I can parse, executes the URLs and get the response for each URL using redstone.
I am thinking about using the unittest mock request and mock response. You can see here:
https://github.com/redstone-dart/redstone/wiki/Unit-test
Now I wonder if the mock request and response are different somehow from regular requests, if they use some analysis or something like it that would harm performance.
So, there are 2 questions:
1) is it ok to mock the redstone to parse several URLs?
2) if not, how could I do it?
thanks
I ended up using the MockRequest and MockResponse to achieve the batch commands. You can know more about it at the wiki: https://github.com/redstone-dart/redstone/wiki/Unit-test

CXF post api fails via jmeter

Trying to automate my test cases using jmeter. I have used cxf for rest apis on my web server. I have an api which actually takes a java object as parameter. On jmeter I have selected the POST method under HTTP-request and sending json data in Body data. The api gets called fine. However the parameter comes null and hence by api fails. I did try changing the parameter to String object, however I get this string as null.
Is this the right way to call apis via jmeter. Or is this failing because I have used cxf on my server.
Any help is appreciated.
Thanks
Most likely you need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
See Testing SOAP/REST Web Services Using JMeter for detailed explanation on JMeter configuration for REST API testing.
Other thing you could try out is using SoapUI tool to send the request to your CXF endpoint and if it succeeds - inspect the request and configure JMeter accordingly. By the way, SoapUI has some limited load testing capabilities, may be it will be enough for your scenario

Recorded Scripts in JMeter doesn't make an order due to csrf token in URL

Using Jmeter GUI, I recorded a test scenario (placing an order) and the script ran successfully. But when I replay the test scripts it doesn't function as it was recorded to do, it did not make an order.
After query the dev, found that with each item selected, the server generate a CSRF token, and put the token in the URL path (Like: /cart/add/type/product_id/7245985/_csrf_token/b46c0aec2e5891808ec42141b1956943204ae8f8) when the item is added to the shopping cart. This is all recorded in the script. This path with the token is used to add the item to cart.
My question is how to test this dynamic token when it is concatenated in the path of URL?
Any help are appreciated.
If you have not already added Tree View Listener to your Test Plan, then add it now. You can use it to view the details of requests & responses. JMeter considers a request successful if it gets "some" response from Server-side. It does not matter if the response is functionally valid or not. So, in order to make sure that JMeter is sending valid parameters and receiving expected response, you will have to check the details of requests / responses in Tree view listener.
You can also add Response Assertions to requests so JMeter itself verifies that it is getting expected responses.
Important Tips:
Use TreeView Listener for debugging only. In real load test keep it disabled as it consumes lot of memory.
Do not use response assertions excessively as they consume lot of memory as well.
JMeter is not a browser-based tool. It just deals with back-end requests. Hence it is expected to be very fast. So nothing wrong with that. You should remove un-necessary timers as there is nothing wrong with it being fast.
If your requests involve some kind of login authorization then have a look at this question for further details Load testing using jmeter with basic authentication
Recording doesn't guarantee working script, it gives you only a "skeleton" and usually you need to perform some correlation (the process of extracting mandatory dynamic parameter from previous response and adding it to the next request).
Reference material:
Building a Web Test Plan
Building an Advanced Web Test Plan
How to use JMeter for Login Authentication?
How to make JMeter behave more like a real browser

Resources