How to open a PDF file that is present with API response in karate? - karate

We have an API with just retrieves PDF from a Server. So when the API is hit, we get this as response.
In SOAP UI, there will be an attachment tab from which we can open the PDF file.
Is there a way to do this in Karate.?
We are trying to move towards Karate

Being able to preview a PDF is for manual testing and Karate is a test-automation tool. So it is not supported and my suggestion is that you don't worry about this and move on. In my opinion this is not a mandatory requirement for you.
What is important is to be able to do a comparison. If you are doing an exact binary match, this is already possible, refer: https://stackoverflow.com/a/55147777/143475
You may be able to embed a PDF into an HTML report, refer: https://github.com/karatelabs/karate/tree/v1.2.1.RC1/karate-demo/src/test/java/demo/embed
Finally if you really insist on "opening" the PDF somehow during a test, you can use the ability of Karate to call command-line programs. For example open foo.pdf works on a Mac. Refer this: https://stackoverflow.com/a/62911366/143475
EDIT: Karate has visual testing in version 1.3.0 onwards, perhaps you can give this a try: https://github.com/karatelabs/karate#compare-image

Related

Selenium and Postman integration or other approach?

I am looking for general idea, approach and subsequently a right tool.
I plan to start testing administration panel. Stable parts of it can be tested by mean of selenium-python scripts. But the challange starts when before testing some funcionalities in panel I need to sent a batch of data via Postman to API endpoint.
As you know Postman is a native app, so it doesn't offer a url which selenium driver could access (browser extension is deprecated.
So the question is. Would it be possible to integrate and automate the process in one selenium script?
Is it possible to do it with Postman or there is another tool that can send a request to endpoint and can be integrated with selenium script?
One more thing. The best approach would be: Sending request and few second after that action start selenium test on data which have been delivered via request to panel. I need to fully automate the process and set those actions with no sighnificant time delay.
Curious about possible solutions.
For API Automation purpose, Use Rest Assured. Its easy to learn, implement. You'll be able to fully automate apis(both JSON & XML). All the validation will be done in seconds. If you integrate RestAssured & Selenium, you'll be able to validate data with API & front end.
Please let me know if you need to know more on this.
Sample GET Code :-
RestAssured.baseURI="base url Eg :- https://www.google.com/";given().header("Accept","application/json").header("Authorization","Value").when().get("rest of the part of the url").then().assertThat().statusCode(200).and().contentType(ContentType.JSON).and().body("name[0]",equalTo("Location"));
Sample POST Code :-
RestAssured.baseURI="https://www.google.com/";
Response res=given().header("Authorization","Value").header("cache-control","no-cache").header("content-type","application/json").body("{"+"\"format\":[\"live-blog\",\"video-story\",\"Photo Gallery\",\"photo-gallery\",\"blank\",\"breaking-news\",\"photo-story\"],"+"\"language\": \"english\""+"}").when().post("Rest of the url`enter code here`").
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).extract().response();
String res_string= res.asString();
System.out.println(res_string);
JsonPath jpath = new JsonPath(res_string);
String articleid = jpath.get("[0].articleId");
System.out.println(articleid);
You can find all the jar files online.
Apologies for the format.
Selenium purpose is not testing your app's APIs, but web. I would suggest as someone commented here, use Java with Rest-Assured, it's very reliable, easy to learn, and fast.
You can use Java's API call if you need anything specific for your web testing, as a requirement or something else.
Since you are using Python already, you could easily use the 'requests' python package to send your API requests and parse the responses as required. This would allow you to easily integrate this into your overall script, sending the api requests, ensuring the necessary response, then starting the selenium steps.

SAP BI Open Doc URL for retrieving pdf

In a reporting application we use, we were using BI 3.x API to produce Web reports. While doing the migration activity to 4.x version, we thought it is fine to go with open doc url rather than doing the report generation through API.
Many of the samples I have seen uses sIDType and iDocID parameters along with Token value to retrieve the document by constructing a URL like below http://server:port/BOE/OpenDocument/opendoc/openDocument.jsp?token=[LogonToken]&iDocID=[XXXX]&sIDType=CUID
But all those URLs get HTML page as response from BI 4.x SAP webservice, the java script in that HTML page does the task of retrieving the pdf file.
I am just wondering if there is any way I could retrieve the pdf report as response from the BI Webservice directly ? Please assist me on this. Thanks
You can if you use the REST SDK to retrieve the document, refresh it and then export it to PDF.
In short, these are the steps:
Logon: POST /biprws/logon/long
Get the doc's prompts (if any) GET /biprws/raylight/v1/documents/5690743/parameters
Pass the correct values for the prompts (if any) and refresh the document: PUT /biprws/raylight/v1/documents/5690743/parameters
Export as PDF GET /biprws/raylight/v1/documents/5690743
That last step requires you to pass Accept: application/pdf in your HTTP headers to get the PDF version.
Detailed information on the REST SDK and the different steps listed above is available on help.sap.com (look for the manual SAP BusinessObjects RESTful Web Service SDK User Guide for Web Intelligence and the BI Semantic Layer).
Use sOutputFormat=P to always retrieve the PDF of the report using open doc

Chromium PDF Service

I am wondering if it would be possible to build a print service using the chromium project source code. The idea would be people clicking a print button on our web page would send a call to this service which would return a PDF rendering of the page?
Yes, on the server side you have a CGI script to do the conversion. You can reply with a link to the document, or you can e-mail it. You need to ensure the user spaces are kept separate and that the documents are kept on the server long enough for them to download.
Or you can rely on the observation that many people have PDF output pseudo-devices and can print the page locally.

How to View a Google Spreadsheet Doc as a PDF

I would like to know if it's possible to view a Google Spreadsheet Doc as a PDF without first manually converting it as a PDF? I don't want to share a link directly to the spreadsheet, I want to share a link to a PDF version of it which ends up looking better (in Print View rather than Spreadsheet Document View)
I know I can Print > Save as PDF, then download to local machine, then upload and save somewhere on my server. But is there is a way to be able to view the spreadsheet as a PDF.
I have Google'd this and found nothing. The best I could come up with is the Google Document Viewer (https://docs.google.com/viewer) but that does not seem to give mt the option I am looking for. Further, I do not want to install any Chrome plugins, etc. because I want to be able to share a link to the PDF with people but not have to have them install a plugin to see the doc.
Unfortunately, what you are trying to do and the way you are trying to do it is not a capability within Google Docs. Sorry.
I think the best way is to use Google Drive API to write own script that will do this job. I mean:
You have a web server
Write a simple method in any web technology, such as PHP, Python, Java, C#, whatever you like and your server is able to serve. This method is connected to the google drive through it's API to your account, knows which spreadsheet to take care of and how to understand the columns. This spread should be parsed to HTML and with some popular tool (proper for your programming language or server's operating system) you create the PDF. The method should create HTTP response with header type: application/pdf.
You provide interested people with the link under which your method is available.
I guess this reference should help you to use Google API:
How to download the resources:
https://developers.google.com/drive/web/manage-downloads
How to convert (i.e. to PDF) and open the resources in your own application:
https://developers.google.com/drive/web/integrate-open#open_and_convert_google_docs_in_your_app
I hope this helps.

How to process values entered into an interactive PDF form on the server?

A client is asking how to create an interactive PDF form with functionality that allows the values entered into the form to be processed on the server.
From what I've read, the best way to do this is to program the submission by embedding javascript into the PDF file via Acrobat, then writing code on the server side to handle the submission.
Does anyone have experience doing this sort of thing? Is the best way to do this indeed by using javascript in the pdf file and using that to post the form values to the server-side form processing method?
If you do that, is there any way to pass back values to the PDF file that the form processed successfully?
We have used the DynamicPDF viewer from ceTE software.
http://www.cete.com/
If the requirement is just to pull data out of PDF form fields, Javascript may not necessarily be required. Javascript can certainly be used with form fields to handle certain requirements (oftentimes auto-calculation and validation), but it might be overkill for just setting and getting data.
There are APIs that will set and get data from PDF form fields pretty easily. One toolkit that does so is EasyPDF SDK, which has a PDFDocument class designed for exactly this:
http://www.pdfonline.com/easypdf/epsdk_manual/index.htm?page=reference%2Fpdfdocumentsdk%2Fpdfdocument%2Fdescription.htm
Whether it will work for your needs will depend largely on whether the PDF has already been created or not. If it's already been created with fillable form fields, then EasyPDF SDK can be used to read data from the fields and insert data into them. But if you don't have the PDF template created yet, then you'd need Adobe tools like Acrobat Professional to do that first.
I will disclaim that I am part of the engineering team for EasyPDF SDK, so I have a vested interest in the tool. But it's nifty and easy to use, and is geared for server side deployment, so feel free to check it out at http://www.pdfonline.com if you feel so inclined. Hope this helps.