Class: SitePrism::Section

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
DSL, ElementChecker, Loadable
Defined in:
lib/site_prism/section.rb

Overview

SitePrism::Section

SitePrism Sections are the mid level construct of the POM framework

Instances of this class represent a a part of a web page that can either sit inside a SitePrism::Page or sit inside another N sections, which then eventually will sit inside a page

All method calls made whilst on a page are scoped using ‘#to_capybara_node` which will be represented by the current `#root_element`. This is the locator for the section itself and is a mandatory argument

Instance Attribute Summary collapse

Attributes included from Loadable

#load_error, #loaded

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

included

Methods included from Loadable

included, #loaded?, #when_loaded

Methods included from ElementChecker

#all_there?, #elements_missing, #elements_present

Constructor Details

#initialize(parent, root_element, &block) ⇒ Section

Returns a new instance of Section.



43
44
45
46
47
# File 'lib/site_prism/section.rb', line 43

def initialize(parent, root_element, &block)
  @parent = parent
  @root_element = root_element
  within(&block) if block
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



19
20
21
# File 'lib/site_prism/section.rb', line 19

def parent
  @parent
end

#root_elementObject (readonly)

Returns the value of attribute root_element.



19
20
21
# File 'lib/site_prism/section.rb', line 19

def root_element
  @root_element
end

Class Method Details

.default_search_argumentsObject



26
27
28
29
30
# File 'lib/site_prism/section.rb', line 26

def default_search_arguments
  return @default_search_arguments if @default_search_arguments

  superclass.respond_to?(:default_search_arguments) && superclass.default_search_arguments
end

.set_default_search_arguments(*args) ⇒ Object



22
23
24
# File 'lib/site_prism/section.rb', line 22

def set_default_search_arguments(*args)
  @default_search_arguments = args
end

Instance Method Details

#capybara_sessionObject



75
76
77
# File 'lib/site_prism/section.rb', line 75

def capybara_session
  Capybara.current_session
end

#parent_pageObject



79
80
81
82
83
# File 'lib/site_prism/section.rb', line 79

def parent_page
  candidate = parent
  candidate = candidate.parent until candidate.is_a?(SitePrism::Page)
  candidate
end

#to_capybara_nodeObject

This scopes our calls inside Section correctly to the ‘Capybara::Node::Element`



63
64
65
# File 'lib/site_prism/section.rb', line 63

def to_capybara_node
  root_element
end

#withinObject

This allows us to return anything that’s passed in as a block to the section at creation time, so that an anonymous section or such-like will have the extra methods

This can also be used manually at runtime to allow people to abbreviate their calls



71
72
73
# File 'lib/site_prism/section.rb', line 71

def within
  Capybara.within(root_element) { yield(self) }
end