lib/page-object/loads_platform.rb in page-object-1.0.3 vs lib/page-object/loads_platform.rb in page-object-1.1.0
- old
+ new
@@ -13,14 +13,33 @@
# @param [Object] A browser driver that has a supported adapter
# @param [adapters] a list of adapters that are currently supported
# @returns [PageObject]
#
def load_platform(browser, adapters)
- adapters.each_value { |adapter|
- return adapter.create_page_object(browser) if adapter.is_for?(browser)
+ adapter_for(browser,adapters).create_page_object(browser)
+ end
+
+ def browser_for root,adapters
+ adapter_for(root,adapters).browser_for(root)
+ end
+
+ def adapter_for element_or_browser, adapters
+ adapter = adapters.values.find { |adapter|
+ adapter.is_for?(element_or_browser)
}
- message = 'Unable to pick a platform for the provided browser.'
- message += "\nnil was passed to the PageObject constructor instead of a valid browser object." if browser.nil?
- raise message
+ unless adapter
+ message = "Unable to pick a platform for the provided browser or element: #{element_or_browser.inspect}."
+ message += "\nnil was passed to the PageObject constructor instead of a valid browser or element object." if element_or_browser.nil?
+ raise message
+ end
+ adapter
+ end
+
+ def root_element_for root, adapters
+ adapter_for(root,adapters).root_element_for(root)
+ end
+
+ def browser_root_for browser, adapters
+ adapter_for(browser,adapters).browser_root_for(browser)
end
end
end