class Selenium::WebDriver::Service

Base class implementing default behavior of service object, responsible for storing a service manager configuration.

Attributes

driver_path[R]
executable_path[R]
extra_args[R]
host[RW]
port[R]

Public Class Methods

chrome(**opts) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 31
def chrome(**opts)
  Chrome::Service.new(**opts)
end
driver_path=(path) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 53
def driver_path=(path)
  Platform.assert_executable path if path.is_a?(String)
  @driver_path = path
end
edge(**opts) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 44
def edge(**opts)
  Edge::Service.new(**opts)
end
Also aliased as: microsoftedge
firefox(**opts) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 35
def firefox(**opts)
  Firefox::Service.new(**opts)
end
ie(**opts) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 39
def ie(**opts)
  IE::Service.new(**opts)
end
Also aliased as: internet_explorer
internet_explorer(**opts)
Alias for: ie
microsoftedge(**opts)
Alias for: edge
new(path: nil, port: nil, args: nil) click to toggle source

End users should use a class method for the desired driver, rather than using this directly.

@api private

# File lib/selenium/webdriver/common/service.rb, line 68
def initialize(path: nil, port: nil, args: nil)
  path ||= self.class.driver_path
  port ||= self.class::DEFAULT_PORT
  args ||= []

  @executable_path = binary_path(path)
  @host = Platform.localhost
  @port = Integer(port)

  @extra_args = args.is_a?(Hash) ? extract_service_args(args) : args

  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
end
safari(**opts) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 49
def safari(**opts)
  Safari::Service.new(**opts)
end

Public Instance Methods

launch() click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 82
def launch
  ServiceManager.new(self).tap(&:start)
end
shutdown_supported() click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 86
def shutdown_supported
  self.class::SHUTDOWN_SUPPORTED
end

Protected Instance Methods

extract_service_args(driver_opts) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 92
def extract_service_args(driver_opts)
  driver_opts.key?(:args) ? driver_opts.delete(:args) : []
end

Private Instance Methods

binary_path(path = nil) click to toggle source
# File lib/selenium/webdriver/common/service.rb, line 98
def binary_path(path = nil)
  path = path.call if path.is_a?(Proc)
  path ||= Platform.find_binary(self.class::EXECUTABLE)

  begin
    path ||= SeleniumManager.driver_path(self.class::EXECUTABLE)
  rescue Error::WebDriverError => e
    WebDriver.logger.debug("Unable obtain driver using Selenium Manager; #{e.message}")
  end

  raise Error::WebDriverError, self.class::MISSING_TEXT unless path

  Platform.assert_executable path
  path
end