My Assertion is failing on newman but not Postman - postman-newman

My Assertion in Postman are passing. However when I run it on Newman ther are failing
This are the response on Newman
expected '{"code":"HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported"}' to deeply equal 'Success' at assertion:3 in test-script

Related

How to get newman results in Email body

I am executing Postman collection using newman and for sending a mail using the VBScript file. I have configured newman and vbs file as a job in Jenkins. Is it possible to get the either the newman results or Jenkin console results in Email body?
Results with Testcase name with Pass or Fail

Getting only one line i.e Configure Successfully message in postman in json but when added in json file for asserting its taking as invalid [duplicate]

We are testing API Automation with Rest Assured in Java.
In Postman, we run API after success gives message as "Record Saved Successfully"
Trying to automate the same. How to validate only message recieve as response in body.
response.then().assertThat().statusCode(200);
.and().body("$", "Record Saved Successfully");
its not working, Please help
Use built-in assertion mechanism:
response
.then()
.assertThat()
.statusCode(200)
.body("message", equalTo("Record Saved Successfully"));

POST in JMeter gives "Unrecognized token 'json'"

I can not figure out why I get this error:
"Failed to parse request body as JSON resource. Error was: Failed to parse JSON encoded FHIR content: Unrecognized token 'json': was expecting ('true', 'false' or 'null')\n at [Source: UNKNOWN; line: 3, column: 29]"
FHIR is the standard used. I also tested with a valid JSON that worked with Postman, so I don't think the actual JSON is the issue.
I'm not sure if I'm correct, but it seems JMeter adds 'json' from somewhere as the error states the token 'json' is unexpected. This is the Request > Request body tab in View Results Tree.
This is just a test JSON, but I got the same response with a JSON body that is working in Postman (and I formatted correctly to be sure). I have the Content-Type header specified. I simply don't understand where the token 'json' would come from as my json itself doesn't contain the token. Does anybody know if JMeter adds something to the request?
You're sending incorrect payload, it should look like:
{
"test" : "X"
}
and you are sending
{
"test" : "X"
}json
^^^^ this guy is causing the issue
JMeter doesn't add anything to request, you need to double check your configuration, i.e. JMeter jmx scripts are "normal" XML files so you can use your favorite text editor to look up this json
If you're able to send a valid request using Postman you should be able to record it using JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy and run your request/collection - JMeter will capture the requests and generate relevant HTTP Request samplers which can be replayed successfully.
More information: How to Convert Your Postman API Tests to JMeter for Scaling
It happened to be that if you add a default parameter in an HTTP Request Defaults (in my case _format=json), it would add it to the body of the POST.
I fixed this by adding a BeanShell PreProcessor with the code:
if(sampler.getMethod().equalsIgnoreCase("get")){ sampler.addArgument("_format", "json"); }

How to deal with JSON array in http requests by using robot framework

I need to send PATCH request with the following JSON data:
${jsonString} Set Variable [{"alias":"EMAIL_ORDER_CONFIRMATION","templateId":"${templateId}"}]
${resp}= Patch Request httpbin /templates data=${jsonString} headers=${headers}
But when I run the test I am getting error message:
[ ERROR ] Parsing of dictionary [{"alias":"EMAIL_ORDER_CONFIRMATION","templateId":"12345678-1111-1111-1111-11111111"}] failed.
| FAIL |
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3 path $[0]
As I understood the problem is that my JSON file contains [], but I need to handle this some how. I am using HttpRequestLibrary, because our project is Java based and I can't use python based robot libraries.
Only one solution what I found is using files=${files} instead data=${jsonString}:
${data}= Get Binary File ${CURDIR}${/}..${/}resources${/}${jsonImportFile}
${files} Create Dictionary file ${data}
${resp}= Patch Request httpbin /templates files=${files} headers=${headers}
didn't help, body is empty with this approach and I am getting PayLoad validation error.
Does anybody had this problem? If so please help how to deal with this type of JSON file

How to retrieve Json error from Zuul Filter

I am using Postman to send a request to the Zuul proxy. Zuul proxy is running on the port 8085
(http://localhost:8085/helloworld)
I am having a zuul filter and calling a micro service from the zuul filter using Spring RestTemplate. Micro service is running on 8089
ResponseEntity<String> response = restTemplate.exchange(
"http://localhost:8089/helloworld", HttpMethod.GET, entity, String.class);
When I get a successful response from the microservice, I am receiving a successful JSON object response in Postman.
But when an error/exception is returned from the microservice, the zuul filter does not send it back it to the calling client. I am getting an empty body with httpstatus message 200 in Postman, even though microservice returned a 500 error.
I tried to send the microservice response using
ctx.setResponseBody(response.getBody());
Basically this will convert the JSON response from the micro service into a String. I was able to get the response as a String object in the Postman.
Could anyone help me how to get the error/exception response as JSON object from the Zuul filter.