module NdrDevSupport::IntegrationTesting::DSL::SessionExtensions

Adds variant of Capybara’s within_window method, that doesn’t return to the preview window on an exception. This allows us to screenshot a popup automatically if a test errors/fails whilst it has focus.

Public Instance Methods

within_screenshot_compatible_window(window_or_proc) { || ... } click to toggle source
# File lib/ndr_dev_support/integration_testing/dsl.rb, line 55
def within_screenshot_compatible_window(window_or_proc)
  original = current_window

  case window_or_proc
  when Capybara::Window
    switch_to_window(window_or_proc) unless original == window_or_proc
  when Proc
    switch_to_window { window_or_proc.call }
  else
    raise ArgumentError, 'Unsupported window type!'
  end

  scopes << nil
  yield
  @scopes.pop
  switch_to_window(original)
end