mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-17 09:58:28 +08:00
A follow-up to 2d640d58ad.
There was a small regression, where the download directory has changed,
resulting in spec artifact archive pollution. This change keeps all the
improvements from the previous commit, but restores the original save
path.
53 lines
1.3 KiB
Ruby
53 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module PageObjects
|
|
module Pages
|
|
class CSVExportPM < PageObjects::Pages::Base
|
|
def initialize
|
|
super
|
|
@downloaded_files = []
|
|
end
|
|
|
|
def download_and_extract
|
|
original_save_path = Capybara.save_path
|
|
Capybara.save_path = Downloads::FOLDER
|
|
|
|
zip_name = find("a.attachment").text
|
|
zip_path = File.join(Downloads::FOLDER, zip_name)
|
|
@downloaded_files << zip_path
|
|
|
|
page.driver.with_playwright_page { |pw_page| pw_page.expect_download { click_link ".zip" } }
|
|
Downloads.wait_for(zip_path)
|
|
|
|
csv_path = unzip(zip_path).first
|
|
@downloaded_files << csv_path
|
|
CSV.read(csv_path)
|
|
ensure
|
|
Capybara.save_path = original_save_path
|
|
end
|
|
|
|
def clear_downloads
|
|
@downloaded_files.each { |file| FileUtils.rm_f(file) }
|
|
@downloaded_files = []
|
|
end
|
|
|
|
def has_download_link?
|
|
find(:link, ".zip").present?
|
|
end
|
|
|
|
private
|
|
|
|
def unzip(file)
|
|
paths = []
|
|
Zip::File.open(file) do |zip_file|
|
|
zip_file.each do |f|
|
|
f.extract(f.name, destination_directory: Downloads::FOLDER)
|
|
paths << File.join(Downloads::FOLDER, f.name)
|
|
end
|
|
end
|
|
|
|
paths
|
|
end
|
|
end
|
|
end
|
|
end
|