class Druid::Elements::Element

Contains functionality that is common across all elements

Attributes

driver[RW]
element[RW]

Public Class Methods

new(element) click to toggle source
# File lib/druid/elements/element.rb, line 15
def initialize(element)
  @element = element
  @driver = @element
end

Public Instance Methods

==(other) click to toggle source

compare this element to another to determine if they are equal @return [Boolean]

# File lib/druid/elements/element.rb, line 37
def ==(other)
  other.is_a? self.class and element == other.element
end
check_exist(timeout=Druid.default_element_wait) click to toggle source

alias_method :when_present, :check_visible alias_method :when_visible, :check_visible

# File lib/druid/elements/element.rb, line 50
def check_exist(timeout=Druid.default_element_wait)
  timed_loop(timeout) do |element|
    element.exists?
  end
  # wait_until(timeout: timeout, &:exist?)
end
check_visible(timeout=Druid.default_element_wait) click to toggle source
# File lib/druid/elements/element.rb, line 41
def check_visible(timeout=Druid.default_element_wait)
  timed_loop(timeout) do |element|
    element.present?
  end
  # wait_until(timeout: timeout, message: "Element not visible in #{timeout} seconds", &:present?)
end
children(opt={}) click to toggle source

Return all elements that are children of this element

# File lib/druid/elements/element.rb, line 94
def children(opt={})
  children = element.children(opt)
  children.collect {|child| druid_wrapper(child)}
end
disabled?() click to toggle source

return true if the element is not enabled

# File lib/druid/elements/element.rb, line 22
def disabled?
  not enabled?
end
following_sibling(opt={}) click to toggle source

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

# File lib/druid/elements/element.rb, line 78
def following_sibling(opt={})
  sibling = element.following_sibling(opt)
  druid_wrapper(sibling)
end
following_siblings(opt={}) click to toggle source

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

# File lib/druid/elements/element.rb, line 112
def following_siblings(opt={})
  siblings = element.following_siblings(opt)
  siblings.collect {|sibling| druid_wrapper(sibling)}
end
method_missing(*args, &block) click to toggle source

@private delegate calls to driver element

# File lib/druid/elements/element.rb, line 156
def method_missing(*args, &block)
  m = args.shift
  element.send m, *args, &block
end
name() click to toggle source
# File lib/druid/elements/element.rb, line 150
def name
  element.attribute(:name)
end
parent(opt = {}) click to toggle source

find the parent element

# File lib/druid/elements/element.rb, line 60
def parent(opt = {})
  parent = element.parent(opt)
  druid_wrapper(parent)
end
preceding_sibling(opt = {}) click to toggle source

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

# File lib/druid/elements/element.rb, line 69
def preceding_sibling(opt = {})
  sibling = element.preceding_sibling(opt)
  druid_wrapper(sibling)
end
preceding_siblings(opt={}) click to toggle source

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

# File lib/druid/elements/element.rb, line 103
def preceding_siblings(opt={})
  siblings = element.preceding_siblings(opt)
  siblings.collect {|sibling| druid_wrapper(sibling)}
end
present?() click to toggle source

return true if the element exists and is visible

# File lib/druid/elements/element.rb, line 29
def present?
  element.present?
end
respond_to_missing?(m,*args) click to toggle source
Calls superclass method
# File lib/druid/elements/element.rb, line 161
def respond_to_missing?(m,*args)
  element.respond_to?(m) || super
end
siblings(opt={}) click to toggle source

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

# File lib/druid/elements/element.rb, line 86
def siblings(opt={})
  siblings = element.siblings(opt)
  siblings.collect {|sibling| druid_wrapper(sibling)}
end
wait_until(timeout=Druid.default_element_wait, message=nil, &block) click to toggle source

Waits until the block returns true

@param [Integer] (defaults to: 5) seconds to wait before timing out @param [String] the message to display if the event timeouts @param the block to execute when the event occurs

# File lib/druid/elements/element.rb, line 146
def wait_until(timeout=Druid.default_element_wait, message=nil, &block)
  element.wait_until(timeout: timeout, message: message, &block)
end
when_not_present(timeout=Druid.default_element_wait) click to toggle source

Waits until the element is not present

@param [Integer] (defaults to: 5) seconds to wait before timing out

# File lib/druid/elements/element.rb, line 134
def when_not_present(timeout=Druid.default_element_wait)
  element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?)
end
Also aliased as: when_not_visible
when_not_visible(timeout=Druid.default_element_wait)
Alias for: when_not_present
when_present(timeout=Druid.default_element_wait) click to toggle source

Wait until the element is present

@param [Integer] (defaults to: 5) seconds to wait before timing out

# File lib/druid/elements/element.rb, line 122
def when_present(timeout=Druid.default_element_wait)
  element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?)
  self
end
Also aliased as: when_visible
when_visible(timeout=Druid.default_element_wait)
Alias for: when_present

Protected Instance Methods

druid_wrapper(object) click to toggle source
# File lib/druid/elements/element.rb, line 167
def druid_wrapper(object)
  type = element.type if object.tag_name.to_sym == :input
  cls = Druid::Elements.element_class_for(object.tag_name, type)
  cls.new(object.to_subtype)
end

Private Instance Methods

timed_loop(timeout) { |self| ... } click to toggle source
# File lib/druid/elements/element.rb, line 175
def timed_loop(timeout)
  end_time = ::Time.now + timeout
  until ::Time.now > end_time
    result = yield(self)
    return result if result
    sleep 0.5
  end
  false
end