module Symbiont module WebObjects # This class is designed to provide methods for functionality that is # common to all web objects and that may need to be called directly # on a web object (as opposed to a web object wrapped up by the # platform). class WebObject attr_reader :web_object def initialize(web_object) @web_object = web_object end def enabled? web_object.enabled? end def disabled? not enabled? end def visible? web_object.present? end def exists? web_object.exists? end def id web_object.id end def value web_object.value end def flash web_object.flash end def attribute(name) web_object.attribute_value(name) end def focus web_object.focus end def text web_object.text end def html web_object.html end def click web_object.click end def double_click web_object.double_click end def tag_name web_object.tag_name end def clear web_object.clear end def style(property) web_object.style(property) end def inspect web_object.inspect end def hover web_object.hover end def fire_event(event) web_object.fire_event(event) end def send_keys(*args) web_object.send_keys(*args) end def ==(other) web_object == other.web_object end def parent parent = web_object.parent type = web_object.type if parent.tag_name.to_sym == :input object_class = ::Symbiont::WebObjects.get_class_for(parent.tag_name, type) object_class.new(parent) end def wait_until(timeout=::Symbiont.element_level_wait, message=nil, &block) Object::Watir::Wait.until(timeout, message, &block) end def when_actionable(timeout=::Symbiont.element_level_wait) web_object.wait_until_present(timeout) self end alias_method :when_present, :when_actionable def when_not_actionable(timeout=::Symbiont.element_level_wait) web_object.wait_while_present(timeout) self end alias_method :when_not_present, :when_not_actionable def when_visible(timeout=::Symbiont.element_level_wait) Object::Watir::Wait.until(timeout, "Object not visible within #{timeout} seconds.") do visible? end self end def when_not_visible(timeout=::Symbiont.element_level_wait) Object::Watir::Wait.while(timeout, "Object still visible after #{timeout} seconds.") do visible? end self end alias_method :must_be_visible, :when_visible alias_method :must_not_be_visible, :when_not_visible def scroll_into_view(wait=2) sleep wait web_object.wd.location_once_scrolled_into_view end def self.usable_selectors [:id, :name, :xpath, :class, :index] end def self.selector_mapping {} end #def self.locator_for(locator) # how, what = locator.keys.first, locator.values.first # return how => what if usable_selectors.include? how # return selector_mapping[how] => what if selector_mapping[how] # return nil => what #end def self.provide_locator_for(locator) locator.each do |key, value| how, what = locator.keys.first, locator.values.first return how => what if usable_selectors.include? how return selector_mapping[how] => what if selector_mapping[how] return nil => what end end end # class: WebObject end # module: WebObjects end # module: Symbiont