Is it possible to test file download in Poltergiest without using selenium or chrome driver - capybara

I am using Poltergiest driver to do headless Browser to test my rails application with capybara Rspec. Everything is working fine.
But I am unable to figure out what is the default download directory, if I download file using poltergeist Or how to verify whether a file download happened or not on a button(link) click.
The rails app I am testing has a button which on clicked initiates a file download. I want to test file-1-time-stamped.pdf is downloaded.
so far I have tried
I tried this answer https://stackoverflow.com/a/16217485/3000299
page.response_headers['Content-Disposition'].should include("filename=\"file.zip\"")
using the above approach is not feasible because the file name is dynamic (file name contains time stamp which is done on server side).
I found an issue logged to Poltergiest which was closed with a suggestion to ask the question over here https://github.com/teampoltergeist/poltergeist/issues/485
is there a way to access the most recently downloaded file?
Any suggests or help would be great.

The latest released PhantomJS doesn't support downloading files, so you are limited to the method, you linked to, of checking response_headers. You mention that it isn't feasible because the filename has a timestamp in it, but as long as you're not trying to verify the exact value of the timestamp portion of it you can use the match matcher with a regex. Something like
page.response_headers['Content-Disposition'].should match(/filename="file-\d+\.pdf"/)
should match filenames like file-1234.pdf

Related

browser downloads rails response as a file

I have been fiddling with rails apps for a while and I sometimes see this behavior on Safari (could be on other browsers as well, not sure) where the browser downloads the response as a file instead of rendering it in the browser. I wonder why that is.
The last time it happened made me decide to ask on stack overflow. My current setup is a very basic rails app that implements devise and I get a file named 'sign_in.admin' with just the following content:
You need to sign in or sign up before continuing.
I know that string comes from the devise locale and is supposed to be rendered with a layout, but the browser just downloads it as a file as if I chose to 'Download linked file as...' It's happened to me before where instead of rails routing me somewhere it downloads a file. Can somebody explain why my browser sometimes does that? I have all the latest updates.

Security issue using Rails, CKEditor, and Roxy fileman

I've been using Ckeditor in my Rails app for a while now, but recently I needed to add the capability to upload html5 videos as well. I added a plugin to CKEditor to utilize the html5 'video' tag, but the generic 'browse server' functionality in CKEditor won't let me upload an mp4 (it just shows the filename as a # sign.)
my solution was to add the Roxy fileman to handle the uploads, and it work great, except there's no security at all in it by default (if the fileman is in a public folder, which is the only way i can see to do it in Rails.)
The only thing Roxy offers is a checkAccess script that gets run before each PHP script gets run, but there's no way for that script to know if the user is logged in or not.
I was thinking I could use x-sendfile to have rails check the permissions, but that seems like using a sledgehammer to hang a picture frame (and it might not even be the right way to do things here.) To me, there should be a simple answer.
Any ideas?

Saxon CE 1.1 - Using result-document to create a output file

I've been playing with Saxon-CE_1.1 over the last few days and have managed to create a little application that allows users to classify pictures according to a data dictionary using a select dialog. All was going really well until I tried to use the result-document() function in it's "classic" way, to create a new file in the file system containing the choices the user has made.
XML Quire is returing with a severe error stating:
XpathException in mode: '{http:saxonica.com/ns/interactiveXSLT}onclick' event: [object MouseEvent]: Expected '?select=' ir '#' at start of result document href found "filename.xml
This error seems, to me, to be stating that I must pipe the results back into the HTML using # or ?select/
Is it still possible to create "external" output using SaxonCE? If so how can I accomplish the task.
Until recently it has not been possible to read or write files in the local client machine from Javascript code running in the browser, and if Javascript can't do it, then Saxon-CE can't do it either.
This may change soon with the HTML5 FileSystem API, but as far as I'm aware support for this is still very patchy. When it appears to be more stable and widespread, we can certainly look at implementing both doc() and xsl:result-document to access local filestore (or indeed, implementing the EXPath file module).

Open a file that is on a file server from a webpage?

I am working on an internal application. We have a website that displays all our SSRS reports for a group of work. I have been asked to see if I can link all the files (pdf, word, excel) for the group of work. These files are stored on a file server that users viewing the reports have access to. Each group has its own group of reports and shared files.
Is it possible to open the files (without downloading them) from a webpage? Meaning that they file is opened from the file server? I don't want people to download a copy of the file.
I am pretty sure this can work with IE because sharepoint does it. However, other browsers may have an issue.
EDIT: What I would like is to have a web page with links to the files. When they click on a link (say for a word doc), word will open the file that resides on the file server. Without out a local copy downloaded from the network share.
EDIT2: Please note, I know what I am asking is probably not possible in all browsers. I am more or less just making sure. It seems possible in IE using activeX, but out side of that browsers do a good job at keeping processes inside a sandbox.
3 options. Remember this is for an internal website.
link to the share using file://. This will have the side affect of downloading the file to be viewed. As long as user clicks open every time it should not be a big deal.
Use JavaScript and activeX to open word (excel, reader, ect) passing in the file path as a command line arguments. This works only in IE and in win7 (probably vista) user will get a pop up asking if it is ok for the activeX control to run.
Create a new protocol. openfile://. This would be set up to run an application that is installed on the client machine which would open the file. Since it is internal, the application could be installed on the machines without issues. This also requires a registry change.
I haven't picked one as this change is still being looked into but i figure I would update this in case someone runs into something similar.

Cucumber, Webrat or RSpec testing file uploading

Background:
I need to perform file uploading. I am currently using Uploadify to push files directly to s3 (but would be happy to use plupload). The files that i am working with are large, and i need to show a progress bar. Everything works fine
Issue / Question: How do I set up a test (cucumber) for this?
Uploadify and Plupload both rely on flash (or silverliht) runtime to interact directly with s3. I am unaware of a way for cucumber or webrat to be able to interact with the flash (or silverlight) to click the "browse" button and select a file.
Has anyone found a solution that they are happy with?
Thanks!
Plupload is still based on an HTML form, which you can see if you turn off javascript and load your uploader page.
Then it's simply a matter of using webrat's 'click_button' in cucumber steps using a file fixture as the input to the file field.
Being brutal about it, this is possibly an example of a trusted externality. Ask yourself "do I trust Uploadify"? In the case that you answer yes, you omit actual upload tests for it and just assert that the form field elements you expect to see are present on the page, and then assuming a mocked response of success/fail that your application does the right thing.

Resources