Sha256: c57bcfcad06ed84088ae9639155fb088f889c970ca9bcd1912ecb4119922c0e9
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
# Encoding: utf-8 require 'json' require 'sauce_whisk' require 'rest_client' require 'sauce/client' module Sauce # wrapps the sauce whick api accessor with sane error handling class SauceFacade attr_accessor :job_id, :timeout def initialize(timeout = 10) @timeout = timeout ||= 10 end def fail_job requires_job_id SauceWhisk::Jobs.fail_job @job_id end def pass_job requires_job_id SauceWhisk::Jobs.pass_job @job_id end def fetch_last_screenshot requires_job_id polling_api_request @timeout do SauceWhisk::Jobs.fetch_asset @job_id, 'final_screenshot.png' end end def fetch_server_log requires_job_id polling_api_request @timeout do SauceWhisk::Jobs.fetch_asset @job_id, 'selenium-server.log' end end 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 => e puts "An error occured while fetching the job data: #{e.message}" end end private def requires_job_id raise ArgumentError, "#{caller[0][/`.*'/][1..-2]} requires that the job_id be set in this object." unless @job_id end def polling_api_request(timeout) begin sleep 1 yield rescue RestClient::Exception => e if timeout > 0 polling_api_request(timeout - 1) { yield } else puts "Request timed out after #{timeout} with: #{e.message}" end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
selenium-connect-3.3.1 | lib/sauce/sauce_facade.rb |
selenium-connect-3.3.0 | lib/sauce/sauce_facade.rb |
selenium-connect-3.2.0 | lib/sauce/sauce_facade.rb |