{"record":{"id":"d73d54cc80a6b440","repo":"teamcapybara/capybara","slug":"result-failure-message","errorCode":null,"errorMessage":"result.failure_message","messagePattern":"result\\.failure_message","errorType":"exception","errorClass":"Capybara::ExpectationNotMet","httpStatus":null,"severity":"error","filePath":"lib/capybara/node/finders.rb","lineNumber":267,"sourceCode":"      #   When `true` allows elements to be reloaded if they become stale. This is an advanced behavior and should only be used\n      #   if you fully understand the potential ramifications. The results can be confusing on dynamic pages. Defaults to `false`\n      # @overload all([kind = Capybara.default_selector], locator = nil, **options)\n      # @overload all([kind = Capybara.default_selector], locator = nil, **options, &filter_block)\n      #   @yieldparam element [Capybara::Node::Element]  The element being considered for inclusion in the results\n      #   @yieldreturn [Boolean]                     Should the element be considered in the results?\n      # @return [Capybara::Result]                   A collection of found elements\n      # @raise [Capybara::ExpectationNotMet]         The number of elements found doesn't match the specified conditions\n      def all(*args, allow_reload: false, **options, &optional_filter_block)\n        minimum_specified = options_include_minimum?(options)\n        options = { minimum: 1 }.merge(options) unless minimum_specified\n        options[:session_options] = session_options\n        query = Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)\n        result = nil\n        begin\n          synchronize(query.wait) do\n            result = query.resolve_for(self)\n            result.allow_reload! if allow_reload\n            raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?\n\n            result\n          end\n        rescue Capybara::ExpectationNotMet\n          raise if minimum_specified || (result.compare_count == 1)\n\n          Result.new([], nil)\n        end\n      end\n      alias_method :find_all, :all\n\n      ##\n      #\n      # Find the first element on the page matching the given selector\n      # and options. By default {#first} will wait up to {Capybara.configure default_max_wait_time}\n      # seconds for matching elements to appear and then raise an error if no matching\n      # element is found, or `nil` if the provided count options allow for empty results.\n      #","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/node/finders.rb#L249-L285","documentation":"Node::Finders#all raises Capybara::ExpectationNotMet (message built by Result#failure_message: 'expected to find <description> ... but there were no matches' or 'found N matches: ...') when the number of resolved elements does not satisfy the count options after waiting. `all` injects minimum: 1 unless you pass :count, :minimum or :between, so even finding zero plain elements can raise. It retries inside synchronize(query.wait) until the deadline before giving up.","triggerScenarios":"page.all('li', count: 3) when the list has 2 or 4 items; page.all('.item', minimum: 5) on a partially rendered list; page.all('td') inside a table that has not rendered yet within default_max_wait_time. Note the rescue in the source: when only the implicit minimum: 1 applies and too many elements were found (Result#compare_count == 1), `all` silently returns an empty Result instead of raising.","commonSituations":"Async/paged content still loading when the count is taken; wrong expectation of item count after filtering; slow CI making the built-in wait too short; mixed-content lists where some items match filters (:text, :visible) and others do not — the failure message lists 'Also found ... which matched the selector but not all filters'.","solutions":["Verify the actual count first (page.all('li').size) and align the count option with reality","Raise the wait: page.all('li', count: 3, wait: 5) or Capybara.default_max_wait_time = 5","Relax the constraint to minimum:/between: when exact count is brittle (e.g. between: 2..4)","If items are filtered out by :text/:visible, remove or correct the filter so intended items count"],"exampleFix":"# before\npage.all('li.item', count: 3)\n\n# after\npage.all('li.item', count: 3, wait: 5)\n# or tolerate async loading\npage.all('li.item', minimum: 3, wait: 5)","handlingStrategy":"retry","validationCode":"expected = 3\nfound = page.all('li.item', wait: 5).size\npage.all('li.item', count: expected) if found == expected","typeGuard":null,"tryCatchPattern":"begin\n  page.all('li.item', count: 3, wait: 5)\nrescue Capybara::ExpectationNotMet => e\n  puts \"actual: #{page.all('li.item').size} — #{e.message}\"\n  raise\nend","preventionTips":["Set default_max_wait_time to your app's realistic worst-case render time","Prefer minimum:/between: over exact count: for lists that load progressively","Assert a page-level marker first so the count query starts after content exists"],"tags":["capybara","expectation-not-met","count","finders","waiting"],"backgroundTag":"selector-count-mismatch","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}