Class: SitePrism::Section

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

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_present

Constructor Details

#initialize(parent, root_element) ⇒ Section


28
29
30
31
32
# File 'lib/site_prism/section.rb', line 28

def initialize(parent, root_element)
  @parent = parent
  @root_element = root_element
  Capybara.within(@root_element) { yield(self) } if block_given?
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent


13
14
15
# File 'lib/site_prism/section.rb', line 13

def parent
  @parent
end

#root_elementObject (readonly)

Returns the value of attribute root_element


13
14
15
# File 'lib/site_prism/section.rb', line 13

def root_element
  @root_element
end

Class Method Details

.default_search_argumentsObject


19
20
21
22
23
24
25
26
# File 'lib/site_prism/section.rb', line 19

def self.default_search_arguments
  @default_search_arguments ||
    (
      superclass.respond_to?(:default_search_arguments) &&
      superclass.default_search_arguments
    ) ||
    nil
end

.set_default_search_arguments(*args) ⇒ Object


15
16
17
# File 'lib/site_prism/section.rb', line 15

def self.set_default_search_arguments(*args)
  @default_search_arguments = args
end

Instance Method Details

#capybara_sessionObject


54
55
56
# File 'lib/site_prism/section.rb', line 54

def capybara_session
  Capybara.current_session
end

#nativeObject


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

def native
  root_element.native
end

#pageObject

Capybara::DSL module “delegates” Capybara methods to the “page” method as such we need to overload this method so that the correct scoping occurs and calls within a section (For example section.find(element)) correctly scope to look within the section only


38
39
40
41
42
43
# File 'lib/site_prism/section.rb', line 38

def page
  return root_element if root_element

  SitePrism.logger.warn('Root Element not found; Falling back to `super`')
  super
end

#parent_pageObject


58
59
60
61
62
# File 'lib/site_prism/section.rb', line 58

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

#visible?Boolean


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

def visible?
  page.visible?
end