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, name = nil, &block) ⇒ Section

Returns a new instance of Section.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#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



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

def capybara_session
  Capybara.current_session
end

#parent_pageObject



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

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



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

def to_capybara_node
  root_element
end

#wait_until_invisible(*args, **kwargs) ⇒ Object



86
87
88
# File 'lib/site_prism/section.rb', line 86

def wait_until_invisible(*args, **kwargs)
  parent.public_send(:"wait_until_#{name}_invisible", *args, **kwargs)
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



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

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