module Capybara::Lockstep::Configuration

Public Instance Methods

debug=(value) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 26
      def debug=(value)
        @debug = value
        if value
          target_prose = (is_logger?(value) ? 'Ruby logger' : 'STDOUT')
          log "Logging to #{target_prose} and browser console"
        end

        send_config_to_browser(<<~JS)
          CapybaraLockstep.debug = #{value.to_json}
        JS

        @debug
      end
debug?() click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 21
def debug?
  # @debug may also be a Logger object, so convert it to a boolean
  @debug.nil? ? false : !!@debug
end
enabled=(enabled) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 52
def enabled=(enabled)
  case enabled
  when true
    log "Setting `Capybara::Lockstep.enabled = true` is deprecated. Set `Capybara::Lockstep.mode = :auto` instead."
    self.mode = :auto
  when false
    log "Setting `Capybara::Lockstep.enabled = false` is deprecated. Set `Capybara::Lockstep.mode = :manual` or `Capybara::Lockstep.mode = :off` instead."
    self.mode = :manual
  when nil
    # Reset to default
    self.mode = nil
  end
end
mode() click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 40
def mode
  if javascript_driver?
    @mode.nil? ? :auto : @mode
  else
    :off
  end
end
mode=(mode) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 48
def mode=(mode)
  @mode = mode&.to_sym
end
timeout() click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 5
def timeout
  @timeout.nil? ? Capybara.default_max_wait_time : @timeout
end
timeout=(seconds) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 9
def timeout=(seconds)
  @timeout = seconds
end
timeout_with() click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 13
def timeout_with
  @timeout_with.nil? ? :log : @timeout_with
end
timeout_with=(action) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 17
def timeout_with=(action)
  @timeout_with = action&.to_sym
end
wait_tasks() click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 66
def wait_tasks
  @wait_tasks
end
wait_tasks=(value) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 70
      def wait_tasks=(value)
        @wait_tasks = value

        send_config_to_browser(<<~JS)
          CapybaraLockstep.waitTasks = #{value.to_json}
        JS

        @wait_tasks
      end

Private Instance Methods

javascript_driver?() click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 82
def javascript_driver?
  driver.is_a?(Capybara::Selenium::Driver)
end
send_config_to_browser(js) click to toggle source
# File lib/capybara-lockstep/configuration.rb, line 86
      def send_config_to_browser(js)
        begin
          with_max_wait_time(2) do
            page.execute_script(<<~JS)
              if (window.CapybaraLockstep) {
                #{js}
              }
            JS
          end
        rescue StandardError => e
          log "#{e.class.name} while configuring capybara-lockstep in browser: #{e.message}"
          # Don't fail. The next page load will include the snippet with the new config.
        end
      end