Class: SitePrism::Section

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL, ElementChecker, ElementContainer, 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 ElementContainer

included

Methods included from Loadable

included, #loaded?, #when_loaded

Methods included from ElementChecker

#all_there?, #elements_present

Constructor Details

#initialize(parent, root_element) ⇒ Section

Returns a new instance of Section.



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

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.



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

def parent
  @parent
end

#root_elementObject (readonly)

Returns the value of attribute root_element.



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

def root_element
  @root_element
end

Class Method Details

.default_search_argumentsObject



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

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



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

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

Instance Method Details

#evaluate_script(input) ⇒ Object



49
50
51
# File 'lib/site_prism/section.rb', line 49

def evaluate_script(input)
  Capybara.current_session.evaluate_script(input)
end

#execute_script(input) ⇒ Object



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

def execute_script(input)
  Capybara.current_session.execute_script(input)
end

#nativeObject



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

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



37
38
39
# File 'lib/site_prism/section.rb', line 37

def page
  root_element || super
end

#parent_pageObject



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

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

#visible?Boolean

Returns:

  • (Boolean)


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

def visible?
  page.visible?
end