1

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.

Community
  • 1
  • 1
sujay
  • 681
  • 1
  • 8
  • 23

1 Answers1

1

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

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • file-1-time-stamp.pdf was just an example. the file name can completely vary based current user logged in and the content on that page. So I am not able to use regex. Also do you have an documentation link where it is stated that "download is not supported" it would really help conclude my efforts. – sujay Dec 30 '16 at 15:03
  • @sujay When testing an app you control the current user, data loaded by the table, etc so you should know enough of the file name to test it with a regex, – Thomas Walpole Dec 30 '16 at 17:13
  • @sujay here is the phantomjs open issue on downloading files https://github.com/ariya/phantomjs/issues/10052 – Thomas Walpole Dec 30 '16 at 17:16
  • we do control the current user, but as far as the content of the page goes, we have the same spec running against different environment so the data loaded depends on what env the app is running. Thanks for the link. I will go ahead and accept your answer :) – sujay Dec 30 '16 at 18:19