module Capybara::Node::Matchers
def ==(other)
def ==(other) eql?(other) || (other.respond_to?(:base) && base == other.base) end
def _set_query_session_options(*query_args, **query_options)
def _set_query_session_options(*query_args, **query_options) query_options[:session_options] = session_options query_args.push(query_options) end
def _verify_match_result(query_args, optional_filter_block)
def _verify_match_result(query_args, optional_filter_block) query_args = _set_query_session_options(*query_args) query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block) synchronize(query.wait) do yield query.resolve_for(parent || session&.document || query_scope) end true end
def _verify_selector_result(query_args, optional_filter_block)
def _verify_selector_result(query_args, optional_filter_block) query_args = _set_query_session_options(*query_args) query = Capybara::Queries::SelectorQuery.new(*query_args, &optional_filter_block) synchronize(query.wait) do yield query.resolve_for(self), query end true end
def _verify_text(query_args)
def _verify_text(query_args) query_args = _set_query_session_options(*query_args) query = Capybara::Queries::TextQuery.new(*query_args) synchronize(query.wait) do yield query.resolve_for(self), query end true end
def assert_all_of_selectors(*args, wait: nil, **options, &optional_filter_block)
-
assert_all_of_selectors([kind = Capybara.default_selector], *locators, **options)
def assert_all_of_selectors(*args, wait: nil, **options, &optional_filter_block) wait = session_options.default_max_wait_time if wait.nil? selector = extract_selector(args) synchronize(wait) do args.each do |locator| assert_selector(selector, locator, options, &optional_filter_block) end end end
def assert_matches_selector(*args, &optional_filter_block)
-
(Capybara::ExpectationNotMet)- If the selector does not match
Parameters:
-
() --
def assert_matches_selector(*args, &optional_filter_block) _verify_match_result(args, optional_filter_block) do |result| raise Capybara::ExpectationNotMet, 'Item does not match the provided selector' unless result.include? self end end
def assert_no_selector(*args, &optional_filter_block)
-
(Capybara::ExpectationNotMet)- If the selector exists
Parameters:
-
() --
def assert_no_selector(*args, &optional_filter_block) _verify_selector_result(args, optional_filter_block) do |result, query| if result.matches_count? && (!result.empty? || query.expects_none?) raise Capybara::ExpectationNotMet, result.negative_failure_message end end end
def assert_no_text(*args)
-
(true)-
Raises:
-
(Capybara::ExpectationNotMet)- if the assertion hasn't succeeded during wait time
def assert_no_text(*args) _verify_text(args) do |count, query| if query.matches_count?(count) && (count.positive? || query.expects_none?) raise Capybara::ExpectationNotMet, query.negative_failure_message end end end
def assert_none_of_selectors(*args, wait: nil, **options, &optional_filter_block)
-
assert_none_of_selectors([kind = Capybara.default_selector], *locators, **options)
def assert_none_of_selectors(*args, wait: nil, **options, &optional_filter_block) wait = session_options.default_max_wait_time if wait.nil? selector = extract_selector(args) synchronize(wait) do args.each do |locator| assert_no_selector(selector, locator, options, &optional_filter_block) end end end
def assert_not_matches_selector(*args, &optional_filter_block)
def assert_not_matches_selector(*args, &optional_filter_block) _verify_match_result(args, optional_filter_block) do |result| raise Capybara::ExpectationNotMet, 'Item matched the provided selector' if result.include? self end end
def assert_selector(*args, &optional_filter_block)
-
(Capybara::ExpectationNotMet)- If the selector does not exist
Options Hash:
(**options)-
:count(Integer) -- Number of times the expression should occur
Parameters:
-
() --
def assert_selector(*args, &optional_filter_block) _verify_selector_result(args, optional_filter_block) do |result, query| unless result.matches_count? && (result.any? || query.expects_none?) raise Capybara::ExpectationNotMet, result.failure_message end end end
def assert_style(styles, **options)
-
(Capybara::ExpectationNotMet)- If the element doesn't have the specified styles
Parameters:
-
styles(Hash) --
def assert_style(styles, **options) query_args = _set_query_session_options(styles, options) query = Capybara::Queries::StyleQuery.new(*query_args) synchronize(query.wait) do raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) end true end
def assert_text(*args)
-
(true)-
Raises:
-
(Capybara::ExpectationNotMet)- if the assertion hasn't succeeded during wait time
Options Hash:
(**options)-
:normalize_ws(Boolean) -- When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space -
:exact(Boolean) -- Whether text must be an exact match or just substring -
:wait(Numeric) -- Maximum time that Capybara will wait for text to eq/match given string/regexp argument -
:between(Range) -- Range of times that is expected to contain number of times text occurs -
:maximum(Integer) -- Maximum number of times the text is expected to occur -
:minimum(Integer) -- Minimum number of times the text is expected to occur -
:count(Integer) -- Number of times the text is expected to occur -
:normalize_ws(Boolean) -- When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space -
:exact(Boolean) -- Whether text must be an exact match or just substring -
:wait(Numeric) -- Maximum time that Capybara will wait for text to eq/match given string/regexp argument -
:between(Range) -- Range of times that is expected to contain number of times text occurs -
:maximum(Integer) -- Maximum number of times the text is expected to occur -
:minimum(Integer) -- Minimum number of times the text is expected to occur -
:count(Integer) -- Number of times the text is expected to occur
Parameters:
-
text(String, Regexp) -- The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it. -
text(String, Regexp) -- The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it. -
type(:all, :visible) -- Whether to check for only visible or all text. If this parameter is missing or nil then we use the value of `Capybara.ignore_hidden_elements`, which defaults to `true`, corresponding to `:visible`.
Overloads:
-
assert_text(text, **options) -
assert_text(type, text, **options)
def assert_text(*args) _verify_text(args) do |count, query| unless query.matches_count?(count) && (count.positive? || query.expects_none?) raise Capybara::ExpectationNotMet, query.failure_message end end end
def extract_selector(args)
def extract_selector(args) args.first.is_a?(Symbol) ? args.shift : session_options.default_selector end
def has_button?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exists
Parameters:
-
locator(String) -- The text, value or id of a button to check for
def has_button?(locator = nil, **options, &optional_filter_block) has_selector?(:button, locator, options, &optional_filter_block) end
def has_checked_field?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exists
Parameters:
-
locator(String) -- The label, name or id of a checked field
def has_checked_field?(locator = nil, **options, &optional_filter_block) has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block) end
def has_css?(path, **options, &optional_filter_block)
-
(Boolean)- If the selector exists
Options Hash:
(**options)-
:count(Integer) -- Number of times the selector should occur
Parameters:
-
options() -- -
path(String) -- A CSS selector
def has_css?(path, **options, &optional_filter_block) has_selector?(:css, path, options, &optional_filter_block) end
def has_field?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exists
Options Hash:
(**options)-
:type(String) -- The type attribute of the field -
:with(String, Regexp) -- The text content of the field or a Regexp to match
Parameters:
-
locator(String) -- The label, name or id of a field to check for
def has_field?(locator = nil, **options, &optional_filter_block) has_selector?(:field, locator, options, &optional_filter_block) end
def has_link?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exists
Options Hash:
(**options)-
:href(String, Regexp) -- The value the href attribute must be
Parameters:
-
options() -- -
locator(String) -- The text or id of a link to check for
def has_link?(locator = nil, **options, &optional_filter_block) has_selector?(:link, locator, options, &optional_filter_block) end
def has_no_button?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Parameters:
-
locator(String) -- The text, value or id of a button to check for
def has_no_button?(locator = nil, **options, &optional_filter_block) has_no_selector?(:button, locator, options, &optional_filter_block) end
def has_no_checked_field?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Parameters:
-
locator(String) -- The label, name or id of a checked field
def has_no_checked_field?(locator = nil, **options, &optional_filter_block) has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block) end
def has_no_css?(path, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
() --
def has_no_css?(path, **options, &optional_filter_block) has_no_selector?(:css, path, options, &optional_filter_block) end
def has_no_field?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Options Hash:
(**options)-
:type(String) -- The type attribute of the field -
:with(String, Regexp) -- The text content of the field or a Regexp to match
Parameters:
-
locator(String) -- The label, name or id of a field to check for
def has_no_field?(locator = nil, **options, &optional_filter_block) has_no_selector?(:field, locator, options, &optional_filter_block) end
def has_no_link?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Parameters:
-
() --
def has_no_link?(locator = nil, **options, &optional_filter_block) has_no_selector?(:link, locator, options, &optional_filter_block) end
def has_no_select?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Parameters:
-
() --
def has_no_select?(locator = nil, **options, &optional_filter_block) has_no_selector?(:select, locator, options, &optional_filter_block) end
def has_no_selector?(*args, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
() --
def has_no_selector?(*args, **options, &optional_filter_block) make_predicate(options) { assert_no_selector(*args, options, &optional_filter_block) } end
def has_no_table?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Parameters:
-
() --
def has_no_table?(locator = nil, **options, &optional_filter_block) has_no_selector?(:table, locator, options, &optional_filter_block) end
def has_no_text?(*args, **options)
-
(Boolean)- Whether it doesn't exist
def has_no_text?(*args, **options) make_predicate(options) { assert_no_text(*args, options) } end
def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it doesn't exist
Parameters:
-
locator(String) -- The label, name or id of an unchecked field
def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block) has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block) end
def has_no_xpath?(path, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
() --
def has_no_xpath?(path, **options, &optional_filter_block) has_no_selector?(:xpath, path, options, &optional_filter_block) end
def has_select?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exists
Options Hash:
(**options)-
:with_selected(String, Array) -- Partial set of options which should minimally be selected -
:selected(String, Array) -- Options which should be selected -
:with_options(Array) -- Partial set of options which should be contained in this select box -
:options(Array) -- Options which should be contained in this select box
Parameters:
-
locator(String) -- The label, name or id of a select box
def has_select?(locator = nil, **options, &optional_filter_block) has_selector?(:select, locator, options, &optional_filter_block) end
def has_selector?(*args, **options, &optional_filter_block)
-
(Boolean)- If the expression exists
Options Hash:
(**args)-
:between(Range) -- Range of times that should contain number of times text occurs -
:maximum(Integer) -- Maximum number of times the text should occur -
:minimum(Integer) -- Minimum number of times the text should occur -
:count(Integer) -- Number of times the text should occur
Parameters:
-
args() -- -
() --
def has_selector?(*args, **options, &optional_filter_block) make_predicate(options) { assert_selector(*args, options, &optional_filter_block) } end
def has_style?(styles, **options)
-
(Boolean)- If the styles match
Parameters:
-
styles(Hash) --
def has_style?(styles, **options) make_predicate(options) { assert_style(styles, options) } end
def has_table?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exist
Parameters:
-
locator(String) -- The id or caption of a table
def has_table?(locator = nil, **options, &optional_filter_block) has_selector?(:table, locator, options, &optional_filter_block) end
def has_text?(*args, **options)
-
(Boolean)- Whether it exists
def has_text?(*args, **options) make_predicate(options) { assert_text(*args, options) } end
def has_unchecked_field?(locator = nil, **options, &optional_filter_block)
-
(Boolean)- Whether it exists
Parameters:
-
locator(String) -- The label, name or id of an unchecked field
def has_unchecked_field?(locator = nil, **options, &optional_filter_block) has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block) end
def has_xpath?(path, **options, &optional_filter_block)
-
(Boolean)- If the expression exists
Options Hash:
(**options)-
:count(Integer) -- Number of times the expression should occur
Parameters:
-
options() -- -
path(String) -- An XPath expression
def has_xpath?(path, **options, &optional_filter_block) has_selector?(:xpath, path, options, &optional_filter_block) end
def make_predicate(options)
def make_predicate(options) options[:wait] = 0 unless options.key?(:wait) || session_options.predicates_wait yield rescue Capybara::ExpectationNotMet false end
def matches_css?(css, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
css(String) -- The CSS selector to match against the current code
def matches_css?(css, **options, &optional_filter_block) matches_selector?(:css, css, options, &optional_filter_block) end
def matches_selector?(*args, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
() --
def matches_selector?(*args, **options, &optional_filter_block) make_predicate(options) { assert_matches_selector(*args, options, &optional_filter_block) } end
def matches_xpath?(xpath, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
xpath(String, XPath::Expression) -- The XPath expression to match against the current code
def matches_xpath?(xpath, **options, &optional_filter_block) matches_selector?(:xpath, xpath, options, &optional_filter_block) end
def not_matches_css?(css, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
css(String) -- The CSS selector to match against the current code
def not_matches_css?(css, **options, &optional_filter_block) not_matches_selector?(:css, css, options, &optional_filter_block) end
def not_matches_selector?(*args, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
() --
def not_matches_selector?(*args, **options, &optional_filter_block) make_predicate(options) { assert_not_matches_selector(*args, options, &optional_filter_block) } end
def not_matches_xpath?(xpath, **options, &optional_filter_block)
-
(Boolean)-
Parameters:
-
xpath(String, XPath::Expression) -- The XPath expression to match against the current code
def not_matches_xpath?(xpath, **options, &optional_filter_block) not_matches_selector?(:xpath, xpath, options, &optional_filter_block) end
def refute_matches_selector(*args, &optional_filter_block)
Deprecated
def refute_matches_selector(*args, &optional_filter_block) warn '`refute_matches_selector` was never meant to be in this scope unless ' \ 'using minitest. Either replace with `assert_not_matches_selector` ' \ "or require 'capybara/minitest'." assert_not_matches_selector(*args, &optional_filter_block) end
def refute_selector(*args, &optional_filter_block)
Deprecated
def refute_selector(*args, &optional_filter_block) warn '`refute_selector` was never meant to be in this scope unless ' \ 'using minitest. Either replace with `assert_no_selector` ' \ "or require 'capybara/minitest'." assert_no_selector(*args, &optional_filter_block) end