Welcome to mirror list, hosted at ThFree Co, Russian Federation.

capybara_slow_finder.rb « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 697b288e8b5067e1c8b804f718c6601ea72fda74 (plain)
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
# frozen_string_literal: true

module Capybara
  MESSAGE = <<~MSG
    Timeout (%{timeout}s) reached while running a waiting Capybara finder.
    Consider using a non-waiting finder.

    See https://www.cloudbees.com/blog/faster-rails-tests
  MSG

  module Node
    class Base
      # Inspired by https://github.com/ngauthier/capybara-slow_finder_errors
      module SlowFinder
        def synchronize(seconds = nil, errors: nil)
          start_time = ::Gitlab::Metrics::System.monotonic_time

          super
        rescue Capybara::ElementNotFound => e
          seconds ||= Capybara.default_max_wait_time

          raise e unless seconds > 0 && ::Gitlab::Metrics::System.monotonic_time - start_time > seconds

          message = format(MESSAGE, timeout: seconds)
          raise e, "#{$!}\n\n#{message}", e.backtrace
        end
      end

      prepend SlowFinder
    end
  end
end