Module: Tooth::PageObject

Included in:
Widgeon::PageObject
Defined in:
lib/deps/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)



106
107
108
109
110
111
112
# File 'lib/deps/tooth/page_object.rb', line 106

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



48
49
50
# File 'lib/deps/tooth/page_object.rb', line 48

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

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



65
66
67
68
69
70
71
72
# File 'lib/deps/tooth/page_object.rb', line 65

def component name, component_class, locator, options = {}
  page_element[name] = lambda { |*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

TODO: refactor to support :xpath locators



53
54
55
56
57
# File 'lib/deps/tooth/page_object.rb', line 53

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

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



59
60
61
62
63
# File 'lib/deps/tooth/page_object.rb', line 59

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

#field(name, locator) ⇒ Object



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

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


40
41
42
# File 'lib/deps/tooth/page_object.rb', line 40

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

#not_shows?(&block) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
# File 'lib/deps/tooth/page_object.rb', line 80

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)


75
76
77
# File 'lib/deps/tooth/page_object.rb', line 75

def shows? &block
  instance_eval &block
end

#within(scope_locator, &block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/deps/tooth/page_object.rb', line 32

def within scope_locator, &block
  within_scope_klass = Class.new
  within_scope_klass.extend Widgeon::PageObject #TODO: is there a better way to update the #within?
  within_scope_klass.instance_variable_set :@page_element, page_element
  within_scope_klass.element_with_finders = lambda { element_with_finders.find(scope_locator) }
  within_scope_klass.class_eval &block
end