class Selenium::WebDriver::SeleniumManager
@api private
This implementation is still in beta, and may change.
Wrapper for getting information from the Selenium Manager binaries.
def bin_path
def bin_path @bin_path ||= '../../../../../bin' end
def binary
-
(String)
- the path to the correct selenium manager
def binary @binary ||= begin path = File.expand_path(bin_path, __FILE__) path << if Platform.windows? '/windows/selenium-manager.exe' elsif Platform.mac? '/macos/selenium-manager' elsif Platform.linux? '/linux/selenium-manager' end location = File.expand_path(path, __FILE__) begin Platform.assert_file(location) Platform.assert_executable(location) rescue TypeError raise Error::WebDriverError, "Unable to locate or obtain Selenium Manager binary; #{location} is not a valid file object" rescue Error::WebDriverError => e raise Error::WebDriverError, "Selenium Manager binary located, but #{e.message}" end WebDriver.logger.debug("Selenium Manager binary found at #{location}", id: :selenium_manager) location end end
def driver_path(options)
-
(String)
- the path to the correct driver.
Parameters:
-
options
(Options
) -- browser options.
def driver_path(options) message = 'applicable driver not found; attempting to install with Selenium Manager (Beta)' WebDriver.logger.debug(message, id: :selenium_manager) command = generate_command(binary, options) location = run(*command) WebDriver.logger.debug("Driver found at #{location}", id: :selenium_manager) Platform.assert_executable location location end
def generate_command(binary, options)
def generate_command(binary, options) command = [binary, '--browser', options.browser_name, '--output', 'json'] if options.browser_version command << '--browser-version' command << options.browser_version end if options.respond_to?(:binary) && !options.binary.nil? command << '--browser-path' command << options.binary.gsub('\\', '\\\\\\') end if options.proxy command << '--proxy' (command << options.proxy.ssl) || options.proxy.http end command << '--debug' if WebDriver.logger.debug? command end
def run(*command)
def run(*command) WebDriver.logger.debug("Executing Process #{command}", id: :selenium_manager) begin stdout, stderr, status = Open3.capture3(*command) json_output = stdout.empty? ? nil : JSON.parse(stdout) result = json_output&.dig('result', 'message') rescue StandardError => e raise Error::WebDriverError, "Unsuccessful command executed: #{command}; #{e.message}" end (json_output&.fetch('logs') || []).each do |log| level = log['level'].casecmp('info').zero? ? 'debug' : log['level'].downcase WebDriver.logger.send(level, log['message'], id: :selenium_manager) end if status.exitstatus.positive? raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{result}#{stderr}" end result end