class AutomationHelpers::Drivers::V4::Local

{AutomationHelpers::Drivers::V4::Local}

The Local Driver that will spin up and run on your machine (Without connecting to any grid)

Attributes

browser[R]

Public Class Methods

new(browser) click to toggle source

#### Initial setup options

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

# File lib/automation_helpers/drivers/v4/local.rb, line 23
def initialize(browser)
  @browser = browser
end

Public Instance Methods

capabilities() click to toggle source

@return [Array]

The order of these capabilities is important because in the internal configuration for the driver; these 2 objects are merged (And both will contain a browserName) as such we need to ensure the browserName we manually set in ‘desired_capabilities` is retained as this is the one required by safari

# File lib/automation_helpers/drivers/v4/local.rb, line 47
def capabilities
  if safari?
    [options, desired_capabilities]
  else
    [desired_capabilities, options]
  end
end
register() click to toggle source

@return [Nil]

Register a new driver with the default selenium name for use locally

# File lib/automation_helpers/drivers/v4/local.rb, line 30
def register
  Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(
      app,
      browser: browser,
      service: service,
      capabilities: capabilities
    )
  end
end

Private Instance Methods

desired_capabilities() click to toggle source

This is required because Capybara and Safari aren’t quite sure what the difference is between the two browsers. So to compensate an illegal browserName value is set that allows easy distinction between the two browsers

NB: Whilst using Safari TP this is required.

# File lib/automation_helpers/drivers/v4/local.rb, line 73
def desired_capabilities
  ::Selenium::WebDriver::Remote::Capabilities.new.tap do |capabilities|
    if safari?
      capabilities['browserName'] = 'Safari Technology Preview'
      AutomationHelpers.logger.warn('Altering Browser Name request to alleviate Capybara failure with STP.')
    end
  end
end
options() click to toggle source
# File lib/automation_helpers/drivers/v4/local.rb, line 82
def options
  Options.for(browser)
end
safari?() click to toggle source
# File lib/automation_helpers/drivers/v4/local.rb, line 86
def safari?
  browser == :safari
end
service() click to toggle source

This is required to make local drivers work exclusively with Safari TP This is required in V13 of Safari as the driver there is notoriously flaky In V12 it doesn’t hinder it Safari V11 is unsupported.

# File lib/automation_helpers/drivers/v4/local.rb, line 61
def service
  return unless safari?

  ::Selenium::WebDriver::Safari.technology_preview!
  ::Selenium::WebDriver::Service.safari(args: ['--diagnose'])
end