lib/symbiont/generators.rb in symbiont-0.0.2 vs lib/symbiont/generators.rb in symbiont-0.0.3
- old
+ new
@@ -26,53 +26,137 @@
define_method("start") do
@platform.visit(url)
end
end
+ # This method allows for a title_is() method in definitions. The idea
+ # is that you can specify the title of a page. This title can then be
+ # checked on. Note that the assumption here is that the title will
+ # be static. The argument to the method can, however, be a
+ # regular expression.
+ #
+ # @param [String] title the literal string of the expected title
+ # @param [Regexp] title the pattern string of the expected title
+ # @return [Nil]
+ # @raise exception if the title found does not match the title expected
+ def title_is(title)
+ define_method('has_title?') do
+ valid_title = title =~ @browser.title if title.kind_of?(Regexp)
+ valid_title = title == @browser.title if title.kind_of?(String)
+ raise "Expected title: '#{title}'; Actual title: '#{@browser.title}'" unless valid_title
+ valid_title
+ end
+ end
+
+ # This method allows for a look_for() method in definitions. The idea
+ # is that you can specify an object that should appear on a given page
+ # when that page appears.
+ #
+ # @param [Symbol] widget the friendly name of the object declaration
+ # @param [optional, Integer] timeout the time to wait for the object to appear
+ # @return [Boolean] true if object was found
+ 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
+
# Definition method for links. Methods for the following actions will
# be created:
# * reference a link (identifier_object, identifier_link)
+ # * check text of link (identifier_text)
# * click a link (identifier)
+ # * 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::Link
def link(identifier, locator)
define_method("#{identifier}_object") do
@platform.get_link_for(locator.clone)
end
alias_method "#{identifier}_link".to_sym, "#{identifier}_object".to_sym
-
+
+ define_method("#{identifier}_text") do
+ @platform.get_link_text_for(locator.clone)
+ end
+
define_method(identifier) do
@platform.click_link_for(locator.clone)
end
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_link_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_link_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
end
# Definition method for buttons. Methods for the following actions will
# be created:
# * reference a button (identifier_object, identifier_button)
+ # * get text from button (identifier_text)
# * click a button (identifier)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * check for enabled (identifier!, identifier_enabled?)
# @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::Button
def button(identifier, locator)
define_method("#{identifier}_object") do
@platform.get_button_for(locator.clone)
end
alias_method "#{identifier}_button".to_sym, "#{identifier}_object".to_sym
-
+
+ define_method("#{identifier}_text") do
+ @platform.get_button_text_for(locator.clone)
+ end
+
define_method(identifier) do
@platform.click_button_for(locator.clone)
end
+
+ define_method("#{identifier}_exists?") do
+ @platform.check_button_for_existence(locator.clone)
+ end
+
+ alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_button_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}_enabled?") do
+ @platform.check_button_for_enabled(locator.clone)
+ end
+
+ alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
end
# Definition method for text fields. Methods for the following actions
# will be created:
- # * reference a text field (identifier_object, identifier_button)
+ # * reference a text field (identifier_object, identifier_text_field)
# * get text from a text field (identifier)
# * set text in a text field (identifier=)
+ # * check for existence (identifier?, identifier_exists?)
+ # * check for visibility (identifier_?, identifier_visible?)
+ # * check for enabled (identifier!, identifier_enabled?)
# @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::TextField
def text_field(identifier, locator)
define_method("#{identifier}_object") do
@@ -86,9 +170,27 @@
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
+
+ define_method("#{identifier}_visible?") do
+ @platform.check_text_field_for_visibility(locator.clone)
+ end
+
+ alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym
+
+ define_method("#{identifier}_enabled?") do
+ @platform.check_text_field_for_enabled(locator.clone)
+ end
+
+ alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym
end
end # module: Generators
-end # module: Symbiont
\ No newline at end of file
+end # module: Symbiont