lib/symbiont/web_objects/_common.rb in symbiont-0.1.7 vs lib/symbiont/web_objects/_common.rb in symbiont-0.1.8
- old
+ new
@@ -5,111 +5,90 @@
# 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)
+ attr_reader :web_object
+
+ def initialize(web_object, platform)
@web_object = web_object
+ include_platform_specifics_for(platform)
end
def enabled?
- @web_object.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
+ web_object.text
end
def click
- @web_object.click
+ web_object.click
end
-
+
+ def tag
+ web_object.tag_name
+ end
+
def clear
- @web_object.clear
+ web_object.clear
end
-
- def attribute(name)
- @web_object.attribute_value(name)
- end
-
+
def style(property)
- @web_object.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
+ web_object.inspect
end
-
- def flash
- @web_object.flash
+
+ def self.usable_selectors_for_watir
+ [:id, :name, :xpath, :class, :index]
end
-
- def when_actionable(timeout=5)
- @web_object.wait_until_present(timeout)
- self
+
+ def self.usable_selectors_for_selenium
+ [:id, :name, :xpath, :class, :index, :css]
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
+
+ def self.selector_mapping_for_watir
+ {}
end
-
- def when_not_visible(timeout=5)
- Object::Watir::Wait.while(timeout, "object still visible after #{timeout} seconds.") do
- visible?
- end
- self
+
+ def self.selector_mapping_for_selenium
+ {}
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)
+ 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.usable_selectors
- [:id, :name, :xpath, :class, :index]
+
+ 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.selector_mapping
- {}
+
+ 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 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
+
+ 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