I am using Watir to log into an application, push some buttons, etc… Basically the normal stuff that a person would use Watir for.
However, my problem is that there is one particular page that I need to test. It’s actually a dynamically-generated PDF and I need to get the actual binary data from it, so that I can load it using a certain gem that we’re using. This normally works with static PDF files because we can just use:
open("http://site.com/something.pdf")
This works for static PDFs. However, for a dynamically generated one it doesn’t work because we are using Ruby to send the HTTP request and it is not aware of the headers/cookies/session that Watir is using. So instead of getting the actual PDF we get a login page.
Another thing we tried was to use Watir to get the PDF:
@browser.goto "http://site.com/dynamic/thepdffile"
@browser.text
@browser.html
We tried getting the text or html from the page, but no luck because firefox creates a DOM when loading a pdf so the text is an empty string and the html is the DOM that firefox creates when viewing a pdf page. We need the raw HTTP response and there doesn’t seem to be a way to extract that.
So we need a solution for this and in my opinion we have these options:
- Figure out a way to use “open” or similar method in Ruby, using the session from Watir.
- Figure out how to use watir to get the binary http response from the PDF page.
- Disable the pdf plugin (which doesn’t seem possible) such that the “save as” dialog appears.
Or if you have some other idea please share! Thanks in advance!
I figured out a solution.
In the profile for firefox you can set the plugin.scan.Acrobat to “999” which will effectively disable the PDF plugin.