webkit - Test file download with Capybara and Cucumber -


i trying test download using capybara , cucumber.

the test steps like:

when(/^i export csv$/)   export_button = find("div.results-table input[type=\"submit\"]")    export_button.click end  then(/^i should prompted download csv$/)   capybara.current_driver = :webkit #switch driver can see response_headers   page.response_headers['content-disposition'].should include("filename=\"transactions\"") end 

i had add capybara webkit driver in middle of test can use response_headers, response_headers seem return empty object. using default driver before because need click button, wonder if switching drivers why not getting in response_header?

i have done in recent project shown below

given download folder export empty ,   joe clicks "download csv" button  contents of downloaded csv should be: |team_id | team_external_id | type | reg_option      | team_reg_bracket | race_name  | wave      | bib | bracket | status    | team_name | team_type | athlete_count | min_members  | max_members | team_members | |    8   |                  | team | 10k aggregate   | n/a              | 10k        | universal | 208 | overall | dnf       | team 08   | aggregate |0              |              |             |              | 

and capybara cucumber like

given(/^download folder export empty$/)   fileutils.rm_rf('/home/vagrant/downloads/') end  and(/^(\s*) clicks "([^"]*)" button$/) |user, arg|   button = find_button(arg)   button.click end  , /^the contents of downloaded csv should be:$/ |table|   in 0..5       if(dir.glob('/home/vagrant/downloads/*.csv'))         break;       end       sleep(1); // if not found wait 1 second before continue looping   end    if(dir.glob('/home/vagrant/downloads/*.csv'))     dir['/home/vagrant/downloads/*'].each |file_name|       arr = csv.read(file_name, :col_sep => "\t", :row_sep => "\r\n", encoding: "utf-16:utf-8")       table.raw[0...table.raw.length].each_with_index |row, row_index|         row.each_with_index |value, index|           if arr[row_index][index] == nil             arr[row_index][index] = ""           end           if index == 1           else             puts "#{index}" + 'value in table = ' + "#{value} + 'value in file' + #{arr[row_index][index]}"             value.should eq arr[row_index][index]           end         end       end     end   else     puts "/home/vagrant/downloads/*.csv file not found!"   end end 

hope resolves problem downloading csv , verifying contents :)


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -