Module: NdrDevSupport::IntegrationTesting::DSL

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 headless browser to clear its session:



8
9
10
# File 'lib/ndr_dev_support/integration_testing/dsl.rb', line 8

def clear_headless_session!
  page.driver.reset!
end

#delete_all_cookies!Object

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



14
15
16
17
18
# File 'lib/ndr_dev_support/integration_testing/dsl.rb', line 14

def delete_all_cookies!
  page.driver.cookies.each_key do |name|
    page.driver.remove_cookie(name)
  end
end

#find_new(*args, **options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ndr_dev_support/integration_testing/dsl.rb', line 32

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.



25
26
27
28
29
30
# File 'lib/ndr_dev_support/integration_testing/dsl.rb', line 25

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