Module: Capybara::PomPom::Finder

Included in:
Component, Page, TableRow
Defined in:
lib/capybara/pompom/finder.rb

Overview

Capybara::PomPom::Finder

Adds helper methods to Page for accessing Capybara elements in an instance.

class CustomPage
  include Capybara::PomPom::Finder

  link :documentation_link, "View Documentation"

  def view_docs
    documentation_link.click
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Provides access to finders defined at the class level.



22
23
24
25
26
27
28
# File 'lib/capybara/pompom/finder.rb', line 22

def method_missing(name, *args)
  if self.finders.has_key?(name)
    return self.finders[name].get
  end

  super
end

Class Method Details

.included(mod) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capybara/pompom/finder.rb', line 17

def self.included(mod) # :nodoc:
  mod.class_attribute :finders
  mod.finders = {}

  # Provides access to finders defined at the class level.
  def method_missing(name, *args)
    if self.finders.has_key?(name)
      return self.finders[name].get
    end

    super
  end

  mod.extend Finder
end

Instance Method Details

#button(name, locator) ⇒ Object

Finds a button through find_button

button :login_button, "Log In"

Returns a Capybara::Node::Element



65
66
67
# File 'lib/capybara/pompom/finder.rb', line 65

def button(name, locator)
  self.finders[name] = ElementFinder.new(:find_button, locator)
end

#component(name, locator) ⇒ Object

Finds a component through find

component :overview_component, "#overview"

Returns a Component



83
84
85
# File 'lib/capybara/pompom/finder.rb', line 83

def component(name, locator)
  self.finders[name] = ElementFinder.new(:find, locator, wrapper: Component)
end

#components(name, locator, wrapper: nil) ⇒ Object

Finds components through all

components :statuses, ".status"

Returns a Component



92
93
94
# File 'lib/capybara/pompom/finder.rb', line 92

def components(name, locator, wrapper: nil)
  self.finders[name] = ElementFinder.new(:all, locator, wrapper: wrapper)
end

#css(name, locator) ⇒ Object

Finds a node with find

css :title, ".title"

Returns a Capybara::Node::Element



38
39
40
# File 'lib/capybara/pompom/finder.rb', line 38

def css(name, locator)
  self.finders[name] = ElementFinder.new(:find, locator)
end

#field(name, locator) ⇒ Object

Finds a field through find_field

field :username, "user[username]"

Returns a Capybara::Node::Element



56
57
58
# File 'lib/capybara/pompom/finder.rb', line 56

def field(name, locator)
  self.finders[name] = ElementFinder.new(:find_field, locator)
end

Finds a link through find_link

link :login_link, "Log In"

Returns a Capybara::Node::Element



47
48
49
# File 'lib/capybara/pompom/finder.rb', line 47

def link(name, locator)
  self.finders[name] = ElementFinder.new(:find_link, locator)
end

#table(name, locator, row_wrapper: nil) ⇒ Object

Finds a table through find

table :products_table, "#products", row_wrapper: TableRowWrapper

Returns a Table



74
75
76
# File 'lib/capybara/pompom/finder.rb', line 74

def table(name, locator, row_wrapper: nil)
  self.finders[name] = TableFinder.new(:find, locator, wrapper: row_wrapper)
end