123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Service

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: rb/lib/selenium/webdriver/common/service.rb

Overview

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

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(path: nil, port: nil, log: nil, args: nil) ⇒ Service

This method is for internal use only.

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

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 69

def initialize(path: nil, port: nil, log: nil, args: nil)
  port ||= self.class::DEFAULT_PORT
  args ||= []
  path ||= env_path

  @executable_path = path
  @host = Platform.localhost
  @port = Integer(port)
  @log = case log
         when :stdout
           $stdout
         when :stderr
           $stderr
         else
           log
         end
  @args = args

  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
end

Class Attribute Details

.driver_path (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 29

attr_reader :driver_path

.driver_path=(path) (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 54

def driver_path=(path)
  Platform.assert_executable path if path.is_a?(String)
  @driver_path = path
end

Class Method Details

.chrome(**opts)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 31

def chrome(**opts)
  Chrome::Service.new(**opts)
end

.edge(**opts) Also known as: .microsoftedge, .msedge

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 44

def edge(**opts)
  Edge::Service.new(**opts)
end

.firefox(**opts)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 35

def firefox(**opts)
  Firefox::Service.new(**opts)
end

.ie(**opts) Also known as: .internet_explorer

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 39

def ie(**opts)
  IE::Service.new(**opts)
end

.internet_explorer(**opts)

Alias for .ie.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 42

alias internet_explorer ie

.microsoftedge(**opts)

Alias for .edge.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 47

alias microsoftedge edge

.msedge(**opts)

Alias for .edge.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 48

alias msedge edge

.safari(**opts)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 50

def safari(**opts)
  Safari::Service.new(**opts)
end

Instance Attribute Details

#args (rw) Also known as: #extra_args

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 60

attr_accessor :host, :executable_path, :port, :log, :args

#executable_path (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 60

attr_accessor :host, :executable_path, :port, :log, :args

#extra_args (readonly)

Alias for #args.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 61

alias extra_args args

#host (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 60

attr_accessor :host, :executable_path, :port, :log, :args

#log (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 60

attr_accessor :host, :executable_path, :port, :log, :args

#port (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 60

attr_accessor :host, :executable_path, :port, :log, :args

Instance Method Details

#env_path

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 104

def env_path
  ENV.fetch(self.class::DRIVER_PATH_ENV_KEY, nil)
end

#find_driver_path

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 99

def find_driver_path
  default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
  DriverFinder.new(default_options, self).driver_path
end

#launch

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 90

def launch
  @executable_path ||= env_path || find_driver_path
  ServiceManager.new(self).tap(&:start)
end

#shutdown_supported

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/service.rb', line 95

def shutdown_supported
  self.class::SHUTDOWN_SUPPORTED
end