Module: CapybaraTestHelpers::Selectors

Included in:
TestHelper
Defined in:
lib/capybara_test_helpers/selectors.rb

Overview

Public: Adds aliasing for element selectors to make it easier to encapsulate how to find a particular kind of element in the UI.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SELECTOR_SEPARATOR =
','

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



38
39
40
# File 'lib/capybara_test_helpers/selectors.rb', line 38

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#resolve_alias_for_selector_query(args, kwargs, filter_block) ⇒ Object

Internal: Inspects the arguments for a SelectorQuery, and resolves a selector alias if provided.

Returns a pair of arguments and keywords to initialize a SelectorQuery.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/capybara_test_helpers/selectors.rb', line 97

def resolve_alias_for_selector_query(args, kwargs, filter_block)
  # Extract the explicitly provided selector, if any. Example: `find_button`.
  explicit_type = args.shift if selectors.key?(args[1])

  if selectors.key?(args[0])
    args, kwargs = locator_for(*args, **kwargs)

    # Remove the type provided by the alias, and add back the explicit one.
    if explicit_type
      args.shift if args[0].is_a?(Symbol)
      args.unshift(explicit_type)
    end
  end

  [args, kwargs, wrap_filter(filter_block)]
end

#selectorsObject

Public: Returns the available selectors for the test helper, or an empty Hash if selectors are not defined.



89
90
91
# File 'lib/capybara_test_helpers/selectors.rb', line 89

def selectors
  self.class.selectors
end