Module: Panda::Core::Testing::CapybaraConfig::Helpers

Defined in:
lib/panda/core/testing/capybara_config.rb

Overview

Helper methods for system tests

Instance Method Summary collapse

Instance Method Details

#take_screenshot_on_failureObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/panda/core/testing/capybara_config.rb', line 54

def take_screenshot_on_failure
  return unless page.driver.respond_to?(:save_screenshot)

  timestamp = Time.now.strftime("%Y%m%d_%H%M%S")
  filename = "screenshot_#{timestamp}_#{example.description.parameterize}.png"
  path = Rails.root.join("tmp", "screenshots", filename)

  FileUtils.mkdir_p(File.dirname(path))
  page.driver.save_screenshot(path)

  puts "\nScreenshot saved: #{path}"
end

#wait_for_ajaxObject



37
38
39
40
41
42
43
# File 'lib/panda/core/testing/capybara_config.rb', line 37

def wait_for_ajax
  Timeout.timeout(Capybara.default_max_wait_time) do
    loop until page.evaluate_script("jQuery.active").zero?
  end
rescue Timeout::Error
  # Ajax didn't finish, but continue anyway
end

#wait_for_turboObject



45
46
47
48
49
50
51
52
# File 'lib/panda/core/testing/capybara_config.rb', line 45

def wait_for_turbo
  has_css?("html", wait: 0.1)
  return unless page.evaluate_script("typeof Turbo !== 'undefined'")

  page.evaluate_script("Turbo.session.drive = false")
  yield if block_given?
  page.evaluate_script("Turbo.session.drive = true")
end