class Selenium::WebDriver::SeleniumManager

Wrapper for getting information from the Selenium Manager binaries. This implementation is still in beta, and may change. @api private

Attributes

bin_path[W]

Public Class Methods

bin_path() click to toggle source
# File lib/selenium/webdriver/common/selenium_manager.rb, line 33
def bin_path
  @bin_path ||= '../../../../../bin'
end
binary_paths(*arguments) click to toggle source

@param [Array] arguments what gets sent to to Selenium Manager binary. @return [Hash] paths to the requested assets.

# File lib/selenium/webdriver/common/selenium_manager.rb, line 39
def binary_paths(*arguments)
  arguments += %w[--language-binding ruby]
  arguments += %w[--output json]
  arguments << '--debug' if WebDriver.logger.debug?

  run(binary, *arguments)
end

Private Class Methods

binary() click to toggle source

@return [String] the path to the correct selenium manager

# File lib/selenium/webdriver/common/selenium_manager.rb, line 50
def binary
  @binary ||= begin
    if (location = ENV.fetch('SE_MANAGER_PATH', nil))
      WebDriver.logger.debug("Selenium Manager set by ENV['SE_MANAGER_PATH']: #{location}")
    end
    location ||= platform_location

    Platform.assert_executable(location)
    WebDriver.logger.debug("Selenium Manager binary found at #{location}", id: :selenium_manager)
    location
  end
end
execute_command(*command) click to toggle source
# File lib/selenium/webdriver/common/selenium_manager.rb, line 89
def execute_command(*command)
  WebDriver.logger.debug("Executing Process #{command}", id: :selenium_manager)

  Open3.capture3(*command)
rescue StandardError => e
  raise Error::WebDriverError, "Unsuccessful command executed: #{command}; #{e.message}"
end
parse_result_and_log(stdout) click to toggle source
# File lib/selenium/webdriver/common/selenium_manager.rb, line 97
def parse_result_and_log(stdout)
  json_output = stdout.empty? ? {'logs' => [], 'result' => {}} : JSON.parse(stdout)

  json_output['logs'].each do |log|
    level = log['level'].casecmp('info').zero? ? 'debug' : log['level'].downcase
    WebDriver.logger.send(level, log['message'], id: :selenium_manager)
  end

  json_output['result']
end
platform_location() click to toggle source
# File lib/selenium/webdriver/common/selenium_manager.rb, line 72
def platform_location
  directory = File.expand_path(bin_path, __FILE__)
  if Platform.windows?
    "#{directory}/windows/selenium-manager.exe"
  elsif Platform.mac?
    "#{directory}/macos/selenium-manager"
  elsif Platform.linux?
    "#{directory}/linux/selenium-manager"
  elsif Platform.unix?
    WebDriver.logger.warn('Selenium Manager binary may not be compatible with Unix',
                          id: %i[selenium_manager unix_binary])
    "#{directory}/linux/selenium-manager"
  else
    raise Error::WebDriverError, "unsupported platform: #{Platform.os}"
  end
end
run(*command) click to toggle source
# File lib/selenium/webdriver/common/selenium_manager.rb, line 63
def run(*command)
  stdout, stderr, status = execute_command(*command)
  result = parse_result_and_log(stdout)

  validate_command_result(command, status, result, stderr)

  result
end
validate_command_result(command, status, result, stderr) click to toggle source
# File lib/selenium/webdriver/common/selenium_manager.rb, line 108
def validate_command_result(command, status, result, stderr)
  if status.nil? || status.exitstatus.nil?
    WebDriver.logger.info("No exit status for: #{command}. Assuming success if result is present.",
                          id: :selenium_manager)
  end

  return unless status&.exitstatus&.positive? || result.nil?

  code = status&.exitstatus || 'exit status not available'
  raise Error::WebDriverError,
        "Unsuccessful command executed: #{command} - Code #{code}\n#{result}\n#{stderr}"
end