Module: Tooth::PageObject

Defined in:
lib/tooth/page_object.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



76
77
78
79
80
81
82
# File 'lib/tooth/page_object.rb', line 76

def method_missing(meth, *args, &block)
  if( element_finder = page_element[meth.to_sym])
    element_finder.call(*args)
  else
    element_with_finders.send(meth, *args, &block)
  end
end

Instance Method Details

#button(name, locator) ⇒ Object



19
20
21
# File 'lib/tooth/page_object.rb', line 19

def button name, locator
  page_element[name] = ->(*args){ element_with_finders.find_button(locator_string(locator, args)) }
end

#component(name, component_class, locator, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/tooth/page_object.rb', line 35

def component name, component_class, locator, options = {}
  page_element[name] = ->(*args){
    component_element = find(locator_string(locator, args), options)
    component_class.tap do |cmp|
      cmp.element_with_finders = component_element
    end
  }
end

#element(name, locator, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/tooth/page_object.rb', line 23

def element name, locator, options = {}
  page_element[name] = ->(*args){
    element_with_finders.find(locator_string(locator, args), options)
  }
end

#elements(name, locator, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/tooth/page_object.rb', line 29

def elements name, locator, options = {}
  page_element[name] = ->(*args){
    element_with_finders.all(locator_string(locator, args), options)
  }
end

#field(name, locator) ⇒ Object



15
16
17
# File 'lib/tooth/page_object.rb', line 15

def field name, locator
  page_element[name] = ->(*args){ element_with_finders.find_field(locator_string(locator, args)) }
end


11
12
13
# File 'lib/tooth/page_object.rb', line 11

def link name, locator
  page_element[name] = ->(*args){ element_with_finders.find_link(locator_string(locator, args)) }
end

#not_shows?(&block) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/tooth/page_object.rb', line 50

def not_shows? &block
  instance_eval &block
rescue Capybara::ElementNotFound
else
  raise 'Element is shown'
end

#shows?(&block) ⇒ Boolean Also known as: scenario

convenience methods

Returns:

  • (Boolean)


45
46
47
# File 'lib/tooth/page_object.rb', line 45

def shows? &block
  instance_eval &block
end

#within(scope_locator, &block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/tooth/page_object.rb', line 3

def within scope_locator, &block
  within_scope_klass = Class.new
  within_scope_klass.extend PageObject
  within_scope_klass.instance_variable_set :@page_element, page_element
  within_scope_klass.element_with_finders = -> { element_with_finders.find(scope_locator) }
  within_scope_klass.class_eval &block
end