class AutomatedTest

Helpful representation of a selenium test

Public Class Methods

new(testId) click to toggle source

@param testId: the selenium session ID, usually from webdriver

# File lib/cbthelper/AutomatedTest.rb, line 12
def initialize(testId)
        @testId = testId
end

Public Instance Methods

RecordingVideo(description=nil) click to toggle source

Return the video recording for this test

# File lib/cbthelper/AutomatedTest.rb, line 85
def RecordingVideo(description=nil)
         response = RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos")
         hash = /(?<="hash": ")((\w|\d)*)/.match(response)[0]
         video = Video.new(hash, @testId)
         if description != nil
              video.setDescription(description)
         end
         return video
        
end
getSnapshots() click to toggle source

Returns all snapshots for this test

# File lib/cbthelper/AutomatedTest.rb, line 57
def getSnapshots()
        snaps = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots/"))        
        ret = []

        for snap in snaps
                ret.push(Snapshot.new(snap["hash"], @testId))

        end
        return ret
end
getVideos() click to toggle source

Returns all videos for this test

# File lib/cbthelper/AutomatedTest.rb, line 97
def getVideos
        videos = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos/"))  
        ret = []

        for video in videos
                ret.push(Video.new(video["hash"], @testId))

        end

        return ret
end
saveAllSnapshots(directory, useDescription=false) click to toggle source

Downloads all snapshots for this test into the provided directory

# File lib/cbthelper/AutomatedTest.rb, line 69
def saveAllSnapshots(directory, useDescription=false)
        prefix = "image"
        snaps = getSnapshots
        makeDirectory(directory)
      
        for i in 0...snaps.size
                if useDescription and snaps[i].info["description"] != ""
        img = snaps[i].info["description"] + ".png"
    else
        img = prefix + i.to_s + ".png"
    end
        snaps[i].saveSnapshot(File.join(directory, img))
        end
end
saveAllVideos(directory, useDescription=false) click to toggle source

Downloads all videos for this test into a directory

# File lib/cbthelper/AutomatedTest.rb, line 110
def saveAllVideos(directory, useDescription=false)
        prefix = "video"
        videos = getVideos
        makeDirectory(directory)

        for i in 0...videos.size
                if useDescription and videos[i].info["description"] != ""
        vid = videos[i].info["description"] + ".mp4"
    else
        vid = prefix + i.to_s + ".mp4"
    end
    videos[i].saveVideo(File.join(directory, vid))
        end

end
setDescription(description) click to toggle source

Sets the description for the test in the web app

# File lib/cbthelper/AutomatedTest.rb, line 24
def setDescription(description)
        RestClient.put("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}",
    "action=set_description&description=#{description}")
end
setScore(score) click to toggle source

Sets the score for our test in the CBT app @param score: should be 'pass', 'fail', or 'unset'.

# File lib/cbthelper/AutomatedTest.rb, line 18
def setScore(score)            
        RestClient.put("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}",
    "action=set_score&score=#{score}")
end
stop(score = nil) click to toggle source

@param score is optional, will combine setScore and stopTest Sends the command to our api to stop the selenium test. Similar to driver.quit()

# File lib/cbthelper/AutomatedTest.rb, line 32
def stop(score = nil)
        if score != nil
                setScore(score)
                RestClient.delete("https://#{Cbthelper.username}:#{$Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}")
        end

end
takeSnapshot(description= nil) click to toggle source

Sends the command to take a snapshot and returns a Snapshot instance @param description: (optional) shortcut for Snapshot.setDescription

# File lib/cbthelper/AutomatedTest.rb, line 42
def takeSnapshot(description= nil)

#@return : the Snapshot instance for this snapshot
         response = RestClient.post("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots",
              "selenium_test_id=#{@testId}")
         hash = /(?<="hash": ")((\w|\d)*)/.match(response)[0]
         snap = Snapshot.new(hash, @testId)
         if description != nil
              snap.setDescription(description)
         end
         return snap

end

Private Instance Methods

makeDirectory(dir) click to toggle source
# File lib/cbthelper/AutomatedTest.rb, line 127
def makeDirectory(dir)
        Dir.mkdir(dir) unless Dir.exist?(dir)

end