Module: EvilSystems::Helpers

Includes:
ActionView::RecordIdentifier, CupriteHelpers, SessionHelpers
Defined in:
lib/evil_systems/helpers.rb

Overview

Helpers to make life easier

Instance Method Summary collapse

Methods included from SessionHelpers

#within_session

Methods included from CupriteHelpers

#debug, #pause, #wait_for_network_idle!

Instance Method Details

#absolute_image_pathString

Use our ‘Capybara.save_path` to store screenshots with other capybara artifacts (Rails screenshots path is not configurable github.com/rails/rails/blob/49baf092439fc74fc3377b12e3334c3dd9d0752f/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb#L79)

Returns:

  • (String)


13
14
15
16
17
18
# File 'lib/evil_systems/helpers.rb', line 13

def absolute_image_path
  save_path = ::Capybara.save_path.presence || Rails.root.join("tmp/screenshots/#{image_name}")
  return ::Rails.root.join("#{save_path}/screenshots/#{image_name}.png") if defined? ::Rails

  File.join("#{save_path}/screenshots/#{image_name}.png")
end

#dom_id(*args) ⇒ String

Convert dom_id to a selector.

Examples:

dom_id(Facility.first)
# => "#facility-1"

Returns:

  • (String)


41
42
43
# File 'lib/evil_systems/helpers.rb', line 41

def dom_id(*args)
  "##{super}"
end

#image_pathString

Use relative path in screenshot message to make it clickable in VS Code when running in Docker

Returns:

  • (String)


22
23
24
25
26
# File 'lib/evil_systems/helpers.rb', line 22

def image_path
  return absolute_image_path.relative_path_from(::Rails.root).to_s if defined? ::Rails

  absolute_image_path.relative_path_from(Dir.pwd)
end

#take_screenshotObject

Make failure screenshots compatible with multi-session setup

Returns:

  • void



30
31
32
33
34
# File 'lib/evil_systems/helpers.rb', line 30

def take_screenshot
  return super unless ::Capybara.respond_to?(:last_used_session) && ::Capybara.last_used_session

  ::Capybara.using_session(::Capybara.last_used_session) { super }
end