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

Commit

Permalink
Make FileField window titles, button values etc configurable for mult…
Browse files Browse the repository at this point in the history
…i language environments.
  • Loading branch information
jarmo committed Mar 9, 2013
1 parent 4f3d18b commit c9cf457
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/watir-classic/dialogs/alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Alert
#
# @example When the title of your IE dialog is missing, add a new one:
# Watir::Alert::WINDOW_TITLES << "My missing title"
WINDOW_TITLES = ['Message from webpage', 'Windows Internet Explorer', 'Microsoft Internet Explorer', /Mensaje de p.*/, "Explorer User Prompt"]
WINDOW_TITLES = ['Message from webpage', 'Windows Internet Explorer', 'Microsoft Internet Explorer', /Mensaje de p.*/, 'Explorer User Prompt']

def initialize(container)
@container = container
Expand Down Expand Up @@ -47,7 +47,7 @@ def set(text)
private

def dialog
@window ||= RAutomation::Window.new(:hwnd => @container.hwnd).child(:title => /^(#{WINDOW_TITLES.join('|')})$/)
@window ||= RAutomation::Window.new(:hwnd => @container.hwnd).child(:title => Regexp.new("^#{Regexp.union WINDOW_TITLES}$", Regexp::IGNORECASE))
end

def wait_until_not_exists
Expand Down
30 changes: 27 additions & 3 deletions lib/watir-classic/dialogs/file_field.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
module Watir
# Returned by {Container#file_field}.
class FileField < InputElement
# File upload dialog titles to search for.
#
# @example When the title of your IE dialog is missing, add a new one:
# Watir::FileField::WINDOW_TITLES << "My missing title"
WINDOW_TITLES = [/choose file( to upload)?/i, "Elegir archivos para cargar", "Datei zum Hochladen"]

# File upload dialog "OK" button values to search for.
#
# @example When the "OK" button of your IE is missing, add a new one:
# Watir::FileField::OK_BUTTON_VALUES << "My missing button value"
OK_BUTTON_VALUES = ['&Open', '&Abrir', '&ffnen']

# File upload dialog "Cancel" button values to search for.
#
# @example When the "Cancel" button of your IE is missing, add a new one:
# Watir::FileField::CANCEL_BUTTON_VALUES << "My missing button value"
CANCEL_BUTTON_VALUES = ['Cancel', 'Abbrechen']

# Set the path of the file field.
#
# @example
Expand Down Expand Up @@ -31,15 +49,21 @@ def set_file_name(path_to_file)
end

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

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

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

private

def formatted_regexp(values)
Regexp.new("^#{Regexp.union values}$", Regexp::IGNORECASE)
end

end
Expand Down

0 comments on commit c9cf457

Please sign in to comment.