Class: Capybara::Driver::Akephalos::Node

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

Overview

Akephalos-specific implementation for Capybara’s Driver::Node class.

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ String

Returns the attribute value.

Parameters:

  • name (String)

    attribute name

Returns:

  • (String)

    the attribute value



21
22
23
24
25
26
27
28
29
# File 'lib/akephalos/capybara.rb', line 21

def [](name)
  name = name.to_s
  case name
  when 'checked'
    native.checked?
  else
    native[name.to_s]
  end
end

#checked?true, false

Returns the element’s visiblity.

Returns:

  • (true, false)

    the element’s visiblity



100
101
102
# File 'lib/akephalos/capybara.rb', line 100

def checked?
  native.checked?
end

#clickObject

Click the element.



72
73
74
# File 'lib/akephalos/capybara.rb', line 72

def click
  native.click
end

#drag_to(element) ⇒ Object

Drag the element on top of the target element.

Parameters:

  • element (Node)

    the target element



80
81
82
83
84
# File 'lib/akephalos/capybara.rb', line 80

def drag_to(element)
  trigger('mousedown')
  element.trigger('mousemove')
  element.trigger('mouseup')
end

#find(selector) ⇒ Array<Node>

Returns the matched nodes.

Parameters:

  • selector (String)

    XPath query

Returns:

  • (Array<Node>)

    the matched nodes



127
128
129
130
131
# File 'lib/akephalos/capybara.rb', line 127

def find(selector)
  nodes = []
  native.find(selector).each { |node| nodes << self.class.new(self, node) }
  nodes
end

#pathString

Returns the XPath to locate the node.

Returns:

  • (String)

    the XPath to locate the node



112
113
114
# File 'lib/akephalos/capybara.rb', line 112

def path
  native.xpath
end

#select_optionObject



56
57
58
# File 'lib/akephalos/capybara.rb', line 56

def select_option
  native.click
end

#selected?true, false

Returns the element’s visiblity.

Returns:

  • (true, false)

    the element’s visiblity



106
107
108
# File 'lib/akephalos/capybara.rb', line 106

def selected?
  native.selected?
end

#set(value) ⇒ Object

Set the form element’s value.

Parameters:

  • value (String)

    the form element’s new value



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/akephalos/capybara.rb', line 41

def set(value)
  if tag_name == 'textarea'
    native.value = value.to_s
  elsif tag_name == 'input' and type == 'radio'
    click
  elsif tag_name == 'input' and type == 'checkbox'
    if value != self['checked']
      click
    end
  elsif tag_name == 'input'
    native.value = value.to_s
  end
end

#tag_nameString

Returns the element’s tag name.

Returns:

  • (String)

    the element’s tag name



88
89
90
# File 'lib/akephalos/capybara.rb', line 88

def tag_name
  native.tag_name
end

#textString

Returns the inner text of the node.

Returns:

  • (String)

    the inner text of the node



14
15
16
# File 'lib/akephalos/capybara.rb', line 14

def text
  native.text
end

#trigger(event) ⇒ Object

Trigger an event on the element.

Parameters:

  • event (String)

    the event to trigger



120
121
122
# File 'lib/akephalos/capybara.rb', line 120

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

#unselect_optionObject

Unselect an option from a select box.



63
64
65
66
67
68
69
# File 'lib/akephalos/capybara.rb', line 63

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

  native.unselect
end

#valueString+

Returns the form element’s value.

Returns:

  • (String, Array<String>)

    the form element’s value



33
34
35
# File 'lib/akephalos/capybara.rb', line 33

def value
  native.value
end

#visible?true, false

Returns the element’s visiblity.

Returns:

  • (true, false)

    the element’s visiblity



94
95
96
# File 'lib/akephalos/capybara.rb', line 94

def visible?
  native.visible?
end