Sha256: 42ec3f0dcfdae905496e9027fe2b6a2b8780e554764244f51b4861c0e675fccc

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module SeleniumRecord
  # Helpers for executing actions in custom scope
  module Scopes
    # Class for giving custom scope to selenium objects
    class LocatorScope < SimpleDelegator
      include Actions
      attr_accessor :scoped_locator

      def root_el
        @root_el ||= __rootel__.find_element(scoped_locator)
      end

      def find(locator)
        root_el.find_element(locator)
      end

      def find_elements(locator)
        root_el.find_elements(locator)
      end

      def run(&block)
        instance_eval(&block)
      end

      def class
        __getobj__.class
      end
    end

    # Executes the block passed as parameter in the scope associated to the
    # locator referenced by the scope name
    # @param name [Symbol] The name of the scope. Adding the suffix '_locator'
    #   it should match a locator name
    def scope(scope_name, &block)
      scope_obj = LocatorScope.new(self)
      scope_obj.scoped_locator = send "#{scope_name}_locator"
      scope_obj.run(&block)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
seleniumrecord-0.0.4 lib/selenium_record/scopes.rb
seleniumrecord-0.0.3 lib/selenium_record/scopes.rb
seleniumrecord-0.0.2.revision lib/selenium_record/scopes.rb
seleniumrecord-0.0.2 lib/selenium_record/scopes.rb
seleniumrecord-0.0.1.beta1 lib/selenium_record/scopes.rb