json to pdf
I have a REST API service and the response is a pdf file.
When I execute the API test in Postman, it says: cannot show content download it. And that works just fine, the pdf is visible.
When I execute the same API test in UFT v14.50, the StatusCode = 200 but the content is the problem.
Properties \ RequestHeader name = Accept
Properties \ RequestHeader value= application/pdf
So far as i know, the Request body and Response body are not needed.
Any idea how to solve this, how to create a pdf output file?
Re: json to pdf
The issue is solved with help of the tool Postman.
When I execute the REST API in Postman, Postman is showing a message to download the response which is a pdf document. That is correct. So, now I have an original pdf file which I can use as a reference file in UFT.
In the UFT REST services, I used on the 4th Property tab HTTP the Response body = File and made a link to the pdf file which was created by Postman.
So, every time I execute this same UFT API test, a response file is created and compared with the Postman pdf file. The new created file showing the binary content and luckily that can be compared with a pdf file.
The thing is that UFT cannot handle blob files.
Re: json to pdf
I found a solution to this problem. Maybe you can try the Test User code like this:
1. Add a AfterExecuteStepEvent for your REST activity.
2. Add these code into the event handler method:
//TODO: Add your code here...
// use the actual Activity in your test. HTTPActivity5 is used in this sample.
byte byteArray = this.HTTPActivity5.ResponseBodyBytes;
MemoryStream filestream = new MemoryStream( byteArray );
//file path and file name can be defined here
var fileName = "C:\\tmp\\MyNewFile.pdf";
using (var stream = File.Create(fileName))
This method will try to write the response body (pdf stream) into a pdf file.