module Symbiont module Generators def url_is(url) define_method("view") do platform.visit(url) end end def begin_at(url) define_method("start") do platform.visit(url) end end def title_is(title) define_method('has_title?') do sleep 1 valid_title = title =~ browser.title if title.kind_of?(Regexp) valid_title = title == browser.title if title.kind_of?(String) raise "\n\nExpected title: '#{title}'; Actual title: '#{browser.title}'" unless valid_title valid_title end end def look_for(widget, timeout=5) define_method('has_object?') do if self.respond_to? "#{widget}_object" self.send("#{widget}_object").when_actionable(timeout) else puts "The #{widget} object was not declared and could not be checked." end end end def paragraph(identifier, locator) define_method(identifier) do platform.paragraph_text_for(locator.clone) end common_definition_methods(identifier, locator, 'paragraph_element') end alias_method :p, :paragraph def link(identifier, locator) define_method(identifier) do platform.click_link_for(locator.clone) end common_definition_methods(identifier, locator, 'link_element') end alias_method :a, :link def button(identifier, locator) define_method(identifier) do platform.click_button_for(locator.clone) end common_definition_methods(identifier, locator, 'button_element') end def text_field(identifier, locator) 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 common_definition_methods(identifier, locator, 'text_field_element') end def select_list(identifier, locator) 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}_options?") do object = self.send("#{identifier}_object") (object && object.options) ? object.options.collect(&:text) : [] end define_method("#{identifier}=") do |value| platform.set_select_list_value_for(locator.clone, value) end common_definition_methods(identifier, locator, 'select_list_element') end alias_method :select, :select_list def checkbox(identifier, locator) 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 common_definition_methods(identifier, locator, 'checkbox_element') end def radio(identifier, locator) #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 common_definition_methods(identifier, locator, 'radio_element') end alias_method :radio_button, :radio # 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 def div(identifier, locator) common_definition_methods(identifier, locator, 'div_element') end def span(identifier, locator) common_definition_methods(identifier, locator, 'span_element') end def common_definition_methods(identifier, locator, method) define_method("#{identifier}_object") do platform.send(method, locator.clone) end define_method("#{identifier}_exists?") do platform.send(method, locator.clone).exists? end define_method("#{identifier}_visible?") do platform.send(method, locator.clone).visible? end define_method("#{identifier}_enabled?") do platform.send(method, locator.clone).enabled? end define_method("#{identifier}_text") do platform.send(method, locator.clone).text end element = method[0..method.index("_") - 1] alias_method "#{identifier}_#{element}".to_sym, "#{identifier}_object".to_sym alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym end end # module: Generators end # module: Symbiont