class Sauce::SauceFacade

wrapps the sauce whick api accessor with sane error handling

Attributes

job_id[RW]
timeout[RW]

Public Class Methods

new(timeout = 10) click to toggle source
# File lib/sauce/sauce_facade.rb, line 14
def initialize(timeout = 10)
  @timeout  = timeout ||= 10
end

Public Instance Methods

fail_job() click to toggle source
# File lib/sauce/sauce_facade.rb, line 18
def fail_job
  requires_job_id
  SauceWhisk::Jobs.fail_job @job_id
end
fetch_job_data() click to toggle source
# File lib/sauce/sauce_facade.rb, line 42
def fetch_job_data
  requires_job_id
  # TODO: let's switch this over to use whisk as well
  # This is used because it's easy to get all the data out of the job
  begin
    job = Sauce::Job.find @job_id
    JSON.parse job.to_json
  rescue StandardError => exception
    puts "An error occured while fetching the job data: #{exception.message}"
  end
end
fetch_last_screenshot() click to toggle source
# File lib/sauce/sauce_facade.rb, line 28
def fetch_last_screenshot
  requires_job_id
  polling_api_request @timeout do
    SauceWhisk::Jobs.fetch_asset @job_id, 'final_screenshot.png'
  end
end
fetch_server_log() click to toggle source
# File lib/sauce/sauce_facade.rb, line 35
def fetch_server_log
  requires_job_id
  polling_api_request @timeout do
    SauceWhisk::Jobs.fetch_asset @job_id, 'selenium-server.log'
  end
end
pass_job() click to toggle source
# File lib/sauce/sauce_facade.rb, line 23
def pass_job
  requires_job_id
  SauceWhisk::Jobs.pass_job @job_id
end

Private Instance Methods

polling_api_request(timeout) { || ... } click to toggle source
# File lib/sauce/sauce_facade.rb, line 60
def polling_api_request(timeout)
  sleep 1
  yield
  rescue RestClient::Exception => exception
    if timeout > 0
      polling_api_request(timeout - 1) { yield }
    else
      puts "Request timed out after #{timeout} with: #{exception.message}"
    end
end
requires_job_id() click to toggle source
# File lib/sauce/sauce_facade.rb, line 56
def requires_job_id
  raise ArgumentError, "#{caller[0][/`.*'/][1..-2]} requires that the job_id be set in this object." unless @job_id
end