2009-11-12 11:51:31 -05:00
|
|
|
module Webcat
|
2009-11-12 12:09:29 -05:00
|
|
|
class << self
|
|
|
|
attr_writer :default_driver, :current_driver
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-12 12:57:46 -05:00
|
|
|
attr_accessor :app
|
|
|
|
|
2009-11-12 12:09:29 -05:00
|
|
|
def default_driver
|
|
|
|
@default_driver || :rack_test
|
|
|
|
end
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-12 12:09:29 -05:00
|
|
|
def current_driver
|
|
|
|
@current_driver || default_driver
|
|
|
|
end
|
|
|
|
alias_method :mode, :current_driver
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-12 12:09:29 -05:00
|
|
|
def use_default_driver
|
|
|
|
@current_driver = nil
|
|
|
|
end
|
2009-11-12 11:51:31 -05:00
|
|
|
|
2009-11-12 12:57:46 -05:00
|
|
|
def current_session
|
|
|
|
session_pool["#{current_driver}#{app.object_id}"] ||= Webcat::Session.new(current_driver, app)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2009-11-12 12:09:29 -05:00
|
|
|
def session_pool
|
|
|
|
@session_pool ||= {}
|
|
|
|
end
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
|
2009-11-12 12:09:29 -05:00
|
|
|
extend(self)
|
|
|
|
|
2009-11-14 07:51:52 -05:00
|
|
|
def page
|
|
|
|
Webcat.current_session
|
|
|
|
end
|
2009-11-12 12:09:29 -05:00
|
|
|
|
2009-11-12 11:51:31 -05:00
|
|
|
SESSION_METHODS = [
|
2009-11-15 07:40:50 -05:00
|
|
|
:visit, :body, :click_link, :click_button, :fill_in, :choose, :has_xpath?,
|
2009-11-14 10:20:15 -05:00
|
|
|
:check, :uncheck, :attach_file, :select, :has_content?, :within, :save_and_open_page
|
2009-11-12 11:51:31 -05:00
|
|
|
]
|
|
|
|
SESSION_METHODS.each do |method|
|
|
|
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
|
|
|
def #{method}(*args, &block)
|
2009-11-14 07:51:52 -05:00
|
|
|
page.#{method}(*args, &block)
|
2009-11-12 11:51:31 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|