Sha256: 846526ea7a4dac5896a60f0dc037a9dae4da754f918b90f243f0f43954f0e1f9

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module Watir
  module PageCheckers
    # raises an error if javascript error was found
    JAVASCRIPT_ERRORS_CHECKER = lambda {|ie| raise "Expected no JavaScript errors to appear on page, but having some!" if ie.status =~ /Error on page/}
  end
end

# patches for Watir
module Watir
  class IE #:nodoc:all
    include WaitHelper
  end

  class Element #:nodoc:all
    include ElementExtensions

    # saves a file with the browser
    #
    # clicking the button opens a browser's save as dialog and saves the file document.pdf
    #  button(:id => "something").download("c:/document.pdf") # => c:/document.pdf
    #
    # * raises an exception if saving the file is unsuccessful
    # * returns saved file path
    def save_as(file_path)
      path = Pathname.new(file_path)
      raise "path to #{file_path} has to be absolute!" unless path.absolute?
      self.click_no_wait
      download_window = RAutomation::Window.new(:title => "File Download",
                                                :text => "Do you want to open or save this file?")
      WaitHelper.wait_until {download_window.present?}
      download_window.button(:value => "&Save").click

      save_as_window = RAutomation::Window.new(:title => "Save As")
      WaitHelper.wait_until {save_as_window.present?}
      save_as_window.text_field(:class_name => "Edit1").set(File.native_path(file_path))
      save_as_window.button(:value => "&Save").click

      WaitHelper.wait_until {File.exists?(file_path)}
      file_path
    end
  end

  class FileField < InputElement
    def set(file_path)
      raise "#{file_path} has to exist to set!" unless File.exists?(file_path)
      assert_exists
      self.click_no_wait
      window = RAutomation::Window.new(:title => /choose file( to upload)?/i)
      WaitHelper.wait_until {window.present?}
      window.text_field(:class_name => "Edit1").set(File.native_path(file_path))
      window.button(:value => "&Open").click
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
watirsplash-0.2.10 lib/watirsplash/watir.rb
watirsplash-0.2.9 lib/watirsplash/watir.rb