Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
fix file_download_link and add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh McGowan committed May 17, 2011
1 parent 3a664c8 commit 20747ef
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
22 changes: 14 additions & 8 deletions watir/lib/watir/dialogs/file_download.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down
34 changes: 34 additions & 0 deletions 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
Empty file.
8 changes: 8 additions & 0 deletions watir/unittests/html/filedownload.html
@@ -0,0 +1,8 @@
<html>
<head>
</head>
<body>

<a href="file://C:\ws\github\bret\watir\watir\unittests\html\download_me.bin">file</a>
</body>
</html>

0 comments on commit 20747ef

Please sign in to comment.