class Gondola::Tester
Constants
- SELENIUM_OBJECT
Attributes
errors[R]
job_id[R]
status[R]
Public Class Methods
new(req, converter)
click to toggle source
# File lib/gondola/tester.rb, line 15 def initialize(req, converter) @sel = Gondola::Selenium.new req @converter = converter @cmd_num = 0 @errors = [] end
Public Instance Methods
begin()
click to toggle source
Issue all the test commands, catching any errors
# File lib/gondola/tester.rb, line 46 def begin begin eval @converter.ruby rescue AssertionError rescue ::Selenium::Client::CommandError => e add_error_with_trace e.message, e.backtrace rescue Timeout::Error => e add_error_with_trace "ERROR: Command timed out", e.backtrace ensure finish end end
setup()
click to toggle source
Start a new Sauce Labs’ job and return the session_id
# File lib/gondola/tester.rb, line 23 def setup begin @sel.start @job_id = @sel.session_id @status = :in_progress rescue ::Selenium::Client::CommandError => e @status = :not_started @errors << { :cmd_num => 0, :command => {:ruby => "#{SELENIUM_OBJECT}.start"}, :error => e.message } rescue Timeout::Error => e @errors << { :cmd_num => 0, :command => {:ruby => "#{SELENIUM_OBJECT}.start"}, :error => "ERROR: Command timed out" } end @job_id end
Private Instance Methods
add_error_with_trace(desc, trace=caller)
click to toggle source
Add the current command to the error list with the given description
# File lib/gondola/tester.rb, line 96 def add_error_with_trace(desc, trace=caller) cmd_num = get_cmd_num(trace) @errors.push << { :cmd_num => cmd_num, :command => @converter.commands[cmd_num-1], :error => desc } end
finish()
click to toggle source
Shutdown the Sauce Labs’ job and report the status of the test
# File lib/gondola/tester.rb, line 63 def finish begin if @errors.empty? @status = :passed @sel.passed! else @status = :failed @sel.failed! end @sel.stop rescue ::Selenium::Client::CommandError => e @errors << { :cmd_num => 0, :command => {:ruby => ""}, :error => e.message } rescue Timeout::Error => e @errors << { :cmd_num => 0, :command => {:ruby => ""}, :error => "ERROR: Command timed out" } end end
get_cmd_num(trace)
click to toggle source
# File lib/gondola/tester.rb, line 88 def get_cmd_num(trace) ev = trace.delete_if { |c| !(c =~ /\(eval\)/) }[0] return 0 unless ev ev.match(/:(\d+)/)[1].to_i end
method_missing(method, *args)
click to toggle source
Handle all the assert functions by just making the respective verify call and throwing an exception to end the flow
# File lib/gondola/tester.rb, line 107 def method_missing(method, *args) if method.to_s =~ /^assert(.*)/ raise AssertionError unless send "verify#{$1}".to_sym, *args end end
verify(expr)
click to toggle source
# File lib/gondola/tester.rb, line 113 def verify(expr) add_error_with_trace "ERROR: Command returned false, expecting true" unless expr return expr end
verify_equal(eq, expr)
click to toggle source
# File lib/gondola/tester.rb, line 123 def verify_equal(eq, expr) add_error_with_trace "ERROR: Command returned '#{expr}', expecting '#{eq}'" unless eq == expr return eq == expr end
verify_not(expr)
click to toggle source
# File lib/gondola/tester.rb, line 118 def verify_not(expr) add_error_with_trace "ERROR: Command returned true, expecting false" if expr return !expr end
verify_not_equal(eq, expr)
click to toggle source
# File lib/gondola/tester.rb, line 128 def verify_not_equal(eq, expr) add_error_with_trace "ERROR: Command returned '#{expr}', expecting anything but" unless eq != expr return eq != expr end