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, platform) @web_object = web_object include_platform_specifics_for(platform) end def enabled? web_object.enabled? end def disabled? not enabled? end def text web_object.text end def click web_object.click end def tag 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 self.usable_selectors_for_watir [:id, :name, :xpath, :class, :index] end def self.usable_selectors_for_selenium [:id, :name, :xpath, :class, :index, :css] end def self.selector_mapping_for_watir {} end def self.selector_mapping_for_selenium {} end def self.provide_watir_locator_for(locator) locator = locator_for(locator, usable_selectors_for_watir, selector_mapping_for_watir) return {locator.keys.first => locator.values.first} end def self.provide_selenium_locator_for(locator) locator = locator_for(locator, usable_selectors_for_selenium, selector_mapping_for_selenium) return locator.keys.first, locator.values.first end def self.locator_for(locator, selectors, mappings) how, what = locator.keys.first, locator.values.first return how => what if selectors.include? how return mappings[how] => what if mappings[how] return nil => what end def include_platform_specifics_for(platform) if platform[:platform] == :watir_webdriver require 'symbiont/platform_watir/web_objects/common' self.class.send :include, ::Symbiont::Platforms::WatirWebDriver::WebObject elsif platform[:platform] == :selenium_webdriver require 'symbiont/platform_selenium/web_objects/common' self.class.send :include, ::Symbiont::Platforms::SeleniumWebDriver::WebObject else raise ArgumentError, "The platform #{platform[:platform]} appears to be unsupported." end end end # class: WebObject end # module: WebObjects end # module: Symbiont