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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/intransient_capybara/patches.rb', line 4
def synchronize(seconds=Capybara.default_max_wait_time, options = {})
start_time = Capybara::Helpers.monotonic_time
begin
if session.synchronized
yield
else
session.synchronized = true
begin
yield
rescue => e
session.raise_server_error!
raise e unless driver.wait?
raise e unless catch_error?(e, options[:errors])
if (Capybara::Helpers.monotonic_time - start_time) >= seconds
warn "Capybara's timeout limit reached - if your tests are green, something is wrong"
raise e
end
sleep(0.05)
raise Capybara::FrozenInTime, "time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead" if Capybara::Helpers.monotonic_time == start_time
reload if Capybara.automatic_reload
retry
ensure
session.synchronized = false
end
end
rescue Capybara::ElementNotFound => sad_day
puts 'We failed to find an element :('
puts
puts 'We are on path: ' + session.current_path
unless ENV.fetch('DEBUG_HIDE_PAGE_HTML', false) == 'true'
puts
puts 'This is the page HTML: ' + session.body
end
puts
raise sad_day
end
end
|