Class: Capybara::RackTest::Node
Direct Known Subclasses
Form
Constant Summary
collapse
- BLOCK_ELEMENTS =
%w[p h1 h2 h3 h4 h5 h6 ol ul pre address blockquote dl div fieldset form hr noscript table].freeze
Instance Attribute Summary
Attributes inherited from Driver::Node
#driver, #initial_cache, #native
Instance Method Summary
collapse
#double_click, #drag_to, #drop, #hover, #initialize, #inspect, #multiple?, #obscured?, #readonly?, #right_click, #scroll_by, #scroll_to, #send_keys, #trigger
Instance Method Details
#==(other) ⇒ Object
130
131
132
|
# File 'lib/capybara/rack_test/node.rb', line 130
def ==(other)
native == other.native
end
|
#[](name) ⇒ Object
25
26
27
|
# File 'lib/capybara/rack_test/node.rb', line 25
def [](name)
string_node[name]
end
|
#all_text ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/capybara/rack_test/node.rb', line 8
def all_text
native.text
.gsub(/[\u200b\u200e\u200f]/, '')
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, ' ')
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
.tr("\u00a0", ' ')
end
|
#checked? ⇒ Boolean
90
91
92
|
# File 'lib/capybara/rack_test/node.rb', line 90
def checked?
string_node.checked?
end
|
#click(keys = [], **options) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/capybara/rack_test/node.rb', line 66
def click(keys = [], **options)
options.delete(:offset)
raise ArgumentError, 'The RackTest driver does not support click options' unless keys.empty? && options.empty?
if link?
follow_link
elsif submits?
associated_form = form
Capybara::RackTest::Form.new(driver, associated_form).submit(self) if associated_form
elsif checkable?
set(!checked?)
elsif tag_name == 'label'
click_label
end
end
|
#disabled? ⇒ Boolean
98
99
100
101
102
103
104
105
106
|
# File 'lib/capybara/rack_test/node.rb', line 98
def disabled?
return true if string_node.disabled?
if %w[option optgroup].include? tag_name
find_xpath(OPTION_OWNER_XPATH)[0].disabled?
else
!find_xpath(DISABLED_BY_FIELDSET_XPATH).empty?
end
end
|
#find_css(locator, **_hints) ⇒ Object
116
117
118
|
# File 'lib/capybara/rack_test/node.rb', line 116
def find_css(locator, **_hints)
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |el| self.class.new(driver, el) }
end
|
#find_xpath(locator, **_hints) ⇒ Object
112
113
114
|
# File 'lib/capybara/rack_test/node.rb', line 112
def find_xpath(locator, **_hints)
native.xpath(locator).map { |el| self.class.new(driver, el) }
end
|
#path ⇒ Object
108
109
110
|
# File 'lib/capybara/rack_test/node.rb', line 108
def path
native.path
end
|
#select_option ⇒ Object
53
54
55
56
57
58
|
# File 'lib/capybara/rack_test/node.rb', line 53
def select_option
return if disabled?
deselect_options unless select_node.multiple?
native['selected'] = 'selected'
end
|
#selected? ⇒ Boolean
94
95
96
|
# File 'lib/capybara/rack_test/node.rb', line 94
def selected?
string_node.selected?
end
|
#set(value, **options) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/capybara/rack_test/node.rb', line 37
def set(value, **options)
return if disabled? || readonly?
warn "Options passed to Node#set but the RackTest driver doesn't support any - ignoring" unless options.empty?
if value.is_a?(Array) && !multiple?
raise TypeError, "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
end
if radio? then set_radio(value)
elsif checkbox? then set_checkbox(value)
elsif input_field? then set_input(value)
elsif textarea? then native['_capybara_raw_value'] = value.to_s
end
end
|
#style(_styles) ⇒ Object
29
30
31
|
# File 'lib/capybara/rack_test/node.rb', line 29
def style(_styles)
raise NotImplementedError, 'The rack_test driver does not process CSS'
end
|
#tag_name ⇒ Object
82
83
84
|
# File 'lib/capybara/rack_test/node.rb', line 82
def tag_name
native.node_name
end
|
#unselect_option ⇒ Object
60
61
62
63
64
|
# File 'lib/capybara/rack_test/node.rb', line 60
def unselect_option
raise Capybara::UnselectNotAllowed, 'Cannot unselect option from single select box.' unless select_node.multiple?
native.remove_attribute('selected')
end
|
#value ⇒ Object
33
34
35
|
# File 'lib/capybara/rack_test/node.rb', line 33
def value
string_node.value
end
|
#visible? ⇒ Boolean
86
87
88
|
# File 'lib/capybara/rack_test/node.rb', line 86
def visible?
string_node.visible?
end
|
#visible_text ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/capybara/rack_test/node.rb', line 17
def visible_text
displayed_text.gsub(/\ +/, ' ')
.gsub(/[\ \n]*\n[\ \n]*/, "\n")
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
.tr("\u00a0", ' ')
end
|