/usr/lib/ruby/vendor_ruby/capybara/node/simple.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 | module Capybara
module Node
##
#
# A {Capybara::Node::Simple} is a simpler version of {Capybara::Node::Base} which
# includes only {Capybara::Node::Finders} and {Capybara::Node::Matchers} and does
# not include {Capybara::Node::Actions}. This type of node is returned when
# using {Capybara.string}.
#
# It is useful in that it does not require a session, an application or a driver,
# but can still use Capybara's finders and matchers on any string that contains HTML.
#
class Simple
include Capybara::Node::Finders
include Capybara::Node::Matchers
attr_reader :native
def initialize(native)
native = Capybara::HTML(native) if native.is_a?(String)
@native = native
end
##
#
# @return [String] The text of the element
#
def text(type=nil)
native.text
end
##
#
# Retrieve the given attribute
#
# element[:title] # => HTML title attribute
#
# @param [Symbol] name The attribute name to retrieve
# @return [String] The value of the attribute
#
def [](name)
attr_name = name.to_s
if attr_name == 'value'
value
elsif 'input' == tag_name and 'checkbox' == native[:type] and 'checked' == attr_name
native['checked'] == 'checked'
else
native[attr_name]
end
end
##
#
# @return [String] The tag name of the element
#
def tag_name
native.node_name
end
##
#
# An XPath expression describing where on the page the element can be found
#
# @return [String] An XPath expression
#
def path
native.path
end
##
#
# @return [String] The value of the form element
#
def value
if tag_name == 'textarea'
native.content
elsif tag_name == 'select'
if native['multiple'] == 'multiple'
native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content }
else
option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
option[:value] || option.content if option
end
elsif tag_name == 'input' && %w(radio checkbox).include?(native[:type])
native[:value] || 'on'
else
native[:value]
end
end
##
#
# Whether or not the element is visible. Does not support CSS, so
# the result may be inaccurate.
#
# @return [Boolean] Whether the element is visible
#
def visible?
native.xpath("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none') or @hidden or name()='script' or name()='head']").size == 0
end
##
#
# Whether or not the element is checked.
#
# @return [Boolean] Whether the element is checked
#
def checked?
native[:checked]
end
##
#
# Whether or not the element is disabled.
#
# @return [Boolean] Whether the element is disabled
def disabled?
native[:disabled]
end
##
#
# Whether or not the element is selected.
#
# @return [Boolean] Whether the element is selected
#
def selected?
native[:selected]
end
def synchronize(seconds=nil)
yield # simple nodes don't need to wait
end
def allow_reload!
# no op
end
def title
native.xpath("//title").first.text
end
def has_title?(content)
title.match(Capybara::Helpers.to_regexp(content))
end
def has_no_title?(content)
not has_title?(content)
end
private
def resolve_query(query, exact=nil)
elements = if query.selector.format == :css
native.css(query.css)
else
native.xpath(query.xpath(exact))
end.map do |node|
self.class.new(node)
end
Capybara::Result.new(elements, query)
end
end
end
end
|