parent
8e3816e64e
commit
2af9ccddf1
4 changed files with 77 additions and 8 deletions
|
|
@ -1,11 +1,20 @@
|
|||
@wip
|
||||
@javascript
|
||||
Feature: Download Photos
|
||||
|
||||
Scenario: Download my photos
|
||||
Given I am signed in
|
||||
And I click on my name in the header
|
||||
And I follow "settings"
|
||||
Scenario: Request my photos
|
||||
Given I am signed in
|
||||
When I click on my name in the header
|
||||
When I follow "Settings"
|
||||
Then I should be on my account settings page
|
||||
And I follow "download my photos"
|
||||
Then I confirm the alert
|
||||
When I follow "Request my photos"
|
||||
Then I should see a flash message indicating success
|
||||
And I should see a flash message containing "We are currently processing your photos"
|
||||
|
||||
Scenario: Download my photos
|
||||
Given I am signed in
|
||||
When I did request my photos
|
||||
And I click on my name in the header
|
||||
When I follow "Settings"
|
||||
Then I should be on my account settings page
|
||||
When I follow "Download my photos"
|
||||
Then I should get a zipped file
|
||||
|
|
|
|||
|
|
@ -219,3 +219,11 @@ end
|
|||
When /^I click the sign in button$/ do
|
||||
click_link "Sign in"
|
||||
end
|
||||
|
||||
Given /^I did request my photos$/ do
|
||||
@me.perform_export_photos!
|
||||
end
|
||||
|
||||
Then /^I should get a zipped file$/ do
|
||||
expect(DownloadHelpers.download).to end_with("zip")
|
||||
end
|
||||
|
|
|
|||
40
features/support/download_helpers.rb
Normal file
40
features/support/download_helpers.rb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Credits goes to Steve Richert
|
||||
# http://collectiveidea.com/blog/archives/2012/01/27/testing-file-downloads-with-capybara-and-chromedriver/
|
||||
module DownloadHelpers
|
||||
TIMEOUT ||= 5
|
||||
PATH ||= Rails.root.join("tmp/downloads")
|
||||
|
||||
module_function
|
||||
|
||||
def downloads
|
||||
Dir[PATH.join("*")]
|
||||
end
|
||||
|
||||
def download
|
||||
wait_for_download
|
||||
downloads.first
|
||||
end
|
||||
|
||||
def download_content
|
||||
wait_for_download
|
||||
File.read(download)
|
||||
end
|
||||
|
||||
def wait_for_download
|
||||
Timeout.timeout(TIMEOUT) do
|
||||
sleep 0.1 until downloaded?
|
||||
end
|
||||
end
|
||||
|
||||
def downloaded?
|
||||
!downloading? && downloads.any?
|
||||
end
|
||||
|
||||
def downloading?
|
||||
downloads.grep(/\.part$/).any?
|
||||
end
|
||||
|
||||
def clear_downloads
|
||||
FileUtils.rm_f(downloads)
|
||||
end
|
||||
end
|
||||
|
|
@ -21,7 +21,17 @@ Rails.application.routes.default_url_options[:port] = AppConfig.pod_uri.port
|
|||
Selenium::WebDriver::Firefox::Binary.path = ENV["FIREFOX_BINARY_PATH"] || Selenium::WebDriver::Firefox::Binary.path
|
||||
|
||||
Capybara.register_driver :selenium do |app|
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox)
|
||||
profile = Selenium::WebDriver::Firefox::Profile.new
|
||||
# Set the download directory to "tmp/downloads"
|
||||
profile["browser.download.dir"] = DownloadHelpers::PATH.to_s
|
||||
# Save the file instead of opening it
|
||||
profile["browser.download.folderList"] = 2
|
||||
# Hide the download Manager
|
||||
profile["browser.download.manager.showWhenStarting"] = false
|
||||
# Suppress "open with" dialog for zipped files only
|
||||
profile["browser.helperApps.neverAsk.saveToDisk"] = "application/zip"
|
||||
# Start Firefox using our profile
|
||||
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
|
||||
end
|
||||
|
||||
Capybara.register_driver :mobile do |app|
|
||||
|
|
@ -70,4 +80,6 @@ include HelperMethods
|
|||
|
||||
Before do
|
||||
Devise.mailer.deliveries = []
|
||||
# Delete all files in "tmp/downloads"
|
||||
DownloadHelpers.clear_downloads
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue