lib/symbiont/generators.rb in symbiont-0.0.4 vs lib/symbiont/generators.rb in symbiont-0.1.0
- old
+ new
@@ -1,6 +1,12 @@
module Symbiont
+
+ # The Generators module is used to provide groupings of methods that are
+ # generated dynamically based on object declarations in page definitions.
+ # The method provided allow for referencing and accessing web objects.
+ # The platform object acts as a delegate for all method calls.
+
module Generators
# This method allows for a url_is() method in definitions that will
# define a direct means of accessing a resource. The most common
# example will be a URL for a web page, but any URI is valid. The
@@ -166,15 +172,15 @@
alias_method "#{identifier}_text_field".to_sym, "#{identifier}_object".to_sym
define_method(identifier) do
@platform.get_text_field_value_for(locator.clone)
end
-
+
define_method("#{identifier}=") do |value|
@platform.set_text_field_value_for(locator.clone, value)
end
-
+
define_method("#{identifier}_exists?") do
@platform.check_text_field_for_existence(locator.clone)
end
alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
@@ -189,8 +195,278 @@
@platform.check_text_field_for_enabled(locator.clone)
end
alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
end
-
+
+ # Definition method for select lists. Methods for the following actions
+ # will be created:
+ # * reference a checkbox (identifier_object, identifier_select_list)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * check for enabled (identifier!, identifier_enabled?)
+ # * check for option (identifier_option?)
+ # * set selected value (identifier=)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::SelectList
+ def select_list(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_select_list_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_select_list".to_sym, "#{identifier}_object".to_sym
+
+ define_method(identifier) do
+ @platform.get_select_list_item_for(locator.clone)
+ end
+
+ define_method("#{identifier}_option?") do
+ @platform.get_select_list_value_for(locator.clone)
+ end
+
+ define_method("#{identifier}=") do |value|
+ @platform.set_select_list_value_for(locator.clone, value)
+ end
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_select_list_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_select_list_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}_enabled?") do
+ @platform.check_select_list_for_enabled(locator.clone)
+ end
+
+ alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
+ end
+
+ # Definition method for checkboxes. Methods for the following actions
+ # will be created:
+ # * reference a checkbox (identifier_object, identifier_checkbox)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * check for enabled (identifier!, identifier_enabled?)
+ # * check for checked (identifier_checked?)
+ # * set checked state (check_identifier)
+ # * set unchecked state (uncheck_identifier)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::CheckBox
+ def checkbox(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_checkbox_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_checkbox".to_sym, "#{identifier}_object".to_sym
+
+ define_method("check_#{identifier}") do
+ @platform.check_checkbox_for(locator.clone)
+ end
+
+ define_method("uncheck_#{identifier}") do
+ @platform.uncheck_checkbox_for(locator.clone)
+ end
+
+ define_method("#{identifier}_checked?") do
+ @platform.check_checkbox_for_checked(locator.clone)
+ end
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_checkbox_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_checkbox_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}_enabled?") do
+ @platform.check_checkbox_for_enabled(locator.clone)
+ end
+
+ alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
+ end
+
+ # Definition method for radios. Methods for the following actions will be created:
+ # * reference a radio (identifier_object, identifier_radio, identifier_radio_button)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * check for enabled (identifier!, identifier_enabled?)
+ # * check for selected (identifier_set?, identifier_selected?)
+ # * set selected state (set_identifier, select_identifier)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::Radio
+ def radio(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_radio_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_radio".to_sym, "#{identifier}_object".to_sym
+ alias_method "#{identifier}_radio_button".to_sym, "#{identifier}_object".to_sym
+
+ define_method("#{identifier}_selected?") do
+ @platform.check_radio_for_selected(locator.clone)
+ end
+
+ alias_method "#{identifier}_set?".to_sym, "#{identifier}_selected?".to_sym
+
+ define_method("select_#{identifier}") do
+ @platform.select_radio_for(locator.clone)
+ end
+
+ alias_method "set_#{identifier}".to_sym, "select_#{identifier}".to_sym
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_radio_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_radio_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}_enabled?") do
+ @platform.check_radio_for_enabled(locator.clone)
+ end
+
+ alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
+ end
+
+ # Definition method for tables. Methods for the following actions will be created:
+ # * reference a table (identifier_object, identifier_table)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::Table
+ def table(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_table_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_table".to_sym, "#{identifier}_object".to_sym
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_table_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_table_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+ end
+
+ # Definition method for table cells. Methods for the following actions will be created:
+ # * reference a table cell (identifier_object, identifier_cell)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * get text from cell (identifier)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::TableCell
+ def cell(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_table_cell_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_cell".to_sym, "#{identifier}_object".to_sym
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_table_cell_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_table_cell_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}") do
+ @platform.get_table_cell_text_for(locator.clone)
+ end
+ end
+
+ # Definition method for div objects. Methods for the following actions will be created:
+ # * reference a div (identifier_object, identifier_div)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * get text from div (identifier)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::Div
+ def div(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_div_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_div".to_sym, "#{identifier}_object".to_sym
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_div_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_div_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}") do
+ @platform.get_div_text_for(locator.clone)
+ end
+ end
+
+ # Definition method for span objects. Methods for the following actions will be created:
+ # * reference a span (identifier_object, identifier_span)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * get text from span (identifier)
+ # @param [Symbol] identifier the friendly name of the web object
+ # @param [optional, Hash] locator the key/values that identify the object
+ # @return [Object] instance of Symbiont::WebObjects::Span
+ def span(identifier, locator)
+ define_method("#{identifier}_object") do
+ @platform.get_span_for(locator.clone)
+ end
+
+ alias_method "#{identifier}_span".to_sym, "#{identifier}_object".to_sym
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_span_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_span_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}") do
+ @platform.get_span_text_for(locator.clone)
+ end
+ end
end # module: Generators
end # module: Symbiont