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

896 views Asked by At

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

  1. 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).

  1. 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.

1

There are 1 answers

4
Thomas Walpole On BEST ANSWER

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