Module: NdrDevSupport::IntegrationTesting::DSL

Includes:
ShowMeTheCookies
Defined in:
lib/ndr_dev_support/integration_testing/dsl.rb

Overview

Additional integration testing DSL:

Defined Under Namespace

Modules: SessionExtensions

Instance Method Summary collapse

Instance Method Details

#clear_headless_session!Object

Instruct the browser to clear its session:



11
12
13
# File 'lib/ndr_dev_support/integration_testing/dsl.rb', line 11

def clear_headless_session!
  page.driver.reset!
end

#delete_all_cookies!Object

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



17
18
19
20
21
22
23
# 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) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# 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: '#modal', remain: false) ⇒ Object

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.



30
31
32
33
34
35
# 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