test/ui_test_helper.rb
# load file either in browser or download and check for existence
load file either in browser or download and check for existence
load file either in browser or download and check for existence
def download_file(link, basename)
    link.click
    if @driver.current_url.include?('https://storage.googleapis.com/')
      assert @driver.current_url =~ /#{basename}/, "Downloaded file url incorrect, did not find #{basename}"
      @driver.navigate.back
    else
      sleep(5)
      file_exists = Dir.entries($download_dir).select {|f| f =~ /#{basename}/}.size >= 1 || File.exists?(File.join($download_dir, basename))
      assert file_exists, "did not find downloaded file: #{basename} in #{Dir.entries($download_dir).join(', ')}"
      Dir.glob("#{$download_dir}/*").select {|f| /#{basename}/.match(f)}.map {|f| File.delete(f)}
    end
  end
def download_file ( link , basename ) link . click if @driver . current_url . include? ( 'https://storage.googleapis.com/' ) assert @driver . current_url =~ / #{ basename } / , "Downloaded file url incorrect, did not find #{basename}" @driver . navigate . back else sleep ( 5 ) file_exists = Dir . entries ( $download_dir ) . select { | f | f =~ / #{ basename } / } . size >= 1 || File . exists? ( File . join ( $download_dir , basename ) ) assert file_exists , "did not find downloaded file: #{basename} in #{Dir.entries($download_dir).join(', ')}" Dir . glob ( "#{$download_dir}/*" ) . select { | f | / #{ basename } / . match ( f ) } . map { | f | File . delete ( f ) } end end
load file either in browser or download and check for existence
load file either in browser or download and check for existence
# give browser 5 seconds to initiate download # make sure file was actually downloaded # delete matching files
link
<not_specific>
basename
<not_specific>