class AutomationHelpers::Drivers::V4::Browserstack

{AutomationHelpers::Drivers::V4::Browserstack}

The Browserstack Driver that will connect to a hosted grid Requires a series of pre-set values to be passed in

Attributes

browser[R]
browserstack_options[R]
device_options[R]

Public Class Methods

new(browser, browserstack_options, device_options = {}) click to toggle source

#### Initial setup options

  • browser (required) - When instantiating, the first argument must be the symbol that represents what browser to use

  • browserstack_options (required) - A Hash of all required options that will be parsed and used to setup the driver

    • :build_name (String) -> The build name to be stored on browserstack servers

    • :project_name (String) -> The project name to be stored on browserstack servers

    • :session_name (String) -> The session name to be stored on browserstack servers

    • :browserstack_debug_mode (Boolean) -> Set this to true to run in browserstack debug mode (Note this runs slower!)

    • :config (String) -> This is an underscore separated key that distils the granular running information i.e. Windows_7_86 means run on Windows Operating System, OS Version 7, Browser Version 86 i.e. OSX_Mojave_12 means run on Mac Operating System, OS Version Mojave, Browser Version 12 i.e. Windows_10_92 means run on Windows Operating System, OS Version 10, Browser Version 92

    • :username (String) -> The username for Browserstack

    • :api_key (String) -> The api key for Browserstack

# File lib/automation_helpers/drivers/v4/browserstack.rb, line 37
def initialize(browser, browserstack_options, device_options = {})
  @browser = browser
  @browserstack_options = browserstack_options
  @device_options = device_options
end

Public Instance Methods

register() click to toggle source

@return [Nil]

Register a new driver with the default selenium name for use in a remote browserstack setup

# File lib/automation_helpers/drivers/v4/browserstack.rb, line 46
def register
  Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(
      app,
      browser: :remote,
      capabilities: [desired_capabilities, options],
      url: browserstack_hub_url
    )
  end
end

Private Instance Methods

browser_specific_capabilities() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 99
def browser_specific_capabilities
  Capabilities.for(browser, device_options)
end
browser_version() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 125
def browser_version
  browserstack_options[:config].split('_')[2]
end
browser_version_capability() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 103
def browser_version_capability
  return {} if device?

  { 'browserVersion' => browser_version }
end
browserstack_capabilities() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 70
def browserstack_capabilities
  ::Faraday::Utils.deep_merge(configurable_capabilities, static_capabilities)
end
browserstack_hub_url() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 113
def browserstack_hub_url
  "https://#{browserstack_options[:username]}:#{browserstack_options[:api_key]}@hub-cloud.browserstack.com/wd/hub"
end
configurable_capabilities() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 74
def configurable_capabilities
  {
    'bstack:options' => {
      'buildName' => browserstack_options[:build_name],
      'projectName' => browserstack_options[:project_name],
      'sessionName' => browserstack_options[:session_name],
      'debug' => browserstack_options[:browserstack_debug_mode],
      'os' => os,
      'osVersion' => os_version
    }
  }
end
desired_capabilities() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 59
def desired_capabilities
  Selenium::WebDriver::Remote::Capabilities.new(
    ::Faraday::Utils.deep_merge(
      # Browserstack Capabilities and General Capabilities are at different levels, so we merge first
      browserstack_capabilities.merge(browser_version_capability),
      # Then we deep merge with anything specifically passed into the driver registration (as these can be nested)
      browser_specific_capabilities.as_json
    )
  )
end
device?() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 129
def device?
  %i[android ios].include?(browser)
end
options() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 109
def options
  Options.for(browser)
end
os() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 117
def os
  browserstack_options[:config].split('_')[0]
end
os_version() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 121
def os_version
  browserstack_options[:config].split('_')[1]
end
static_capabilities() click to toggle source
# File lib/automation_helpers/drivers/v4/browserstack.rb, line 87
def static_capabilities
  {
    'bstack:options' => {
      'local' => 'false',
      'seleniumVersion' => '4.0.0-alpha-6',
      'consoleLogs' => 'verbose',
      'networkLogs' => 'true',
      'resolution' => '1920x1080'
    }
  }
end