Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 308
barek2k2 Avatar asked Nov 01 '22 00:11

barek2k2


1 Answers

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`

like image 190
barek2k2 Avatar answered Nov 09 '22 09:11

barek2k2