class Video

Represents a video recording for a selenium test

Attributes

info[RW]

@param hash: the hash for this video, returned by rest api when starting a recording @param test: an AutomatedTest object that represents a test currently running

Public Class Methods

new(hash, test) click to toggle source
# File lib/cbthelper/Video.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 video @return : a hash object with all of the info for this video

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

@param location: a string with the location and filename for the video. Should have a .mp4 extension

# File lib/cbthelper/Video.rb, line 39
def saveVideo(location)
        url = getInfo["video"]
stopRecording unless info["is_finished"]

path = File.split(location)[0]
Dir.mkdir(path) unless Dir.exist?(path)

#downloads the video 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 video

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

end
stopRecording() click to toggle source
# File lib/cbthelper/Video.rb, line 25
def stopRecording
        #Sends the command to stop a video recording
        RestClient.delete("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos/#{@hash}")
        
end