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



102
103
104
# File 'lib/akephalos/capybara.rb', line 102

def checked?
  native.checked?
end

#clickObject

Click the element.



74
75
76
# File 'lib/akephalos/capybara.rb', line 74

def click
  native.click
end

#drag_to(element) ⇒ Object

Drag the element on top of the target element.

Parameters:

  • element (Node)

    the target element



82
83
84
85
86
# File 'lib/akephalos/capybara.rb', line 82

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



129
130
131
132
133
# File 'lib/akephalos/capybara.rb', line 129

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



114
115
116
# File 'lib/akephalos/capybara.rb', line 114

def path
  native.xpath
end

#select_optionObject



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

def select_option
  #if it is already selected: do nothing
  #if it isn't selected: click on it
  native.click unless selected?
end

#selected?true, false

Returns the element’s visiblity.

Returns:

  • (true, false)

    the element’s visiblity



108
109
110
# File 'lib/akephalos/capybara.rb', line 108

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



90
91
92
# File 'lib/akephalos/capybara.rb', line 90

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



122
123
124
# File 'lib/akephalos/capybara.rb', line 122

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

#unselect_optionObject

Unselect an option from a select box.



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

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



96
97
98
# File 'lib/akephalos/capybara.rb', line 96

def visible?
  native.visible?
end