Sha256: 31310f5144ab1a910a66e8b0c062910e17095c13de9102172db42ed2ef8f9a4d

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module PageObject
  module Elements

    #
    # Contains functionality that is common across all elements.
    #
    class Element
      
      def initialize(element, platform)
        @element = element
        include_platform_for platform
      end
      
      def self.watir_identifier_for identifier
        identifier_for identifier, watir_finders, watir_mapping
      end

      def self.selenium_identifier_for identifier
        identifier = identifier_for identifier, selenium_finders, selenium_mapping
        return identifier.keys.first, identifier.values.first
      end
      
      protected

      def self.identifier_for identifier, find_by, find_by_mapping
        how, what = identifier.keys.first, identifier.values.first
        return how => what if find_by.include? how
        return find_by_mapping[how] => what if find_by_mapping[how]
        return nil => what
      end
      
      def self.watir_finders
        [:class, :id, :index, :name, :xpath]
      end
      
      def self.watir_mapping 
        {} 
      end
      
      def self.selenium_finders
        [:class, :id, :name, :xpath]
      end
      
      def self.selenium_mapping 
        {} 
      end
      
      def include_platform_for platform
        if platform[:platform] == :watir
          require 'page-object/platforms/watir_element'
          self.class.send :include, PageObject::Platforms::WatirElement
        elsif platform[:platform] == :selenium
          require 'page-object/platforms/selenium_element'
          self.class.send :include, PageObject::Platforms::SeleniumElement
        else
          raise ArgumentError, "expect platform to be :watir or :selenium"          
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
page-object-0.0.2 lib/page-object/elements/element.rb