Class: Capybara::Driver::Celerity::Node
- Inherits:
-
Node
- Object
- Node
- Capybara::Driver::Celerity::Node
show all
- Defined in:
- lib/capybara/driver/celerity_driver.rb
Instance Attribute Summary
Attributes inherited from Node
#driver, #native
Instance Method Summary
collapse
Methods inherited from Node
#initialize, #inspect
Instance Method Details
#[](name) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/capybara/driver/celerity_driver.rb', line 7
def [](name)
value = if name.to_sym == :class
native.class_name
else
native.send(name.to_sym)
end
return value if value and not value.to_s.empty?
end
|
#click ⇒ Object
52
53
54
|
# File 'lib/capybara/driver/celerity_driver.rb', line 52
def click
native.click
end
|
#drag_to(element) ⇒ Object
56
57
58
59
60
|
# File 'lib/capybara/driver/celerity_driver.rb', line 56
def drag_to(element)
native.fire_event('mousedown')
element.native.fire_event('mousemove')
element.native.fire_event('mouseup')
end
|
#find(locator) ⇒ Object
80
81
82
83
84
|
# File 'lib/capybara/driver/celerity_driver.rb', line 80
def find(locator)
noko_node = Nokogiri::HTML(driver.body).xpath(native.xpath).first
all_nodes = noko_node.xpath(locator).map { |n| n.path }.join(' | ')
if all_nodes.empty? then [] else driver.find(all_nodes) end
end
|
#path ⇒ Object
72
73
74
|
# File 'lib/capybara/driver/celerity_driver.rb', line 72
def path
native.xpath
end
|
#select_option(option) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/capybara/driver/celerity_driver.rb', line 28
def select_option(option)
native.select(option)
rescue
options = find("//option").map { |o| "'#{o.text}'" }.join(', ')
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
end
|
#set(value) ⇒ Object
24
25
26
|
# File 'lib/capybara/driver/celerity_driver.rb', line 24
def set(value)
native.set(value)
end
|
#tag_name ⇒ Object
62
63
64
65
66
|
# File 'lib/capybara/driver/celerity_driver.rb', line 62
def tag_name
native.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1]
end
|
#text ⇒ Object
3
4
5
|
# File 'lib/capybara/driver/celerity_driver.rb', line 3
def text
native.text
end
|
#trigger(event) ⇒ Object
76
77
78
|
# File 'lib/capybara/driver/celerity_driver.rb', line 76
def trigger(event)
native.fire_event(event.to_s)
end
|
#unselect_option(option) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/capybara/driver/celerity_driver.rb', line 35
def unselect_option(option)
unless native.multiple?
raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
end
selected_options = native.selected_options
if unselect_option = selected_options.detect { |value| value == option } ||
selected_options.detect { |value| value.index(option) }
native.clear
(selected_options - [unselect_option]).each { |value| native.select_value(value) }
else
options = find("//option").map { |o| "'#{o.text}'" }.join(', ')
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
end
end
|
#value ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/capybara/driver/celerity_driver.rb', line 16
def value
if tag_name == "select" and native.multiple?
native.selected_options
else
self[:value]
end
end
|
#visible? ⇒ Boolean
68
69
70
|
# File 'lib/capybara/driver/celerity_driver.rb', line 68
def visible?
native.visible?
end
|