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 Driver::Node class.
Instance Method Summary collapse
-
#[](name) ⇒ String
The attribute value.
-
#checked? ⇒ true, false
The element’s visiblity.
-
#click ⇒ Object
Click the element.
-
#drag_to(element) ⇒ Object
Drag the element on top of the target element.
-
#find(selector) ⇒ Array<Node>
The matched nodes.
-
#path ⇒ String
The XPath to locate the node.
- #select_option ⇒ Object
-
#selected? ⇒ true, false
The element’s visiblity.
-
#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.
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.
102 103 104 |
# File 'lib/akephalos/capybara.rb', line 102 def checked? native.checked? end |
#click ⇒ Object
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.
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.
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 |
#path ⇒ String
Returns the XPath to locate the node.
114 115 116 |
# File 'lib/akephalos/capybara.rb', line 114 def path native.xpath end |
#select_option ⇒ Object
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.
108 109 110 |
# File 'lib/akephalos/capybara.rb', line 108 def selected? native.selected? 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' 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_name ⇒ String
Returns the element’s tag name.
90 91 92 |
# File 'lib/akephalos/capybara.rb', line 90 def tag_name native.tag_name end |
#text ⇒ String
Returns 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.
122 123 124 |
# File 'lib/akephalos/capybara.rb', line 122 def trigger(event) native.fire_event(event.to_s) end |
#unselect_option ⇒ Object
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 |
#value ⇒ String+
Returns 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.
96 97 98 |
# File 'lib/akephalos/capybara.rb', line 96 def visible? native.visible? end |