1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# frozen_string_literal: true
require 'capybara'
module Capybara
module DSL
def self.included(base)
warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
super
end
def self.extended(base)
warn 'extending the main object with Capybara::DSL is not recommended!' if base == TOPLEVEL_BINDING.eval('self')
super
end
##
#
# Shortcut to working in a different session.
#
def using_session(name_or_session, &block)
Capybara.using_session(name_or_session, &block)
end
# Shortcut to using a different wait time.
#
def using_wait_time(seconds, &block)
page.using_wait_time(seconds, &block)
end
##
#
# Shortcut to accessing the current session.
#
# class MyClass
# include Capybara::DSL
#
# def has_header?
# page.has_css?('h1')
# end
# end
#
# @return [Capybara::Session] The current session object
#
def page
Capybara.current_session
end
Session::DSL_METHODS.each do |method|
class_eval <<~METHOD, __FILE__, __LINE__ + 1
def #{method}(...)
page.method("#{method}").call(...)
end
METHOD
end
end
extend(Capybara::DSL)
end
|