So I have a print form to a pdf button, and want to save that pdf for further comparisons in the same testcase.
Is there a way to use Browser keywords, such as “Promise to wait for download” to download pdf to current directory?
I have tried many ways without succeeding, the problem being that “save file as” is not part of the browser context. I can get to the stage where pressing print would get me to “save file as” part when manually doing the steps.
Also as the pdf is generated at that instance, there is no direct url to file
Been there too, where I needed to check pdf content, and also get a screenshot of the content.
From my understanding and search in ways to interact with the PDF viewer, main issue is that buttons (i.e. the print/download one) are in shadow-dom and not easily interactable.
On my side I finally choose to do this :
Start browser (Chrome here) with options to directly download the file
Check content with PyPDF2 and a .py file
Eventually , as the PDF is directly downloaded and not displayed , open it to perform the required screenshot. Note here that it’s OK while your content his in first page
Challenging thing then is if you need to scroll down the pdf for visual checks.
How do you directly download the pdf?
That has been my issue, cant seem to be able to get that file for comparison.
In my case there is no one file to download, so I could use that Download -keyword properly.
I would like to ask for your assistance with opening a PDF file in a new tab and then taking a screenshot of the PDF using Robot Framework.
I tried to open the PDF using a URL format like this: file://.../.../file.pdf, but it cannot open properly. Could you please help me resolve this issue?
If you simply need to open as you required you can do something like this.
It considering you already have a browser opened, and just need to open, screen then return to the first browser instance:
VAR ${chrome_options} *your_options*
Open Browser about:blank chrome options=${chrome_options}
@{browserID} Get Browser Ids
Go To file://${pdfpath}
Sleep 1s # Wait that the pdf/page is visible, to adapt
Capture Page Screenshot mypage.png
Close Browser
Switch Browser ${browserID}[0]
Note however that with Chrome and Selenium, this will open the file with Chrome Viewer which uses shadow-DOM, so you won’t be able to interact easily (or at all). You would need to use js or even Browser library).
If you need more than that, such as comparison, I would highly suggest you use a library like this:
You can easily download file as you did, get the latest pdf with a small RF script based on file modified nfo or naming, then pass it for to *Compare Images* keywords.
You can also use masks if you a have non fixed values such as date or our pattern.