class Snapshot

Represents a snapshot for selenium tests

Attributes

info[RW]

@param hash: the hash for this image, returned by rest api when taking a screenshot @param test: an AutomatedTest object that represents a test currently running

Public Class Methods

new(hash, test) click to toggle source
# File lib/cbthelper/Snapshot.rb, line 12
def initialize(hash, test)
    @hash = hash
    @testId = test
    getInfo
end

Public Instance Methods

getInfo() click to toggle source

Calls out to api to get updated info for this snapshot @return : a hash object with all of the info for this Snapshot

# File lib/cbthelper/Snapshot.rb, line 20
def getInfo
    @info = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots/#{@hash}"))
end
saveSnapshot(location) click to toggle source

Downloads the snapshot to the given location @param location: a string with the location and filename for the image. Should have a .png extension

# File lib/cbthelper/Snapshot.rb, line 33
def saveSnapshot(location)
    url = getInfo["image"]
    path = File.split(location)[0]
    Dir.mkdir(path) unless Dir.exist?(path)

    #downloads the image to the given location in chunks
    File.open(location, "wb") {|f|
        block = proc { |response|
            response.read_body do |chunk|
                f.write chunk
            end
        }
        RestClient::Request.execute(method: :get,
                                    url: url,
                                    block_response: block)
    }
end
setDescription(description) click to toggle source

Sets the description for this snapshot

# File lib/cbthelper/Snapshot.rb, line 25
def setDescription(description) 
    url = "https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots/#{@hash}"
    @info = RestClient.put(url, "description=#{description}")
  
end