Sha256: 452326802e5d92d188f37db1dd72301926177a1ee5840042c781aadfcfcda72f

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

module MiniAutobot
  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 MiniAutobot::NoSelectorForElement.new, "#{self.class.name} => :#{method_name} needs a selector"
        end
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mini_autobot-1.1.7 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.6 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.5 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.4 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.3 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.2 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.1 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.1.0 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-1.0.0 lib/mini_autobot/page_objects/element_container.rb
mini_autobot-0.8.0 lib/mini_autobot/page_objects/element_container.rb