class CapsBuilder

Builder for generating selenium capabilities All of the with… methods return self for method chaining

Public Class Methods

new() click to toggle source
# File lib/cbthelper/CapsBuilder.rb, line 11
def initialize
    @capsData = JSON.parse(RestClient.get("https://crossbrowsertesting.com/api/v3/selenium/browsers"))
    @platform = nil
    @browser = nil
    @width = nil
    @height = nil
    @name = nil
    @version = nil
    @recordVideo = nil
    @recordNetwork = nil
end

Public Instance Methods

bestBrowserNoPlatform(target) click to toggle source

Determines the best platform based on user input :param target when no platform provided

# File lib/cbthelper/CapsBuilder.rb, line 90
def bestBrowserNoPlatform(target)
    target = target.downcase

    for platform in @capsData
        for browser in platform['browsers']
            name = browser['name'].downcase
            if target == name or target == apiName
                return browser
            end
        end
    end

    return nil
end
bestOption(options, target) click to toggle source

Determines the best platform based on user input :param target

# File lib/cbthelper/CapsBuilder.rb, line 74
def bestOption(options, target)
    if target != nil
        target =target.downcase
    end
    
    for option in options
        name = option['name'].downcase
        apiName = option['name'].downcase
        if target == name or target == apiName
            return option
        end
    end
    return nil
end
build() click to toggle source

Used to generate the capabilites using any options the user specifies

# File lib/cbthelper/CapsBuilder.rb, line 69
def build
    return choose
end
withBrowserApiName(browser) click to toggle source

Sets the browser the user wants to use. The string will be compared against the 'name' and 'api_name' properties returned from the selenium api. @param browser: as string specifying the browser (eg. Edge 17, Chrome 55x64)

# File lib/cbthelper/CapsBuilder.rb, line 32
def withBrowserApiName(browser)
    @browser = browser
    self
end
withBuild(build) click to toggle source

Sets the build number in the web app

# File lib/cbthelper/CapsBuilder.rb, line 51
def withBuild(build)
    @version = build
    self
end
withName(name) click to toggle source

Sets the name of the test in the web app

# File lib/cbthelper/CapsBuilder.rb, line 45
def withName(name)
    @name = name
    self
end
withPlatform(platform) click to toggle source

Sets the platform (OS) the user wants to use. The string will be compared against the 'name' and 'api_name' properties returned from the selenium api. @param platform: a string specifying the platform (eg. Windows 7, Mac 10.13)

# File lib/cbthelper/CapsBuilder.rb, line 25
def withPlatform(platform)
    @platform = platform
    self
end
withRecordNetwork(bool) click to toggle source

Records network traffic for the length of the test

# File lib/cbthelper/CapsBuilder.rb, line 63
def withRecordNetwork(bool)
    @recordNetwork = bool
    self
end
withRecordVideo(bool) click to toggle source

Records a video for the length of the test

# File lib/cbthelper/CapsBuilder.rb, line 57
def withRecordVideo(bool)
    @recordVideo = bool
    self
end
withResolution(width, height) click to toggle source

Sets the screen size for the test

# File lib/cbthelper/CapsBuilder.rb, line 38
def withResolution(width, height)
    @width = width
    @height = height
    self
end

Private Instance Methods

choose() click to toggle source

Sets the capabilities passed to the WebDriver

# File lib/cbthelper/CapsBuilder.rb, line 107
def choose
    data = @capsData
    caps = Selenium::WebDriver::Remote::Capabilities.new
    if @platform
        caps['platform'] = @platform
    end
    if @browser
        caps['browser_api_name'] = @browser
    end

    if @width and @height
        caps['screenResolution'] = @width.to_s + 'x' + @height.to_s
    end

    if @name
        caps['name'] = @name
    end

    if @version
        caps['build'] = @version
    end 

    if @recordVideo
        caps['record_video'] = @recordVideo
    end

    if @recordNetwork
        caps['record_network'] = @recordNetwork
    end
    return caps
end