barek2k2
barek2k2

Reputation: 154

How to download CSV file with poltergeist using Capybara on phantomjs?

For a integration test, I need to download a CSV file using poltergeist driver with Capybara. In selenium(for example firefox/chrom webdriver), I can specify download directory and it works fine. But in poltergeist, is there a way to specify the download directory or any special configuration?. Basically I need to know how download stuff works using poltergeist,Capybara, Phantomjs.

I can read server response header as Hash using ruby but can not read the server response to get the file content.Any clue? or help please.

Upvotes: 5

Views: 997

Answers (1)

barek2k2
barek2k2

Reputation: 154

Finally I solved the download part by simply using CURL inside Ruby code without using any webdriver. The idea is simple, first of all, I submitted the login form via CURL and saved the cookie into my server and then submitted(via CURL) the CVS Export form using the saved cookie like this

post_data = "p1=d1&p2=d2&p3=d3" `curl -c cookie.txt -d "userName=USERNAME&password=PASSWORD" LOGIN SUBMIT_URL`
csv_data = `curl -X POST -b cookie.txt -d '#{post_data}' SUBMIT_URL_FOR_DOWNLOAD_CSV`

Upvotes: 2

Related Questions