6

I searched around and couldn't find how to test a file download box using capybara/cucumber?

The following image asks the question much clearer.


How to test file download using capybara

millisami
  • 9,931
  • 15
  • 70
  • 112

3 Answers3

2

This was similar to another question I just answered, hope it helps Anybody have idea how to test file download using cucumber?

Community
  • 1
  • 1
ToreyHeinz
  • 585
  • 1
  • 4
  • 16
  • 1
    Well I tried it but the first 'Content-Type' assertion blows up with ` Failure/Error: result = page.response_headers['Content-Type'].should == "application/octet-stream" Capybara::NotSupportedByDriverError` – millisami Mar 18 '11 at 06:39
  • What version of Capybara do have? I was using `capybara (0.4.1.2)`. – ToreyHeinz Mar 18 '11 at 11:02
  • OOOPS.. What version of Capybara do have? I was using `capybara (0.4.1.2)`. In your step try just `puts page.methods.sort` and see what you get. If response_headers exists then try `puts page.response_headers`. – ToreyHeinz Mar 18 '11 at 11:08
  • 2
    I upgraded to 0.4.1.2. The method `response_headers` does respond but when I try to lookup `page.response_headers`, I get `(rdb:1) p page.response_headers Capybara::NotSupportedByDriverError Exception: Capybara::NotSupportedByDriverError` – millisami Mar 21 '11 at 11:19
1

@Millisami Capybara::NotSupportedByDriverError Fixed for me!

What i had to do is removing the @javascript tag from my cucumber test, which was included. I mean:

@search Scenario: Recieving a file ...

instead of

@search @javascript
Scenario: Recieving a file ...

Hope it helps :-)

viktorvogh
  • 51
  • 1
0

The download box is a function of the browser. Capybara simulates a browser but without all the UI etc.. (e.g. it looks like a browser to your application, so using it you'd mostly skip over the whole file download UI stuff. It would look to the browser like someone did whatever they needed to in order to tell the browser where to put the file and start the download)

If you are trying to test a download box, (beyond clicks needed to start the download) you are now testing the browser, not your application. As yourself if that's part of your charter and worth your time.

To actually test the download box you are going to have to have a browser instance going, and use a tool like Firewatir/Watir or Selenium, to actually 'drive' the browser, and some other gem to actually automate up at the OS UI level (on windows we usually use autoit) in order to click things and fill in values of the browser's file download UI.

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
  • Thanks for the explanation. But I am no longer in this project. And as you've explained its like testing the browser itself, I won't bother to look for such kinda test anymore. – millisami Jul 14 '11 at 08:53