Highlighted
Contributor.. Bert Contributor..
Contributor..
206 views

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?

0 Likes
4 Replies
Micro Focus Contributor
Micro Focus Contributor

Re: json to pdf

Hi Bert,

As far as I know, UFT can't support to response the PDF file. You can create a ticket about this problem to the supporter.

Thanks & Best Regards,

Mango

0 Likes
Micro Focus Contributor
Micro Focus Contributor

Re: json to pdf

Hi Bert,

As far as I know, UFT can't support to response the PDF file. You can create a ticket about this problem to the supporter.

Thanks & Best Regards,

Mango

0 Likes
Contributor.. Bert Contributor..
Contributor..

Re: json to pdf

The issue is solved with help of the tool Postman.

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.

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.

0 Likes
Micro Focus Contributor
Micro Focus Contributor

Re: json to pdf

Hello Bert,

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))
            {
                filestream.CopyTo(stream);
            }

This method will try to write the response body (pdf stream) into a pdf file. 

Thanks,

Wenwen

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.