Class: Capybara::Driver::Celerity::Node

Inherits:
Node
  • Object
show all
Defined in:
lib/capybara/driver/celerity_driver.rb

Instance Attribute Summary

Attributes inherited from Node

#driver, #native

Instance Method Summary collapse

Methods inherited from Node

#drag_to_location, #initialize, #inspect

Constructor Details

This class inherits a constructor from Capybara::Driver::Node

Instance Method Details

#[](name) ⇒ Object



7
8
9
10
# File 'lib/capybara/driver/celerity_driver.rb', line 7

def [](name)
  value = native.attribute_value(name.to_sym)
  return value if value and not value.to_s.empty?
end

#checked?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/capybara/driver/celerity_driver.rb', line 59

def checked?
  native.checked?
rescue # https://github.com/langalex/culerity/issues/issue/33
  false
end

#clickObject



39
40
41
# File 'lib/capybara/driver/celerity_driver.rb', line 39

def click
  native.click
end

#drag_to(element) ⇒ Object



43
44
45
46
47
# File 'lib/capybara/driver/celerity_driver.rb', line 43

def drag_to(element)
  native.fire_event('mousedown')
  element.native.fire_event('mousemove')
  element.native.fire_event('mouseup')
end

#find(locator) ⇒ Object



79
80
81
82
83
# File 'lib/capybara/driver/celerity_driver.rb', line 79

def find(locator)
  noko_node = Nokogiri::HTML(driver.body).xpath(native.xpath).first
  all_nodes = noko_node.xpath(locator).map { |n| n.path }.join(' | ')
  if all_nodes.empty? then [] else driver.find(all_nodes) end
end

#pathObject



71
72
73
# File 'lib/capybara/driver/celerity_driver.rb', line 71

def path
  native.xpath
end

#select_optionObject



24
25
26
# File 'lib/capybara/driver/celerity_driver.rb', line 24

def select_option
  native.click
end

#selected?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
# File 'lib/capybara/driver/celerity_driver.rb', line 65

def selected?
  native.selected?
rescue # https://github.com/langalex/culerity/issues/issue/33
  false
end

#set(value) ⇒ Object



20
21
22
# File 'lib/capybara/driver/celerity_driver.rb', line 20

def set(value)
  native.set(value)
end

#tag_nameObject



49
50
51
52
53
# File 'lib/capybara/driver/celerity_driver.rb', line 49

def tag_name
  # FIXME: this might be the dumbest way ever of getting the tag name
  # there has to be something better...
  native.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1]
end

#textObject



3
4
5
# File 'lib/capybara/driver/celerity_driver.rb', line 3

def text
  native.text
end

#trigger(event) ⇒ Object



75
76
77
# File 'lib/capybara/driver/celerity_driver.rb', line 75

def trigger(event)
  native.fire_event(event.to_s)
end

#unselect_optionObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/capybara/driver/celerity_driver.rb', line 28

def unselect_option
  unless select_node.native.multiple?
    raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
  end

  # FIXME: couldn't find a clean way to unselect, so clear and reselect
  selected_nodes = select_node.find('.//option[@selected]')
  select_node.native.clear
  selected_nodes.each { |n| n.click unless n.path == path }
end

#valueObject



12
13
14
15
16
17
18
# File 'lib/capybara/driver/celerity_driver.rb', line 12

def value
  if tag_name == "select" and native.multiple?
    find(".//option[@selected]").map { |n| if n.has_value? then n.value else n.text end }
  else
    native.value
  end
end

#visible?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/capybara/driver/celerity_driver.rb', line 55

def visible?
  native.visible?
end