Sha256: d08033b0abfceb10d79c88a2dc71fcda4c62036eb0def5d23875f7592c2bec36

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Browsery
  module PageObjects
    module ElementContainer

      def element(element_name, *find_args)
        build element_name, *find_args do |how, what|
          define_method element_name.to_s do
            find_first(how, what)
          end
        end
      end

      def elements(collection_name, *find_args)
        build collection_name, *find_args do |how, what|
          define_method collection_name.to_s do
            find_all(how, what)
          end
        end
      end
      alias_method :collection, :elements

      def add_to_mapped_items(item)
        @mapped_items ||= []
        @mapped_items << item.to_s
      end

      private

      def build(name, *find_args)
        if find_args.empty?
          create_no_selector name
        else
          add_to_mapped_items name
          if find_args.size == 1
            yield(:css, *find_args)
          else
            yield(*find_args)
          end
        end
      end

      def create_no_selector(method_name)
        define_method method_name do
          fail Browsery::NoSelectorForElement.new, "#{self.class.name} => :#{method_name} needs a selector"
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
browsery-0.4.1 lib/browsery/page_objects/element_container.rb
browsery-0.4.0 lib/browsery/page_objects/element_container.rb
browsery-0.3.0 lib/browsery/page_objects/element_container.rb
browsery-0.2.0 lib/browsery/page_objects/element_container.rb