lib/bauxite/core/context.rb in bauxite-0.6.5 vs lib/bauxite/core/context.rb in bauxite-0.6.6
- old
+ new
@@ -21,10 +21,11 @@
#++
require 'selenium-webdriver'
require 'readline'
require 'csv'
+require 'pathname'
# Load dependencies and extensions without leaking dir into the global scope
lambda do
dir = File.expand_path(File.dirname(__FILE__))
Dir[File.join(dir, '*.rb')].each { |file| require file }
@@ -175,11 +176,16 @@
# ctx.start(lines)
# # => navigates to www.ruby-lang.org, types ljust in the search box
# # and clicks the "Search" button.
#
def start(actions = [])
- _load_driver
+ begin
+ _load_driver
+ rescue StandardError => e
+ print_error(e)
+ raise
+ end
return unless actions.size > 0
begin
actions.each do |action|
begin
exec_action(action)
@@ -418,11 +424,17 @@
end
# Constructs a Logger instance using +name+ as a hint for the logger
# type.
#
- def self.load_logger(name, options)
+ def self.load_logger(loggers, options)
+ if loggers.is_a? Array
+ return Loggers::CompositeLogger.new(options, loggers)
+ end
+
+ name = loggers
+
log_name = (name || 'null').downcase
class_name = "#{log_name.capitalize}Logger"
unless Loggers.const_defined? class_name.to_sym
@@ -551,9 +563,32 @@
with_vars(e.variables) do
exec_parsed_action('capture', [] , false)
e.variables['__CAPTURE__'] = @variables['__CAPTURE__']
end
end
+ end
+
+ # Returns the output path for +path+ accounting for the
+ # <tt>__OUTPUT__</tt> variable.
+ #
+ # For example:
+ # # assuming --output /mnt/disk
+ #
+ # ctx.output_path '/tmp/myfile.txt'
+ # # => returns '/tmp/myfile.txt'
+ #
+ # ctx.output_path 'myfile.txt'
+ # # => returns '/mnt/disk/myfile.txt'
+ #
+ def output_path(path)
+ unless Pathname.new(path).absolute?
+ output = @variables['__OUTPUT__']
+ if output
+ Dir.mkdir output unless Dir.exists? output
+ path = File.join(output, path)
+ end
+ end
+ path
end
# ======================================================================= #
# :section: Metadata
# ======================================================================= #
\ No newline at end of file