/usr/lib/ruby/vendor_ruby/capybara/rack_test/node.rb is in ruby-capybara 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | class Capybara::RackTest::Node < Capybara::Driver::Node
def all_text
Capybara::Helpers.normalize_whitespace(native.text)
end
def visible_text
Capybara::Helpers.normalize_whitespace(unnormalized_text)
end
def [](name)
string_node[name]
end
def value
string_node.value
end
def set(value)
if (Array === value) && !self[:multiple]
raise ArgumentError.new "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
end
if radio?
set_radio(value)
elsif checkbox?
set_checkbox(value)
elsif input_field?
set_input(value)
elsif textarea?
native.content = value.to_s unless self[:readonly]
end
end
def select_option
if select_node['multiple'] != 'multiple'
select_node.find_xpath(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
end
native["selected"] = 'selected'
end
def unselect_option
if select_node['multiple'] != 'multiple'
raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
end
native.remove_attribute('selected')
end
def click
if tag_name == 'a'
method = self["data-method"] if driver.options[:respect_data_method]
method ||= :get
driver.follow(method, self[:href].to_s)
elsif (tag_name == 'input' and %w(submit image).include?(type)) or
((tag_name == 'button') and type.nil? or type == "submit")
associated_form = form
Capybara::RackTest::Form.new(driver, associated_form).submit(self) if associated_form
end
end
def tag_name
native.node_name
end
def visible?
string_node.visible?
end
def checked?
string_node.checked?
end
def selected?
string_node.selected?
end
def disabled?
if %w(option optgroup).include? tag_name
string_node.disabled? || find_xpath("parent::*")[0].disabled?
else
string_node.disabled?
end
end
def path
native.path
end
def find_xpath(locator)
native.xpath(locator).map { |n| self.class.new(driver, n) }
end
def find_css(locator)
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |n| self.class.new(driver, n) }
end
def ==(other)
native == other.native
end
protected
def unnormalized_text
if !visible?
''
elsif native.text?
native.text
elsif native.element?
native.children.map do |child|
Capybara::RackTest::Node.new(driver, child).unnormalized_text
end.join
else
''
end
end
private
def string_node
@string_node ||= Capybara::Node::Simple.new(native)
end
# a reference to the select node if this is an option node
def select_node
find_xpath('./ancestor::select').first
end
def type
native[:type]
end
def form
if native[:form]
native.xpath("//form[@id='#{native[:form]}']").first
else
native.ancestors('form').first
end
end
def set_radio(value)
other_radios_xpath = XPath.generate { |x| x.anywhere(:input)[x.attr(:name).equals(self[:name])] }.to_s
driver.dom.xpath(other_radios_xpath).each { |node| node.remove_attribute("checked") }
native['checked'] = 'checked'
end
def set_checkbox(value)
if value && !native['checked']
native['checked'] = 'checked'
elsif !value && native['checked']
native.remove_attribute('checked')
end
end
def set_input(value)
if text_or_password? && attribute_is_not_blank?(:maxlength)
# Browser behavior for maxlength="0" is inconsistent, so we stick with
# Firefox, allowing no input
value = value.to_s[0...self[:maxlength].to_i]
end
if Array === value #Assert multiple attribute is present
value.each do |v|
new_native = native.clone
new_native.remove_attribute('value')
native.add_next_sibling(new_native)
new_native['value'] = v.to_s
end
native.remove
else
native['value'] = value.to_s unless self[:readonly]
end
end
def attribute_is_not_blank?(attribute)
self[attribute] && !self[attribute].empty?
end
def checkbox?
input_field? && type == 'checkbox'
end
def input_field?
tag_name == 'input'
end
def radio?
input_field? && type == 'radio'
end
def textarea?
tag_name == "textarea"
end
def text_or_password?
input_field? && (type == 'text' || type == 'password')
end
end
|