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

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

Overview

Akephalos-specific implementation for Capybara’s 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



15
16
17
18
19
20
21
22
23
# File 'lib/akephalos/capybara.rb', line 15

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

#clickObject

Click the element.



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

def click
  node.click
end

#drag_to(element) ⇒ Object

Drag the element on top of the target element.

Parameters:

  • element (Node)

    the target element



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

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

#select(option) ⇒ Object

Select an option from a select box.

Parameters:

  • option (String)

    the option to select



59
60
61
62
63
64
65
66
67
68
# File 'lib/akephalos/capybara.rb', line 59

def select(option)
  result = node.select_option(option)

  if result == nil
    options = node.options.map(&:text).join(", ")
    raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
  else
    result
  end
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'
    node.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'
    node.value = value.to_s
  end
end

#tag_nameString

Returns the element’s tag name.

Returns:

  • (String)

    the element’s tag name



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

def tag_name
  node.tag_name
end

#textString

Returns the inner text of the node.

Returns:

  • (String)

    the inner text of the node



27
28
29
# File 'lib/akephalos/capybara.rb', line 27

def text
  node.text
end

#trigger(event) ⇒ Object

Trigger an event on the element.

Parameters:

  • event (String)

    the event to trigger



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

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

#unselect(option) ⇒ Object

Unselect an option from a select box.

Parameters:

  • option (String)

    the option to unselect



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/akephalos/capybara.rb', line 74

def unselect(option)
  unless self[:multiple]
    raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
  end

  result = node.unselect_option(option)

  if result == nil
    options = node.options.map(&:text).join(", ")
    raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
  else
    result
  end
end

#valueString

Returns the form element’s value.

Returns:

  • (String)

    the form element’s value



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

def value
  node.value
end

#visible?true, false

Returns the element’s visiblity.

Returns:

  • (true, false)

    the element’s visiblity



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

def visible?
  node.visible?
end