Class: Selenium::WebDriver::Service
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Service
- Defined in:
- lib/selenium/webdriver/common/service.rb
Overview
Base class implementing default behavior of service object, responsible for starting and stopping driver implementations.
Direct Known Subclasses
Chrome::Service, Edge::Service, Firefox::Service, IE::Service, Selenium::WebDriver::Safari::Service
Constant Summary collapse
- START_TIMEOUT =
20
- SOCKET_LOCK_TIMEOUT =
45
- STOP_TIMEOUT =
20
Class Attribute Summary collapse
-
.default_port ⇒ Object
readonly
Returns the value of attribute default_port.
-
.driver_path ⇒ Object
Returns the value of attribute driver_path.
-
.executable ⇒ Object
readonly
Returns the value of attribute executable.
-
.missing_text ⇒ Object
readonly
Returns the value of attribute missing_text.
-
.shutdown_supported ⇒ Object
readonly
Returns the value of attribute shutdown_supported.
Instance Attribute Summary collapse
-
#executable_path ⇒ Object
readonly
Returns the value of attribute executable_path.
-
#host ⇒ Object
Returns the value of attribute host.
Class Method Summary collapse
- .chrome(**opts) ⇒ Object
- .edge(**opts) ⇒ Object
- .firefox(**opts) ⇒ Object
- .ie(**opts) ⇒ Object (also: internet_explorer)
- .safari(**opts) ⇒ Object
Instance Method Summary collapse
-
#initialize(path: nil, port: nil, args: nil) ⇒ Service
constructor
private
End users should use a class method for the desired driver, rather than using this directly.
- #start ⇒ Object
- #stop ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(path: nil, port: 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.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/selenium/webdriver/common/service.rb', line 89 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 |
Class Attribute Details
.default_port ⇒ Object (readonly)
Returns the value of attribute default_port.
38 39 40 |
# File 'lib/selenium/webdriver/common/service.rb', line 38 def default_port @default_port end |
.driver_path ⇒ Object
Returns the value of attribute driver_path.
38 39 40 |
# File 'lib/selenium/webdriver/common/service.rb', line 38 def driver_path @driver_path end |
.executable ⇒ Object (readonly)
Returns the value of attribute executable.
38 39 40 |
# File 'lib/selenium/webdriver/common/service.rb', line 38 def executable @executable end |
.missing_text ⇒ Object (readonly)
Returns the value of attribute missing_text.
38 39 40 |
# File 'lib/selenium/webdriver/common/service.rb', line 38 def missing_text @missing_text end |
.shutdown_supported ⇒ Object (readonly)
Returns the value of attribute shutdown_supported.
38 39 40 |
# File 'lib/selenium/webdriver/common/service.rb', line 38 def shutdown_supported @shutdown_supported end |
Instance Attribute Details
#executable_path ⇒ Object (readonly)
Returns the value of attribute executable_path.
81 82 83 |
# File 'lib/selenium/webdriver/common/service.rb', line 81 def executable_path @executable_path end |
#host ⇒ Object
Returns the value of attribute host.
80 81 82 |
# File 'lib/selenium/webdriver/common/service.rb', line 80 def host @host end |
Class Method Details
.chrome(**opts) ⇒ Object
40 41 42 |
# File 'lib/selenium/webdriver/common/service.rb', line 40 def chrome(**opts) Chrome::Service.new(**opts) end |
.edge(**opts) ⇒ Object
66 67 68 |
# File 'lib/selenium/webdriver/common/service.rb', line 66 def edge(**opts) Edge::Service.new(**opts) end |
.firefox(**opts) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/selenium/webdriver/common/service.rb', line 44 def firefox(**opts) binary_path = Firefox::Binary.path args = opts.delete(:args) case args when Hash args[:binary] ||= binary_path opts[:args] = args when Array opts[:args] = ["--binary=#{binary_path}"] opts[:args] += args else opts[:args] = ["--binary=#{binary_path}"] end Firefox::Service.new(**opts) end |
Instance Method Details
#start ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/selenium/webdriver/common/service.rb', line 103 def start raise "already started: #{uri.inspect} #{@executable_path.inspect}" if process_running? Platform.exit_hook(&method(:stop)) # make sure we don't leave the server running socket_lock.locked do find_free_port start_process connect_until_stable end end |
#stop ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/selenium/webdriver/common/service.rb', line 115 def stop return unless self.class.shutdown_supported stop_server @process.poll_for_exit STOP_TIMEOUT rescue ChildProcess::TimeoutError nil # noop ensure stop_process end |
#uri ⇒ Object
126 127 128 |
# File 'lib/selenium/webdriver/common/service.rb', line 126 def uri @uri ||= URI.parse("http://#{@host}:#{@port}") end |