"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/rb/lib/selenium/webdriver/common/service.rb" (17 Feb 2023, 3444 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "service.rb":
4.7.0_vs_4.8.0.
1 # frozen_string_literal: true
2
3 # Licensed to the Software Freedom Conservancy (SFC) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The SFC licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
18 # under the License.
19
20 module Selenium
21 module WebDriver
22 #
23 # Base class implementing default behavior of service object,
24 # responsible for storing a service manager configuration.
25 #
26
27 class Service
28 class << self
29 attr_reader :driver_path
30
31 def chrome(**opts)
32 Chrome::Service.new(**opts)
33 end
34
35 def firefox(**opts)
36 Firefox::Service.new(**opts)
37 end
38
39 def ie(**opts)
40 IE::Service.new(**opts)
41 end
42 alias internet_explorer ie
43
44 def edge(**opts)
45 Edge::Service.new(**opts)
46 end
47 alias microsoftedge edge
48 alias msedge edge
49
50 def safari(**opts)
51 Safari::Service.new(**opts)
52 end
53
54 def driver_path=(path)
55 Platform.assert_executable path if path.is_a?(String)
56 @driver_path = path
57 end
58 end
59
60 attr_accessor :host, :executable_path, :port, :args
61 alias extra_args args
62
63 #
64 # End users should use a class method for the desired driver, rather than using this directly.
65 #
66 # @api private
67 #
68
69 def initialize(path: nil, port: nil, args: nil)
70 path ||= self.class.driver_path
71 port ||= self.class::DEFAULT_PORT
72 args ||= []
73
74 @executable_path = binary_path(path)
75 @host = Platform.localhost
76 @port = Integer(port)
77
78 @args = args.is_a?(Hash) ? extract_service_args(args) : args
79
80 raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
81 end
82
83 def launch
84 ServiceManager.new(self).tap(&:start)
85 end
86
87 def shutdown_supported
88 self.class::SHUTDOWN_SUPPORTED
89 end
90
91 protected
92
93 def extract_service_args(driver_opts)
94 WebDriver.logger.deprecate('initializing Service class with :args using Hash',
95 ':args parameter with an Array of String values',
96 id: :driver_opts)
97 driver_opts.key?(:args) ? driver_opts.delete(:args) : []
98 end
99
100 private
101
102 def binary_path(path = nil)
103 path = path.call if path.is_a?(Proc)
104 path ||= Platform.find_binary(self.class::EXECUTABLE)
105
106 begin
107 path ||= SeleniumManager.driver_path(self.class::EXECUTABLE)
108 rescue Error::WebDriverError => e
109 WebDriver.logger.debug("Unable obtain driver using Selenium Manager\n #{e.message}")
110 end
111
112 raise Error::WebDriverError, self.class::MISSING_TEXT unless path
113
114 Platform.assert_executable path
115 path
116 end
117 end # Service
118 end # WebDriver
119 end # Selenium