Class: Selenium::WebDriver::Service

Inherits:
Object
  • Object
show all
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 collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, port: nil, log: nil, args: nil) ⇒ Service

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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_pathObject

Returns the value of attribute driver_path.



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

def driver_path
  @driver_path
end

Instance Attribute Details

#argsObject Also known as: extra_args

Returns the value of attribute args.



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

def args
  @args
end

#executable_pathObject

Returns the value of attribute executable_path.



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

def executable_path
  @executable_path
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#logObject

Returns the value of attribute log.



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

def log
  @log
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

Class Method Details

.chrome(**opts) ⇒ Object



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

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

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



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

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

.firefox(**opts) ⇒ Object



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

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

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



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

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

.safari(**opts) ⇒ Object



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

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

Instance Method Details

#env_pathObject



104
105
106
# 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_pathObject



99
100
101
102
# 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

#launchObject



90
91
92
93
# 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_supportedObject



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

def shutdown_supported
  self.class::SHUTDOWN_SUPPORTED
end