Sha256: 33ec5fe76fa7e8de9509682bda4e97e319e3a2eb74eb9c70305df58ac441f563

Contents?: true

Size: 978 Bytes

Versions: 4

Compression:

Stored size: 978 Bytes

Contents

module Watir
  class FileField < InputElement
    def set(file_path)
      assert_file_exists(file_path)
      assert_exists
      click_no_wait
      set_file_name file_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
      open_button.click
      Wait.until(5) {value.include?(File.basename(file_path))}
    end

    alias_method :value=, :set

    def assert_file_exists(file_path)
      raise Errno::ENOENT, "#{file_path} has to exist to set!" unless File.exists?(file_path)
    end

    def set_file_name(path_to_file)
      file_upload_window.text_field(:class => 'Edit', :index => 0).set path_to_file
    end

    def open_button
      file_upload_window.button(:value => /&Open|&Abrir/)
    end

    def cancel_button
      file_upload_window.button(:value => /Cancel/)
    end

    def file_upload_window
      @window ||= RAutomation::Window.new(:title => /^choose file( to upload)?|Elegir archivos para cargar$/i)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-classic-3.3.0 lib/watir-classic/dialogs/file_field.rb
watir-classic-3.2.0 lib/watir-classic/dialogs/file_field.rb
watir-classic-3.2.0.rc1 lib/watir-classic/dialogs/file_field.rb
watir-classic-3.1.0 lib/watir-classic/dialogs/file_field.rb