Module: Capybara::Lockstep

Extended by:
Configuration, Logging, PageAccess
Defined in:
lib/capybara-lockstep.rb,
lib/capybara-lockstep/util.rb,
lib/capybara-lockstep/client.rb,
lib/capybara-lockstep/errors.rb,
lib/capybara-lockstep/helper.rb,
lib/capybara-lockstep/server.rb,
lib/capybara-lockstep/logging.rb,
lib/capybara-lockstep/version.rb,
lib/capybara-lockstep/lockstep.rb,
lib/capybara-lockstep/middleware.rb,
lib/capybara-lockstep/page_access.rb,
lib/capybara-lockstep/capybara_ext.rb,
lib/capybara-lockstep/capybara_ext.rb,
lib/capybara-lockstep/capybara_ext.rb,
lib/capybara-lockstep/capybara_ext.rb,
lib/capybara-lockstep/configuration.rb,
lib/capybara-lockstep/client/cuprite.rb,
lib/capybara-lockstep/client/selenium.rb

Defined Under Namespace

Modules: Configuration, Helper, Logging, PageAccess, SynchronizeAroundScriptMethod, SynchronizeMacros, SynchronizeWithCatchUp, Util, VisitWithWaiting Classes: Client, DriverNotSupportedError, Error, Middleware, Server, Timeout

Constant Summary collapse

VERSION =
"2.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from PageAccess

alert_present?, page, supported_driver?

Methods included from Logging

log

Methods included from Configuration

after_synchronize, debug, debug=, debug?, enabled=, mode, mode=, timeout, timeout=, timeout_with, timeout_with=, wait_tasks, wait_tasks=, with_mode

Class Attribute Details

.synchronizingObject Also known as: synchronizing?

Returns the value of attribute synchronizing.



8
9
10
# File 'lib/capybara-lockstep/lockstep.rb', line 8

def synchronizing
  @synchronizing
end

Class Method Details

.auto_synchronize(**options) ⇒ Object

Automatic synchronization from within the capybara-lockstep should always call #auto_synchronize. This only synchronizes IFF in :auto mode, i.e. the user has not explicitly disabled automatic syncing. The :auto mode has nothing to do with the { lazy } option.



20
21
22
23
24
# File 'lib/capybara-lockstep/lockstep.rb', line 20

def auto_synchronize(**options)
  if mode == :auto
    synchronize(**options)
  end
end

.clientObject



73
74
75
76
77
78
79
80
# File 'lib/capybara-lockstep/lockstep.rb', line 73

def client
  if @client.nil? || !@client.is_a?(client_class)
    # (Re-)Initialize client if missing or the current driver changes
    @client = client_class.new
  end

  @client
end

.client_classObject



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/capybara-lockstep/lockstep.rb', line 82

def client_class
  if selenium_driver?
    Client::Selenium
  elsif cuprite_driver?
    Client::Cuprite
  else
    # This should never raise, as capybara lockstep should disable itself for any unsupported driver.
    # When it still does, there is probably a bug within capybara lockstep.
    raise DriverNotSupportedError, "The driver #{driver.class.name} is not supported by capybara-lockstep."
  end
end

.serverObject



69
70
71
# File 'lib/capybara-lockstep/lockstep.rb', line 69

def server
  @server ||= Server.new
end

.synchronize(lazy: false, log: 'Synchronizing') ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/capybara-lockstep/lockstep.rb', line 26

def synchronize(lazy: false, log: 'Synchronizing')
  if synchronizing? || mode == :off
    return
  end

  # The { lazy } option is a performance optimization that will prevent capybara-lockstep
  # from synchronizing multiple times in expressions like `page.find('.foo').find('.bar')`.
  # The { lazy } option has nothing to do with :auto mode.
  #
  # With { lazy: true } we only synchronize when the Ruby-side thinks we're out of sync.
  # This saves us an expensive execute_script() roundtrip that goes to the browser and back.
  # However the knowledge of the Ruby-side is limited: We only assume that we're out of sync
  # after a page load or after a Capybara command. There may be additional client-side work
  # that the Ruby-side is not aware of, e.g. an AJAX call scheduled by a timeout.
  #
  # With { lazy: false } we force synchronization with the browser, whether the Ruby-side
  # thinks we're in sync or not. This always makes an execute_script() rountrip, but picks up
  # non-lazy synchronization so we pick up client-side work that have not been caused
  # by Capybara commands.
  will_synchronize_client = !(lazy && client.synchronized?)

  begin
    # Synchronizing the server is free, so we ignore { lazy } and do it every time.
    server.synchronize

    if will_synchronize_client
      self.log(log)
      self.synchronizing = true
      client.synchronize
      # Synchronizing the server is free, so we ignore { lazy } and do it every time.
      server.synchronize
    end
  ensure
    self.synchronizing = false
  end

  if will_synchronize_client
    run_after_synchronize_callbacks
  end
end

.unsynchronizeObject



11
12
13
14
15
# File 'lib/capybara-lockstep/lockstep.rb', line 11

def unsynchronize
  return if mode == :off

  client.synchronized = false
end