Class: PageObject::Elements::Element

Inherits:
Object
  • Object
show all
Includes:
NestedElements
Defined in:
lib/page-object/elements/element.rb

Overview

Contains functionality that is common across all elements.

See Also:

  • for the Watir version of all common methods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NestedElements

included

Constructor Details

#initialize(element) ⇒ Element


15
16
17
18
# File 'lib/page-object/elements/element.rb', line 15

def initialize(element)
  @element = element
  @platform = PageObject::Platforms::Watir::PageObject.new(@element)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

delegate calls to driver element


173
174
175
176
# File 'lib/page-object/elements/element.rb', line 173

def method_missing(*args, &block)
  m = args.shift
  element.send m, *args, &block
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element


13
14
15
# File 'lib/page-object/elements/element.rb', line 13

def element
  @element
end

Class Method Details

.plural_formObject

specify plural form of element


37
38
39
40
41
42
43
# File 'lib/page-object/elements/element.rb', line 37

def self.plural_form
  "#{self.to_s.split('::')[-1].
      gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
      gsub(/([a-z\d])([A-Z])/, '\1_\2').
      tr("-", "_").
      downcase}s"
end

Instance Method Details

#==(other) ⇒ Object

compare this element to another to determine if they are equal


70
71
72
# File 'lib/page-object/elements/element.rb', line 70

def ==(other)
  other.is_a? self.class and element == other.element
end

#check_exists(timeout = ::PageObject.default_element_wait) ⇒ Object

Keeps checking until the element exists


61
62
63
64
65
# File 'lib/page-object/elements/element.rb', line 61

def check_exists(timeout=::PageObject.default_element_wait)
  timed_loop(timeout) do |element|
    element.exists?
  end
end

#check_visible(timeout = ::PageObject.default_element_wait) ⇒ Object

Keeps checking until the element is visible


50
51
52
53
54
# File 'lib/page-object/elements/element.rb', line 50

def check_visible(timeout=::PageObject.default_element_wait)
  timed_loop(timeout) do |element|
    element.visible?
  end
end

#children(opt = {}) ⇒ Object

Return all elements that are children of this element


111
112
113
114
# File 'lib/page-object/elements/element.rb', line 111

def children(opt={})
  children = element.children(opt)
  children.collect {|child| pageobject_wrapper(child)}
end

#disabled?Boolean

return true if the element is not enabled


23
24
25
# File 'lib/page-object/elements/element.rb', line 23

def disabled?
  not enabled?
end

#following_sibling(opt = {}) ⇒ Object

Return the element that exists at the same level of the DOM immediately after this element


95
96
97
98
# File 'lib/page-object/elements/element.rb', line 95

def following_sibling(opt={})
  sibling = element.following_sibling(opt)
  pageobject_wrapper(sibling)
end

#following_siblings(opt = {}) ⇒ Object

Return all elements that exist at the same level of the DOM immediately after this element


129
130
131
132
# File 'lib/page-object/elements/element.rb', line 129

def following_siblings(opt={})
  siblings = element.following_siblings(opt)
  siblings.collect {|sibling| pageobject_wrapper(sibling)}
end

#nameObject


167
168
169
# File 'lib/page-object/elements/element.rb', line 167

def name
  element.attribute(:name)
end

#parent(opt = {}) ⇒ Object

find the parent element


77
78
79
80
# File 'lib/page-object/elements/element.rb', line 77

def parent(opt = {})
  parent = element.parent(opt)
  pageobject_wrapper(parent)
end

#preceding_sibling(opt = {}) ⇒ Object

Return the element that exists at the same level of the DOM immediately prior to this element


86
87
88
89
# File 'lib/page-object/elements/element.rb', line 86

def preceding_sibling(opt = {})
  sibling = element.preceding_sibling(opt)
  pageobject_wrapper(sibling)
end

#preceding_siblings(opt = {}) ⇒ Object

Return all elements that exist at the same level of the DOM immediately prior to this element


120
121
122
123
# File 'lib/page-object/elements/element.rb', line 120

def preceding_siblings(opt={})
  siblings = element.preceding_siblings(opt)
  siblings.collect {|sibling| pageobject_wrapper(sibling)}
end

#present?Boolean

return true if the element exists and is visible


30
31
32
# File 'lib/page-object/elements/element.rb', line 30

def present?
  element.present?
end

#respond_to_missing?(m, *args) ⇒ Boolean


178
179
180
# File 'lib/page-object/elements/element.rb', line 178

def respond_to_missing?(m,*args)
  element.respond_to?(m) || super
end

#siblings(opt = {}) ⇒ Object

Return all elements that are direct children of this element's parent


103
104
105
106
# File 'lib/page-object/elements/element.rb', line 103

def siblings(opt={})
  siblings = element.siblings(opt)
  siblings.collect {|sibling| pageobject_wrapper(sibling)}
end

#wait_until(timeout = ::PageObject.default_element_wait, message = nil, &block) ⇒ Object

Waits until the block returns true


163
164
165
# File 'lib/page-object/elements/element.rb', line 163

def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block)
  element.wait_until(timeout: timeout, message: message, &block)
end

#when_not_present(timeout = ::PageObject.default_element_wait) ⇒ Object Also known as: when_not_visible

Waits until the element is not present

timing out


151
152
153
# File 'lib/page-object/elements/element.rb', line 151

def when_not_present(timeout=::PageObject.default_element_wait)
  element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?)
end

#when_present(timeout = ::PageObject.default_element_wait) ⇒ Object Also known as: when_visible

Waits until the element is present


139
140
141
142
# File 'lib/page-object/elements/element.rb', line 139

def when_present(timeout=::PageObject.default_element_wait)
  element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?)
  self
end