Class: Capybara::Driver::Akephalos::Node
- Inherits:
-
Node
- Object
- Node
- Capybara::Driver::Akephalos::Node
- Defined in:
- lib/akephalos/capybara.rb
Overview
Akephalos-specific implementation for Capybara’s Node class.
Instance Method Summary collapse
-
#[](name) ⇒ String
The attribute value.
-
#click ⇒ Object
Click the element.
-
#drag_to(element) ⇒ Object
Drag the element on top of the target element.
-
#select(option) ⇒ Object
Select an option from a select box.
-
#set(value) ⇒ Object
Set the form element’s value.
-
#tag_name ⇒ String
The element’s tag name.
-
#text ⇒ String
The inner text of the node.
-
#trigger(event) ⇒ Object
Trigger an event on the element.
-
#unselect(option) ⇒ Object
Unselect an option from a select box.
-
#value ⇒ String
The form element’s value.
-
#visible? ⇒ true, false
The element’s visiblity.
Instance Method Details
#[](name) ⇒ String
Returns 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 |
#click ⇒ Object
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.
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.
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 = node..map(&:text).join(", ") raise ::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.
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_name ⇒ String
Returns the element’s tag name.
99 100 101 |
# File 'lib/akephalos/capybara.rb', line 99 def tag_name node.tag_name end |
#text ⇒ String
Returns 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.
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.
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 ::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box." end result = node.unselect_option(option) if result == nil = node..map(&:text).join(", ") raise ::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}" else result end end |
#value ⇒ String
Returns 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.
105 106 107 |
# File 'lib/akephalos/capybara.rb', line 105 def visible? node.visible? end |