From 20747ef6e103df53f89bf8a266b4bd652f9ff0ed Mon Sep 17 00:00:00 2001 From: Hugh McGowan Date: Tue, 17 May 2011 10:36:08 -0500 Subject: [PATCH] fix file_download_link and add test case --- watir/lib/watir/dialogs/file_download.rb | 22 +++++++++----- watir/unittests/file_download_link_test.rb | 34 ++++++++++++++++++++++ watir/unittests/html/download_me.bin | 0 watir/unittests/html/filedownload.html | 8 +++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 watir/unittests/file_download_link_test.rb create mode 100644 watir/unittests/html/download_me.bin create mode 100644 watir/unittests/html/filedownload.html diff --git a/watir/lib/watir/dialogs/file_download.rb b/watir/lib/watir/dialogs/file_download.rb index 1ea5d909..7e8e1040 100644 --- a/watir/lib/watir/dialogs/file_download.rb +++ b/watir/lib/watir/dialogs/file_download.rb @@ -15,7 +15,8 @@ def open # File Download Dialog def file_download_window - wait_for_window('File Download') + @file_download_window ||= wait_for_window('File Download', /save this file/) + @file_download_window end def save_file_button @@ -28,21 +29,26 @@ def open_file_button # Save As Dialog def save_as_window - wait_for_window('Save As') + @save_window ||= wait_for_window('Save As') + @save_window end def set_file_name(path_to_file) - save_as_window.text_field(:value => 'Edit').set path_to_file + save_as_window.text_field(:class => 'Edit').set path_to_file end def save_button - save_as_window.button('&Save') + save_as_window.button(:value=>'&Save') end - - def wait_for_window(title) - window = ::RAutomation::Window.new(:title => title) - Watir::Wait.until {window.exists?} + def wait_for_window(title, text=nil) + args = {:title => title} + args.update(:text => text) if text + window = nil + Watir::Wait.until { + window = ::RAutomation::Window.new(args) + window.exists? + } window end diff --git a/watir/unittests/file_download_link_test.rb b/watir/unittests/file_download_link_test.rb new file mode 100644 index 00000000..0d04b4e9 --- /dev/null +++ b/watir/unittests/file_download_link_test.rb @@ -0,0 +1,34 @@ +# feature tests for file Fields + +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED +require 'unittests/setup' + +class TC_FileDownloadLink < Test::Unit::TestCase + tags :must_be_visible, :creates_windows + include Watir + + def setup + goto_page "filedownload.html" + @file = File.expand_path(File.dirname(__FILE__) + '/test_file_download.bin') + @file.gsub!('/', '\\') + end + + def teardown + Watir::Wait.until {File.exists?(@file)} + File.delete @file + end + + def test_file_field_Exists + # test for existance of 4 file area + assert(browser.file_download_link(:text,"file").exists?) + assert(browser.file_download_link(:url,/download_me\.bin/).exists?) + + # test for missing + assert_false(browser.file_download_link(:text, "missing").exists?) + + # pop one open and put something in it. + browser.file_download_link(:text, "file").set @file + + end + +end diff --git a/watir/unittests/html/download_me.bin b/watir/unittests/html/download_me.bin new file mode 100644 index 00000000..e69de29b diff --git a/watir/unittests/html/filedownload.html b/watir/unittests/html/filedownload.html new file mode 100644 index 00000000..26a26e80 --- /dev/null +++ b/watir/unittests/html/filedownload.html @@ -0,0 +1,8 @@ + + + + + +file + + \ No newline at end of file