Testing file downloads with cucumber + selenium

235 views
Skip to first unread message

Toms Mikoss

unread,
Jun 1, 2009, 10:24:47 AM6/1/09
to Cukes
Hello,
I've run into a problem with writing a feature test for downloading
files.
The idea is - user goes to bills page, clicks link next to a bill,
gets that bill in .pdf. Everything is okay up to the very last point -
checking what the application returns after clicking the download
link. After following the link, the 'response' object still contains
the original page with the link, not the returned file as I would have
liked. Is there some other object specially for returned files? Or
what?

What I have in the controller:
respond_to do |format|
format.pdf do
send_file(@bill.file,
:disposition => 'attachment',
:type => 'application/pdf',
:filename => "#{@bill.number}.pdf")
end
end

That action gets called by:
<%= link_to("PDF", formatted_bill_path(bill, :pdf)) %>

The feature step is a simple " When I follow "PDF" ", and the whole
thing is executed by Selenium + Firefox. Help would be greatly
appreciated.

Matt Wynne

unread,
Jun 1, 2009, 10:43:16 AM6/1/09
to cu...@googlegroups.com

I think might be better asking on the webrat mailing list, assuming
you're driving selenium with webrat?

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com

Toms Mikoss

unread,
Jun 1, 2009, 10:55:30 AM6/1/09
to Cukes
Thanks for the idea, will do.

On Jun 1, 5:43 pm, Matt Wynne <m...@mattwynne.net> wrote:
> On 1 Jun 2009, at 15:24, Toms Mikoss wrote:
>
>
>
>
>
> > Hello,
> > I've run into a problem with writing a feature test for downloading
> > files.
> > The idea is - user goes to bills page, clicks link next to a bill,
> > gets that bill in .pdf. Everything is okay up to the very last point -
> > checking what the application returns after clicking the download
> > link. After following the link, the 'response' object still contains
> > the original page with the link, not the returned file as I would have
> > liked. Is there some other object specially for returned files? Or
> > what?
>
> > What I have in the controller:
> > respond_to do |format|
> >  format.pdf do
> >     send_file(@bill.file,
> >            :disposition => 'attachment',
> >            :type => 'application/pdf',
> >            :filename => "#...@bill.number}.pdf")
Reply all
Reply to author
Forward
0 new messages