How to use make_predicate method of Capybara.Node.Matchers Package

Best Capybara code snippet using Capybara.Node.Matchers.make_predicate

matchers.rb

Source:matchers.rb Github

copy

Full Screen

...35 # @option args [Range] :between (nil) Range of times that should contain number of times text occurs36 # @return [Boolean] If the expression exists37 #38 def has_selector?(*args, **options, &optional_filter_block)39 make_predicate(options) { assert_selector(*args, options, &optional_filter_block) }40 end41 ##42 #43 # Checks if a given selector is not on the page or a descendant of the current node.44 # Usage is identical to Capybara::Node::Matchers#has_selector?45 #46 # @param (see Capybara::Node::Finders#has_selector?)47 # @return [Boolean]48 #49 def has_no_selector?(*args, **options, &optional_filter_block)50 make_predicate(options) { assert_no_selector(*args, options, &optional_filter_block) }51 end52 ##53 #54 # Checks if a an element has the specified CSS styles55 #56 # element.has_style?( 'color' => 'rgb(0,0,255)', 'font-size' => /px/ )57 #58 # @param styles [Hash]59 # @return [Boolean] If the styles match60 #61 def has_style?(styles, **options)62 make_predicate(options) { assert_style(styles, options) }63 end64 ##65 #66 # Asserts that a given selector is on the page or a descendant of the current node.67 #68 # page.assert_selector('p#foo')69 # page.assert_selector(:xpath, './/p[@id="foo"]')70 # page.assert_selector(:foo)71 #72 # By default it will check if the expression occurs at least once,73 # but a different number can be specified.74 #75 # page.assert_selector('p#foo', count: 4)76 #77 # This will check if the expression occurs exactly 4 times. See78 # {Capybara::Node::Finders#all} for other available result size options.79 #80 # If a :count of 0 is specified, it will behave like {#assert_no_selector};81 # however, use of that method is preferred over this one.82 #83 # It also accepts all options that {Capybara::Node::Finders#all} accepts,84 # such as :text and :visible.85 #86 # page.assert_selector('li', text: 'Horse', visible: true)87 #88 # `assert_selector` can also accept XPath expressions generated by the89 # XPath gem:90 #91 # page.assert_selector(:xpath, XPath.descendant(:p))92 #93 # @param (see Capybara::Node::Finders#all)94 # @option options [Integer] :count (nil) Number of times the expression should occur95 # @raise [Capybara::ExpectationNotMet] If the selector does not exist96 #97 def assert_selector(*args, &optional_filter_block)98 _verify_selector_result(args, optional_filter_block) do |result, query|99 raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count? && (result.any? || query.expects_none?)100 end101 end102 ##103 #104 # Asserts that an element has the specified CSS styles105 #106 # element.assert_style( 'color' => 'rgb(0,0,255)', 'font-size' => /px/ )107 #108 # @param styles [Hash]109 # @raise [Capybara::ExpectationNotMet] If the element doesn't have the specified styles110 #111 def assert_style(styles, **options)112 query_args = _set_query_session_options(styles, options)113 query = Capybara::Queries::StyleQuery.new(*query_args)114 synchronize(query.wait) do115 raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self)116 end117 true118 end119 # Asserts that all of the provided selectors are present on the given page120 # or descendants of the current node. If options are provided, the assertion121 # will check that each locator is present with those options as well (other than :wait).122 #123 # page.assert_all_of_selectors(:custom, 'Tom', 'Joe', visible: all)124 # page.assert_all_of_selectors(:css, '#my_div', 'a.not_clicked')125 #126 # It accepts all options that {Capybara::Node::Finders#all} accepts,127 # such as :text and :visible.128 #129 # The :wait option applies to all of the selectors as a group, so all of the locators must be present130 # within :wait (Defaults to Capybara.default_max_wait_time) seconds.131 #132 # @overload assert_all_of_selectors([kind = Capybara.default_selector], *locators, **options)133 #134 def assert_all_of_selectors(*args, **options, &optional_filter_block)135 _verify_multiple(*args, options) do |selector, locator, opts|136 assert_selector(selector, locator, opts, &optional_filter_block)137 end138 end139 # Asserts that none of the provided selectors are present on the given page140 # or descendants of the current node. If options are provided, the assertion141 # will check that each locator is present with those options as well (other than :wait).142 #143 # page.assert_none_of_selectors(:custom, 'Tom', 'Joe', visible: all)144 # page.assert_none_of_selectors(:css, '#my_div', 'a.not_clicked')145 #146 # It accepts all options that {Capybara::Node::Finders#all} accepts,147 # such as :text and :visible.148 #149 # The :wait option applies to all of the selectors as a group, so none of the locators must be present150 # within :wait (Defaults to Capybara.default_max_wait_time) seconds.151 #152 # @overload assert_none_of_selectors([kind = Capybara.default_selector], *locators, **options)153 #154 def assert_none_of_selectors(*args, **options, &optional_filter_block)155 _verify_multiple(*args, options) do |selector, locator, opts|156 assert_no_selector(selector, locator, opts, &optional_filter_block)157 end158 end159 # Asserts that any of the provided selectors are present on the given page160 # or descendants of the current node. If options are provided, the assertion161 # will check that each locator is present with those options as well (other than :wait).162 #163 # page.assert_any_of_selectors(:custom, 'Tom', 'Joe', visible: all)164 # page.assert_any_of_selectors(:css, '#my_div', 'a.not_clicked')165 #166 # It accepts all options that {Capybara::Node::Finders#all} accepts,167 # such as :text and :visible.168 #169 # The :wait option applies to all of the selectors as a group, so any of the locators must be present170 # within :wait (Defaults to Capybara.default_max_wait_time) seconds.171 #172 # @overload assert_any_of_selectors([kind = Capybara.default_selector], *locators, **options)173 #174 def assert_any_of_selectors(*args, wait: nil, **options, &optional_filter_block)175 wait = session_options.default_max_wait_time if wait.nil?176 selector = extract_selector(args)177 synchronize(wait) do178 res = args.map do |locator|179 begin180 assert_selector(selector, locator, options, &optional_filter_block)181 break nil182 rescue Capybara::ExpectationNotMet => e183 e.message184 end185 end186 raise Capybara::ExpectationNotMet, res.join(' or ') if res187 true188 end189 end190 ##191 #192 # Asserts that a given selector is not on the page or a descendant of the current node.193 # Usage is identical to Capybara::Node::Matchers#assert_selector194 #195 # Query options such as :count, :minimum, :maximum, and :between are196 # considered to be an integral part of the selector. This will return197 # true, for example, if a page contains 4 anchors but the query expects 5:198 #199 # page.assert_no_selector('a', minimum: 1) # Found, raises Capybara::ExpectationNotMet200 # page.assert_no_selector('a', count: 4) # Found, raises Capybara::ExpectationNotMet201 # page.assert_no_selector('a', count: 5) # Not Found, returns true202 #203 # @param (see Capybara::Node::Finders#assert_selector)204 # @raise [Capybara::ExpectationNotMet] If the selector exists205 #206 def assert_no_selector(*args, &optional_filter_block)207 _verify_selector_result(args, optional_filter_block) do |result, query|208 if result.matches_count? && (!result.empty? || query.expects_none?)209 raise Capybara::ExpectationNotMet, result.negative_failure_message210 end211 end212 end213 ##214 #215 # Checks if a given XPath expression is on the page or a descendant of the current node.216 #217 # page.has_xpath?('.//p[@id="foo"]')218 #219 # By default it will check if the expression occurs at least once,220 # but a different number can be specified.221 #222 # page.has_xpath?('.//p[@id="foo"]', count: 4)223 #224 # This will check if the expression occurs exactly 4 times.225 #226 # It also accepts all options that {Capybara::Node::Finders#all} accepts,227 # such as :text and :visible.228 #229 # page.has_xpath?('.//li', text: 'Horse', visible: true)230 #231 # has_xpath? can also accept XPath expressions generate by the232 # XPath gem:233 #234 # xpath = XPath.generate { |x| x.descendant(:p) }235 # page.has_xpath?(xpath)236 #237 # @param [String] path An XPath expression238 # @param options (see Capybara::Node::Finders#all)239 # @option options [Integer] :count (nil) Number of times the expression should occur240 # @return [Boolean] If the expression exists241 #242 def has_xpath?(path, **options, &optional_filter_block)243 has_selector?(:xpath, path, options, &optional_filter_block)244 end245 ##246 #247 # Checks if a given XPath expression is not on the page or a descendant of the current node.248 # Usage is identical to Capybara::Node::Matchers#has_xpath?249 #250 # @param (see Capybara::Node::Finders#has_xpath?)251 # @return [Boolean]252 #253 def has_no_xpath?(path, **options, &optional_filter_block)254 has_no_selector?(:xpath, path, options, &optional_filter_block)255 end256 ##257 #258 # Checks if a given CSS selector is on the page or a descendant of the current node.259 #260 # page.has_css?('p#foo')261 #262 # By default it will check if the selector occurs at least once,263 # but a different number can be specified.264 #265 # page.has_css?('p#foo', count: 4)266 #267 # This will check if the selector occurs exactly 4 times.268 #269 # It also accepts all options that {Capybara::Node::Finders#all} accepts,270 # such as :text and :visible.271 #272 # page.has_css?('li', text: 'Horse', visible: true)273 #274 # @param [String] path A CSS selector275 # @param options (see Capybara::Node::Finders#all)276 # @option options [Integer] :count (nil) Number of times the selector should occur277 # @return [Boolean] If the selector exists278 #279 def has_css?(path, **options, &optional_filter_block)280 has_selector?(:css, path, options, &optional_filter_block)281 end282 ##283 #284 # Checks if a given CSS selector is not on the page or a descendant of the current node.285 # Usage is identical to Capybara::Node::Matchers#has_css?286 #287 # @param (see Capybara::Node::Finders#has_css?)288 # @return [Boolean]289 #290 def has_no_css?(path, **options, &optional_filter_block)291 has_no_selector?(:css, path, options, &optional_filter_block)292 end293 ##294 #295 # Checks if the page or current node has a link with the given296 # text or id.297 #298 # @param [String] locator The text or id of a link to check for299 # @param options300 # @option options [String, Regexp] :href The value the href attribute must be301 # @return [Boolean] Whether it exists302 #303 def has_link?(locator = nil, **options, &optional_filter_block)304 has_selector?(:link, locator, options, &optional_filter_block)305 end306 ##307 #308 # Checks if the page or current node has no link with the given309 # text or id.310 #311 # @param (see Capybara::Node::Finders#has_link?)312 # @return [Boolean] Whether it doesn't exist313 #314 def has_no_link?(locator = nil, **options, &optional_filter_block)315 has_no_selector?(:link, locator, options, &optional_filter_block)316 end317 ##318 #319 # Checks if the page or current node has a button with the given320 # text, value or id.321 #322 # @param [String] locator The text, value or id of a button to check for323 # @return [Boolean] Whether it exists324 #325 def has_button?(locator = nil, **options, &optional_filter_block)326 has_selector?(:button, locator, options, &optional_filter_block)327 end328 ##329 #330 # Checks if the page or current node has no button with the given331 # text, value or id.332 #333 # @param [String] locator The text, value or id of a button to check for334 # @return [Boolean] Whether it doesn't exist335 #336 def has_no_button?(locator = nil, **options, &optional_filter_block)337 has_no_selector?(:button, locator, options, &optional_filter_block)338 end339 ##340 #341 # Checks if the page or current node has a form field with the given342 # label, name or id.343 #344 # For text fields and other textual fields, such as textareas and345 # HTML5 email/url/etc. fields, it's possible to specify a :with346 # option to specify the text the field should contain:347 #348 # page.has_field?('Name', with: 'Jonas')349 #350 # It is also possible to filter by the field type attribute:351 #352 # page.has_field?('Email', type: 'email')353 #354 # Note: 'textarea' and 'select' are valid type values, matching the associated tag names.355 #356 # @param [String] locator The label, name or id of a field to check for357 # @option options [String, Regexp] :with The text content of the field or a Regexp to match358 # @option options [String] :type The type attribute of the field359 # @return [Boolean] Whether it exists360 #361 def has_field?(locator = nil, **options, &optional_filter_block)362 has_selector?(:field, locator, options, &optional_filter_block)363 end364 ##365 #366 # Checks if the page or current node has no form field with the given367 # label, name or id. See {Capybara::Node::Matchers#has_field?}.368 #369 # @param [String] locator The label, name or id of a field to check for370 # @option options [String, Regexp] :with The text content of the field or a Regexp to match371 # @option options [String] :type The type attribute of the field372 # @return [Boolean] Whether it doesn't exist373 #374 def has_no_field?(locator = nil, **options, &optional_filter_block)375 has_no_selector?(:field, locator, options, &optional_filter_block)376 end377 ##378 #379 # Checks if the page or current node has a radio button or380 # checkbox with the given label, value, id, or Capybara.test_id attribute that is currently381 # checked.382 #383 # @param [String] locator The label, name or id of a checked field384 # @return [Boolean] Whether it exists385 #386 def has_checked_field?(locator = nil, **options, &optional_filter_block)387 has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)388 end389 ##390 #391 # Checks if the page or current node has no radio button or392 # checkbox with the given label, value or id, or Capybara.test_id attribute that is currently393 # checked.394 #395 # @param [String] locator The label, name or id of a checked field396 # @return [Boolean] Whether it doesn't exist397 #398 def has_no_checked_field?(locator = nil, **options, &optional_filter_block)399 has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)400 end401 ##402 #403 # Checks if the page or current node has a radio button or404 # checkbox with the given label, value or id, or Capybara.test_id attribute that is currently405 # unchecked.406 #407 # @param [String] locator The label, name or id of an unchecked field408 # @return [Boolean] Whether it exists409 #410 def has_unchecked_field?(locator = nil, **options, &optional_filter_block)411 has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)412 end413 ##414 #415 # Checks if the page or current node has no radio button or416 # checkbox with the given label, value or id, or Capybara.test_id attribute that is currently417 # unchecked.418 #419 # @param [String] locator The label, name or id of an unchecked field420 # @return [Boolean] Whether it doesn't exist421 #422 def has_no_unchecked_field?(locator = nil, **options, &optional_filter_block)423 has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)424 end425 ##426 #427 # Checks if the page or current node has a select field with the428 # given label, name or id.429 #430 # It can be specified which option should currently be selected:431 #432 # page.has_select?('Language', selected: 'German')433 #434 # For multiple select boxes, several options may be specified:435 #436 # page.has_select?('Language', selected: ['English', 'German'])437 #438 # It's also possible to check if the exact set of options exists for439 # this select box:440 #441 # page.has_select?('Language', options: ['English', 'German', 'Spanish'])442 #443 # You can also check for a partial set of options:444 #445 # page.has_select?('Language', with_options: ['English', 'German'])446 #447 # @param [String] locator The label, name or id of a select box448 # @option options [Array] :options Options which should be contained in this select box449 # @option options [Array] :with_options Partial set of options which should be contained in this select box450 # @option options [String, Array] :selected Options which should be selected451 # @option options [String, Array] :with_selected Partial set of options which should minimally be selected452 # @return [Boolean] Whether it exists453 #454 def has_select?(locator = nil, **options, &optional_filter_block)455 has_selector?(:select, locator, options, &optional_filter_block)456 end457 ##458 #459 # Checks if the page or current node has no select field with the460 # given label, name or id. See {Capybara::Node::Matchers#has_select?}.461 #462 # @param (see Capybara::Node::Matchers#has_select?)463 # @return [Boolean] Whether it doesn't exist464 #465 def has_no_select?(locator = nil, **options, &optional_filter_block)466 has_no_selector?(:select, locator, options, &optional_filter_block)467 end468 ##469 #470 # Checks if the page or current node has a table with the given id471 # or caption:472 #473 # page.has_table?('People')474 #475 # @param [String] locator The id or caption of a table476 # @return [Boolean] Whether it exist477 #478 def has_table?(locator = nil, **options, &optional_filter_block)479 has_selector?(:table, locator, options, &optional_filter_block)480 end481 ##482 #483 # Checks if the page or current node has no table with the given id484 # or caption. See {Capybara::Node::Matchers#has_table?}.485 #486 # @param (see Capybara::Node::Matchers#has_table?)487 # @return [Boolean] Whether it doesn't exist488 #489 def has_no_table?(locator = nil, **options, &optional_filter_block)490 has_no_selector?(:table, locator, options, &optional_filter_block)491 end492 ##493 #494 # Asserts that the current_node matches a given selector495 #496 # node.assert_matches_selector('p#foo')497 # node.assert_matches_selector(:xpath, '//p[@id="foo"]')498 # node.assert_matches_selector(:foo)499 #500 # It also accepts all options that {Capybara::Node::Finders#all} accepts,501 # such as :text and :visible.502 #503 # node.assert_matches_selector('li', text: 'Horse', visible: true)504 #505 # @param (see Capybara::Node::Finders#all)506 # @raise [Capybara::ExpectationNotMet] If the selector does not match507 #508 def assert_matches_selector(*args, &optional_filter_block)509 _verify_match_result(args, optional_filter_block) do |result|510 raise Capybara::ExpectationNotMet, 'Item does not match the provided selector' unless result.include? self511 end512 end513 def assert_not_matches_selector(*args, &optional_filter_block)514 _verify_match_result(args, optional_filter_block) do |result|515 raise Capybara::ExpectationNotMet, 'Item matched the provided selector' if result.include? self516 end517 end518 ##519 #520 # Checks if the current node matches given selector521 #522 # @param (see Capybara::Node::Finders#has_selector?)523 # @return [Boolean]524 #525 def matches_selector?(*args, **options, &optional_filter_block)526 make_predicate(options) { assert_matches_selector(*args, options, &optional_filter_block) }527 end528 ##529 #530 # Checks if the current node matches given XPath expression531 #532 # @param [String, XPath::Expression] xpath The XPath expression to match against the current code533 # @return [Boolean]534 #535 def matches_xpath?(xpath, **options, &optional_filter_block)536 matches_selector?(:xpath, xpath, options, &optional_filter_block)537 end538 ##539 #540 # Checks if the current node matches given CSS selector541 #542 # @param [String] css The CSS selector to match against the current code543 # @return [Boolean]544 #545 def matches_css?(css, **options, &optional_filter_block)546 matches_selector?(:css, css, options, &optional_filter_block)547 end548 ##549 #550 # Checks if the current node does not match given selector551 # Usage is identical to Capybara::Node::Matchers#has_selector?552 #553 # @param (see Capybara::Node::Finders#has_selector?)554 # @return [Boolean]555 #556 def not_matches_selector?(*args, **options, &optional_filter_block)557 make_predicate(options) { assert_not_matches_selector(*args, options, &optional_filter_block) }558 end559 ##560 #561 # Checks if the current node does not match given XPath expression562 #563 # @param [String, XPath::Expression] xpath The XPath expression to match against the current code564 # @return [Boolean]565 #566 def not_matches_xpath?(xpath, **options, &optional_filter_block)567 not_matches_selector?(:xpath, xpath, options, &optional_filter_block)568 end569 ##570 #571 # Checks if the current node does not match given CSS selector572 #573 # @param [String] css The CSS selector to match against the current code574 # @return [Boolean]575 #576 def not_matches_css?(css, **options, &optional_filter_block)577 not_matches_selector?(:css, css, options, &optional_filter_block)578 end579 ##580 # Asserts that the page or current node has the given text content,581 # ignoring any HTML tags.582 #583 # @!macro text_query_params584 # @overload $0(type, text, **options)585 # @param [:all, :visible] type 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`.586 # @param [String, Regexp] text 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.587 # @option options [Integer] :count (nil) Number of times the text is expected to occur588 # @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur589 # @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur590 # @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs591 # @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for text to eq/match given string/regexp argument592 # @option options [Boolean] :exact (Capybara.exact_text) Whether text must be an exact match or just substring593 # @option options [Boolean] :normalize_ws (false) When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space594 # @overload $0(text, **options)595 # @param [String, Regexp] text 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.596 # @option options [Integer] :count (nil) Number of times the text is expected to occur597 # @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur598 # @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur599 # @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs600 # @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for text to eq/match given string/regexp argument601 # @option options [Boolean] :exact (Capybara.exact_text) Whether text must be an exact match or just substring602 # @option options [Boolean] :normalize_ws (false) When true replace all whitespace with standard spaces and collapse consecutive whitespace to a single space603 # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time604 # @return [true]605 #606 def assert_text(*args)607 _verify_text(args) do |count, query|608 unless query.matches_count?(count) && (count.positive? || query.expects_none?)609 raise Capybara::ExpectationNotMet, query.failure_message610 end611 end612 end613 ##614 # Asserts that the page or current node doesn't have the given text content,615 # ignoring any HTML tags.616 #617 # @macro text_query_params618 # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time619 # @return [true]620 #621 def assert_no_text(*args)622 _verify_text(args) do |count, query|623 if query.matches_count?(count) && (count.positive? || query.expects_none?)624 raise Capybara::ExpectationNotMet, query.negative_failure_message625 end626 end627 end628 ##629 # Checks if the page or current node has the given text content,630 # ignoring any HTML tags.631 #632 # By default it will check if the text occurs at least once,633 # but a different number can be specified.634 #635 # page.has_text?('lorem ipsum', between: 2..4)636 #637 # This will check if the text occurs from 2 to 4 times.638 #639 # @macro text_query_params640 # @return [Boolean] Whether it exists641 #642 def has_text?(*args, **options)643 make_predicate(options) { assert_text(*args, options) }644 end645 alias_method :has_content?, :has_text?646 ##647 # Checks if the page or current node does not have the given text648 # content, ignoring any HTML tags and normalizing whitespace.649 #650 # @macro text_query_params651 # @return [Boolean] Whether it doesn't exist652 #653 def has_no_text?(*args, **options)654 make_predicate(options) { assert_no_text(*args, options) }655 end656 alias_method :has_no_content?, :has_no_text?657 def ==(other)658 eql?(other) || (other.respond_to?(:base) && base == other.base)659 end660 private661 def extract_selector(args)662 args.first.is_a?(Symbol) ? args.shift : session_options.default_selector663 end664 def _verify_multiple(*args, wait: nil, **options)665 wait = session_options.default_max_wait_time if wait.nil?666 selector = extract_selector(args)667 synchronize(wait) do668 args.each { |locator| yield(selector, locator, options) }669 end670 end671 def _verify_selector_result(query_args, optional_filter_block)672 query_args = _set_query_session_options(*query_args)673 query = Capybara::Queries::SelectorQuery.new(*query_args, &optional_filter_block)674 synchronize(query.wait) do675 yield query.resolve_for(self), query676 end677 true678 end679 def _verify_match_result(query_args, optional_filter_block)680 query_args = _set_query_session_options(*query_args)681 query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)682 synchronize(query.wait) do683 yield query.resolve_for(parent || session&.document || query_scope)684 end685 true686 end687 def _verify_text(query_args)688 query_args = _set_query_session_options(*query_args)689 query = Capybara::Queries::TextQuery.new(*query_args)690 synchronize(query.wait) do691 yield query.resolve_for(self), query692 end693 true694 end695 def _set_query_session_options(*query_args, **query_options)696 query_options[:session_options] = session_options697 query_args.push(query_options)698 end699 def make_predicate(options)700 options[:wait] = 0 unless options.key?(:wait) || session_options.predicates_wait701 yield702 rescue Capybara::ExpectationNotMet703 false704 end705 end706 end707end...

Full Screen

Full Screen

document_matchers.rb

Source:document_matchers.rb Github

copy

Full Screen

...38 # @macro title_query_params39 # @return [Boolean]40 #41 def has_title?(title, **options)42 make_predicate(options) { assert_title(title, **options) }43 end44 ##45 # Checks if the page doesn't have the given title.46 #47 # @macro title_query_params48 # @return [Boolean]49 #50 def has_no_title?(title, **options)51 make_predicate(options) { assert_no_title(title, **options) }52 end53 private54 def _verify_title(title, options)55 query = Capybara::Queries::TitleQuery.new(title, **options)56 synchronize(query.wait) { yield(query) }57 true58 end59 end60 end61end...

Full Screen

Full Screen

make_predicate

Using AI Code Generation

copy

Full Screen

1 def make_predicate(name, opts={}, &block)2 define_method(name) do |*args|3 block.call(self, *args)4 block.call(self)5 def make_predicate(name, opts={}, &block)6 define_method(name) do |*args|7 block.call(self, *args)8 block.call(self)9 def make_predicate(name, opts={}, &block)10 define_method(name) do |*args|11 block.call(self, *args)12 block.call(self)

Full Screen

Full Screen

make_predicate

Using AI Code Generation

copy

Full Screen

1 def make_predicate(name, &block)2 define_method(name) do |*args, &optional_block|3 block.call(*args, &optional_block)4 make_predicate(:have_selector?) do |*args|5 has_selector?(*args)6 def make_predicate(name, &block)7 define_method(name) do |*args, &optional_block|8 block.call(*args, &optional_block)9 make_predicate(:have_selector?) do |*args|10 has_selector?(*args)11 make_predicate(:have_selector?) do |*args|12 has_selector?(*args)13 make_predicate(:have_selector?) do |*args|14 has_selector?(*args)15 make_predicate(:have_selector?) do |*args|16 has_selector?(*args)17 def make_predicate(name, &block)18 define_method(name) do |*args, &optional_block|19 block.call(*args, &optional_block)20 make_predicate(:have_selector?) do |*args|21 has_selector?(*args)22 make_predicate(:have_selector?) do |*args|23 has_selector?(*args)24 make_predicate(:have_selector?) do |*args|25 has_selector?(*args)

Full Screen

Full Screen

make_predicate

Using AI Code Generation

copy

Full Screen

1 def make_predicate(name, options = {})2 define_method(name) do |*args|3 Capybara.using_wait_time(options[:wait]) do4 assert self.send(options[:method], *args)5 assert self.send(options[:method], *args)6 def make_predicate(name, options = {})7 define_method(name) do |*args|8 Capybara.using_wait_time(options[:wait]) do9 assert self.send(options[:method], *args)10 assert self.send(options[:method], *args)11 def make_predicate(name, options = {})12 define_method(name) do |*args|

Full Screen

Full Screen

make_predicate

Using AI Code Generation

copy

Full Screen

1Capybara::Node::Matchers.make_predicate(:have_text?) do |text|2 has_content?(text)3 def has_text?(text)4 page.has_text?(text)5puts page.has_text?('Google')6Capybara::Node::Matchers.make_predicate(:have_text?) do |text|7 has_content?(text)8 def has_text?(text)9 page.has_text?(text)10puts page.has_text?('Google')11Capybara::Node::Matchers.make_predicate(:have_text?) do |text|12 has_content?(text)13 def has_text?(text)14 page.has_text?(text)15puts page.has_text?('Google')16Capybara::Node::Matchers.make_predicate(:have_text?) do |text|17 has_content?(text)18 def has_text?(text)19 page.has_text?(

Full Screen

Full Screen

make_predicate

Using AI Code Generation

copy

Full Screen

1Capybara.visit("http://www.google.com")2Capybara.make_predicate(:have_title) do3Capybara.make_predicate(:have_link) do4Capybara.make_predicate(:have_button) do5Capybara.make_predicate(:have_text) do6Capybara.make_predicate(:have_textarea) do7Capybara.make_predicate(:have_input) do8Capybara.make_predicate(:have_select) do9Capybara.make_predicate(:have_image) do10Capybara.make_predicate(:have_table) do11Capybara.make_predicate(:have_tr) do12Capybara.make_predicate(:have_td) do13Capybara.make_predicate(:have_th) do14Capybara.make_predicate(:have_li) do15Capybara.make_predicate(:have_ol) do16Capybara.make_predicate(:have_ul) do17Capybara.make_predicate(:have_div) do18Capybara.make_predicate(:have_span) do19Capybara.make_predicate(:have_p) do20Capybara.make_predicate(:have

Full Screen

Full Screen

make_predicate

Using AI Code Generation

copy

Full Screen

1Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has_title?(title) }2Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has_title?(title) }3Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has_title?(title) }4Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has_title?(title) }5Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has_title?(title) }6Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has_title?(title) }7Capybara::Node::Matchers.make_predicate(:have_title?) { |title| has

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful