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 def initialize(web_object) @web_object = web_object end def enabled? @web_object.enabled? end def disabled? not enabled? end def exists? @web_object.exists? end def visible? @web_object.present? end def text @web_object.text end def click @web_object.click end def clear @web_object.clear end def attribute(name) @web_object.attribute_value(name) end def style(property) @web_object.style(property) end def tag @web_object.tag_name end def id @web_object.id end def value @web_object.value end def inspect @web_object.inspect end def flash @web_object.flash end def when_actionable(timeout=5) @web_object.wait_until_present(timeout) self end alias :when_present :when_actionable def when_visible(timeout=5) Object::Watir::Wait.until(timeout, "object not visible within #{timeout} seconds.") do visible? end self end def when_not_visible(timeout=5) Object::Watir::Wait.while(timeout, "object still visible after #{timeout} seconds.") do visible? end self end alias :must_be_visible :when_visible alias :must_not_be_visible :when_not_visible def wait_until(timeout, message=nil, &block) Object::Watir::Wait.until(timeout, message, &block) end def self.usable_selectors [:id, :name, :xpath, :class, :index] end def self.selector_mapping {} 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