Given(/^I visit PPL XML page$/) do
  visit(OA::GeneratePPlXMlPage)
end

When(/^I upload a txt file with a valid track unique id$/) do
  upload_file = DataHelpers::PplXmlUpload.create_unique_copy
  on(OA::GeneratePPlXMlPage).upload_ppl_file(upload_file)
end

Then(/^the uploaded txt file should be available for download$/) do
  download_file = on(OA::GeneratePPlXMlPage).files_table_element[1]["Filename"].text
  upload_file = File.basename(DataHelpers::PplXmlUpload.uploaded_file)
  expect(download_file).to eql upload_file
end

When(/^I download the uploaded txt file$/) do
  url = on(OA::GeneratePPlXMlPage).download_input_file
  downloaded_file_path = FileSystemHelpers::Downloader.download(url, with_timestamp: false).first
  puts "Downloaded file: #{downloaded_file_path}"
  DataHelpers::PplXmlUpload.downloaded_file = downloaded_file_path
end

Then(/^I should see the same track unique id in the downloaded txt file$/) do
  DataHelpers::PplXmlUpload.ensure_files_match
end
