module NdrDevSupport::IntegrationTesting::DSL

Additional integration testing DSL:

Public Instance Methods

clear_headless_session!() click to toggle source

Instruct the browser to clear its session:

# File lib/ndr_dev_support/integration_testing/dsl.rb, line 11
def clear_headless_session!
  page.driver.reset!
end
delete_all_cookies!() click to toggle source

Get the browser to delete all of the cookies for the current page without resetting:

# File lib/ndr_dev_support/integration_testing/dsl.rb, line 17
      def delete_all_cookies!
        ActiveSupport::Deprecation.warn(<<~MSG)
          `delete_all_cookies!` is deprecated in favour of `expire_cookies`
        MSG

        expire_cookies
      end
find_new(*args, **options) { || ... } click to toggle source
# File lib/ndr_dev_support/integration_testing/dsl.rb, line 37
def find_new(*args, **options)
  # There is no point waiting to see there are no existing matches:
  pre_options = { wait: 0 }.merge(options)
  prior_matches = find_all(*args, **pre_options)

  yield

  # We expect exactly one new match as a result of the interaction:
  post_options = { count: prior_matches.length + 1 }
  current_matches = find_all(*args, **post_options)

  current_matches.without(*prior_matches).first
end
within_modal(selector: ' { || ... } click to toggle source

Wrap up interacting with modals. The assumption is that the modal should be gone one the interaction is complete (as this is a good proxy for a triggered AJAX request to have completed, and therefore a signal for capybara to wait for); if this is not the case, pass `remain: true` to signal that the modal should remain active.

# File lib/ndr_dev_support/integration_testing/dsl.rb, line 30
def within_modal(selector: '#modal', remain: false)
  within(selector) { yield }

  message = "modal was #{'not ' unless remain} expected to remain visible!"
  assert(remain ? has_selector?(selector) : has_no_selector?(selector), message)
end