Class: Capybara::Node::Simple
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/capybara/node/simple.rb, lib/capybara/minitest/spec.rb |
Overview
A Simple
is a simpler version of Base
which includes only Finders
and Matchers
and does not include 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 Capybara.HTML.
Constant Summary
-
VISIBILITY_XPATH =
# File 'lib/capybara/node/simple.rb', line 206XPath.generate do |x| x.ancestor_or_self[ x.attr(:style)[x.contains('display:none') | x.contains('display: none')] | x.attr(:hidden) | x.qname.one_of('script', 'head') | (~x.self(:summary) & XPath.parent(:details)[!XPath.attr(:open)]) ].boolean end.to_s.freeze
Class Method Summary
- .new(native) ⇒ Simple constructor
Instance Attribute Summary
-
#checked? ⇒ Boolean
readonly
Whether or not the element is checked.
-
#disabled? ⇒ Boolean
readonly
Whether or not the element is disabled.
- #multiple? ⇒ Boolean readonly
- #native readonly
- #readonly? ⇒ Boolean readonly
-
#selected? ⇒ Boolean
readonly
Whether or not the element is selected.
Instance Method Summary
- #==(other)
-
#[](name) ⇒ String
Retrieve the given attribute.
- #allow_reload!
- #inspect
-
#path ⇒ String
An XPath expression describing where on the page the element can be found.
- #synchronize(_seconds = nil)
- #tag_name ⇒ String
- #text(_type = nil, normalize_ws: false) ⇒ String
- #title ⇒ String
- #value ⇒ String
-
#visible?(check_ancestors = true) ⇒ Boolean
Whether or not the element is visible.
- #option_value(option) private
- #find_css(css, **_options) Internal use only Internal use only
- #find_xpath(xpath, **_options) Internal use only Internal use only
- #initial_cache Internal use only Internal use only
- #session_options Internal use only Internal use only
Minitest::Expectations
- Included
DocumentMatchers
- Included
#assert_no_title | Asserts that the page doesn’t have the given title. |
#assert_title | Asserts that the page has the given title. |
#has_no_title? | Checks if the page doesn’t have the given title. |
#has_title? | Checks if the page has the given title. |
#_verify_title |
Matchers
- Included
#==, | |
#assert_all_of_selectors | Asserts that all of the provided selectors are present on the given page or descendants of the current node. |
#assert_ancestor | Asserts that a given selector matches an ancestor of the current node. |
#assert_any_of_selectors | Asserts that any of the provided selectors are present on the given page or descendants of the current node. |
#assert_matches_selector | Asserts that the current node matches a given selector. |
#assert_matches_style | Asserts that an element has the specified CSS styles. |
#assert_no_ancestor, | |
#assert_no_selector | Asserts that a given selector is not on the page or a descendant of the current node. |
#assert_no_sibling, | |
#assert_no_text | Asserts that the page or current node doesn’t have the given text content, ignoring any Capybara.HTML tags. |
#assert_none_of_selectors | Asserts that none of the provided selectors are present on the given page or descendants of the current node. |
#assert_not_matches_selector | Asserts that the current node does not match a given selector. |
#assert_selector | Asserts that a given selector is on the page or a descendant of the current node. |
#assert_sibling | Asserts that a given selector matches a sibling of the current node. |
#assert_style, | |
#assert_text | Asserts that the page or current node has the given text content, ignoring any Capybara.HTML tags. |
#has_ancestor? | Predicate version of |
#has_button? | Checks if the page or current node has a button with the given text, value or id. |
#has_checked_field? | Checks if the page or current node has a radio button or checkbox with the given label, value, id, or test_id attribute that is currently checked. |
#has_content? | Alias for Matchers#has_text?. |
#has_css? | Checks if a given CSS selector is on the page or a descendant of the current node. |
#has_element? | Checks if the page or current node has a element with the given local name. |
#has_field? | Checks if the page or current node has a form field with the given label, name or id. |
#has_link? | Checks if the page or current node has a link with the given text or id. |
#has_no_ancestor? | Predicate version of |
#has_no_button? | Checks if the page or current node has no button with the given text, value or id. |
#has_no_checked_field? | Checks if the page or current node has no radio button or checkbox with the given label, value or id, or test_id attribute that is currently checked. |
#has_no_content? | Alias for Matchers#has_no_text?. |
#has_no_css? | Checks if a given CSS selector is not on the page or a descendant of the current node. |
#has_no_element? | Checks if the page or current node has no element with the given local name. |
#has_no_field? | Checks if the page or current node has no form field with the given label, name or id. |
#has_no_link? | Checks if the page or current node has no link with the given text or id. |
#has_no_select? | Checks if the page or current node has no select field with the given label, name or id. |
#has_no_selector? | Checks if a given selector is not on the page or a descendant of the current node. |
#has_no_sibling? | Predicate version of |
#has_no_table? | Checks if the page or current node has no table with the given id or caption. |
#has_no_text? | Checks if the page or current node does not have the given text content, ignoring any Capybara.HTML tags and normalizing whitespace. |
#has_no_unchecked_field? | Checks if the page or current node has no radio button or checkbox with the given label, value or id, or test_id attribute that is currently unchecked. |
#has_no_xpath? | Checks if a given |
#has_select? | Checks if the page or current node has a select field with the given label, name or id. |
#has_selector? | Checks if a given selector is on the page or a descendant of the current node. |
#has_sibling? | Predicate version of |
#has_style?, | |
#has_table? | Checks if the page or current node has a table with the given id or caption: |
#has_text? | Checks if the page or current node has the given text content, ignoring any Capybara.HTML tags. |
#has_unchecked_field? | Checks if the page or current node has a radio button or checkbox with the given label, value or id, or test_id attribute that is currently unchecked. |
#has_xpath? | Checks if a given |
#matches_css? | Checks if the current node matches given CSS selector. |
#matches_selector? | Checks if the current node matches given selector. |
#matches_style? | Checks if a an element has the specified CSS styles. |
#matches_xpath? | Checks if the current node matches given |
#not_matches_css? | Checks if the current node does not match given CSS selector. |
#not_matches_selector? | Checks if the current node does not match given selector. |
#not_matches_xpath? | Checks if the current node does not match given |
#_set_query_session_options, #_verify_match_result, #_verify_multiple, #_verify_selector_result, #_verify_text, #extract_selector, #make_predicate |
Finders
- Included
#all | Find all elements on the page matching the given selector and options. |
#ancestor | Find an |
#find | Find an |
#find_all | Alias for Finders#all. |
#find_button | Find a button on the page. |
#find_by_id | Find a element on the page, given its id. |
#find_field | Find a form field on the page. |
#find_link | Find a link on the page. |
#first | Find the first element on the page matching the given selector and options. |
#sibling | Find an |
#ambiguous?, #options_include_minimum?, #parent, #prefer_exact?, #synced_resolve |
Constructor Details
.new(native) ⇒ Simple
Instance Attribute Details
#checked? ⇒ Boolean
(readonly)
Whether or not the element is checked.
# File 'lib/capybara/node/simple.rb', line 123
def checked? native.has_attribute?('checked') end
#disabled? ⇒ Boolean
(readonly)
Whether or not the element is disabled.
#multiple? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/node/simple.rb', line 147
def multiple? native.has_attribute?('multiple') end
#native (readonly)
[ GitHub ]# File 'lib/capybara/node/simple.rb', line 20
attr_reader :native
#readonly? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/node/simple.rb', line 151
def readonly? native.has_attribute?('readonly') end
#selected? ⇒ Boolean
(readonly)
Whether or not the element is selected.
# File 'lib/capybara/node/simple.rb', line 143
def selected? native.has_attribute?('selected') end
Instance Method Details
#==(other)
[ GitHub ]
#[](name) ⇒ String
Retrieve the given attribute
element[:title] # => HTML title attribute
#allow_reload!
[ GitHub ]# File 'lib/capybara/node/simple.rb', line 159
def allow_reload!(*) # no op end
#find_css(css, **_options)
# File 'lib/capybara/node/simple.rb', line 175
def find_css(css, ** ) native.css(css) end
#find_xpath(xpath, **_options)
# File 'lib/capybara/node/simple.rb', line 180
def find_xpath(xpath, ** ) native.xpath(xpath) end
#initial_cache
# File 'lib/capybara/node/simple.rb', line 190
def initial_cache {} end
#inspect
[ GitHub ]#option_value(option) (private)
[ GitHub ]# File 'lib/capybara/node/simple.rb', line 200
def option_value(option) return nil if option.nil? option[:value] || option.content end
#path ⇒ String
An XPath expression describing where on the page the element can be found
# File 'lib/capybara/node/simple.rb', line 70
def path native.path end
#session_options
# File 'lib/capybara/node/simple.rb', line 185
def Capybara. end
#synchronize(_seconds = nil)
[ GitHub ]# File 'lib/capybara/node/simple.rb', line 155
def synchronize(_seconds = nil) yield # simple nodes don't need to wait end
#tag_name ⇒ String
# File 'lib/capybara/node/simple.rb', line 60
def tag_name native.node_name end
#text(_type = nil, normalize_ws: false) ⇒ String
# File 'lib/capybara/node/simple.rb', line 31
def text(_type = nil, normalize_ws: false) txt = native.text normalize_ws ? txt.gsub(/[[:space:]]+/, ' ').strip : txt end
#title ⇒ String
# File 'lib/capybara/node/simple.rb', line 166
def title native.title end
#value ⇒ String
# File 'lib/capybara/node/simple.rb', line 78
def value if tag_name == 'textarea' native['_capybara_raw_value'] elsif tag_name == 'select' = find_xpath('.//option[@selected]') if multiple? .map(&method(:option_value)) else option_value( .first || find_xpath('.//option').first) end elsif tag_name == 'input' && %w[radio checkbox].include?(native[:type]) native[:value] || 'on' else native[:value] end end
#visible?(check_ancestors = true) ⇒ Boolean
Whether or not the element is visible. Does not support CSS, so the result may be inaccurate.
# File 'lib/capybara/node/simple.rb', line 103
def visible?(check_ancestors = true) # rubocop:disable Style/OptionalBooleanParameter return false if (tag_name == 'input') && (native[:type] == 'hidden') return false if tag_name == 'template' if check_ancestors !find_xpath(VISIBILITY_XPATH) else # No need for an xpath if only checking the current element !(native.key?('hidden') || /display:\s?none/.match?(native[:style] || '') || %w[script head style].include?(tag_name)) end end