Module: Capybara::Lockstep::VisitWithWaiting

Defined in:
lib/capybara-lockstep/capybara_ext.rb

Instance Method Summary collapse

Instance Method Details

#visit(*args, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/capybara-lockstep/capybara_ext.rb', line 85

def visit(*args, &block)
  url = args[0]
  # Some of our apps have a Cucumber step that changes drivers mid-scenario.
  # It works by creating a new Capybara session and re-visits the URL from the
  # previous session. If this happens before a URL is ever loaded,
  # it re-visits the URL "data:", which will never "finish" initializing.
  # Also when opening a new tab via Capybara, the initial URL is about:blank.
  visiting_real_url = !(url.start_with?('data:') || url.start_with?('about:'))

  if visiting_real_url
    # We're about to leave this screen, killing all in-flight requests.
    # Give pending form submissions etc. a chance to finish before we tear down
    # the browser environment.
    #
    # We force a non-lazy synchronization so we pick up all client-side changes
    # that have not been caused by Capybara commands.
    Lockstep.auto_synchronize(lazy: false, log: "Synchronizing before visiting #{url}")
  end

  super(*args, &block).tap do
    if visiting_real_url
      # We haven't yet synchronized the new screen.
      Lockstep.unsynchronize
    end
  end
end