Skip to content

Commit 7602371

Browse files
authored
[rb] Allow driver path to be set using ENV variables (#14287)
1 parent 39c38e4 commit 7602371

File tree

19 files changed

+221
-6
lines changed

19 files changed

+221
-6
lines changed

rb/lib/selenium/webdriver/chrome/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Service < WebDriver::Service
2424
DEFAULT_PORT = 9515
2525
EXECUTABLE = 'chromedriver'
2626
SHUTDOWN_SUPPORTED = true
27+
DRIVER_PATH_ENV_KEY = 'SE_CHROMEDRIVER'
2728

2829
def log
2930
return @log unless @log.is_a? String

rb/lib/selenium/webdriver/common/service.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def driver_path=(path)
6969
def initialize(path: nil, port: nil, log: nil, args: nil)
7070
port ||= self.class::DEFAULT_PORT
7171
args ||= []
72+
path ||= env_path
7273

7374
@executable_path = path
7475
@host = Platform.localhost
@@ -87,16 +88,22 @@ def initialize(path: nil, port: nil, log: nil, args: nil)
8788
end
8889

8990
def launch
90-
@executable_path ||= begin
91-
default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
92-
DriverFinder.new(default_options, self).driver_path
93-
end
91+
@executable_path ||= env_path || find_driver_path
9492
ServiceManager.new(self).tap(&:start)
9593
end
9694

9795
def shutdown_supported
9896
self.class::SHUTDOWN_SUPPORTED
9997
end
98+
99+
def find_driver_path
100+
default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
101+
DriverFinder.new(default_options, self).driver_path
102+
end
103+
104+
def env_path
105+
ENV.fetch(self.class::DRIVER_PATH_ENV_KEY, nil)
106+
end
100107
end # Service
101108
end # WebDriver
102109
end # Selenium

rb/lib/selenium/webdriver/edge/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Service < WebDriver::Service
2424
DEFAULT_PORT = 9515
2525
EXECUTABLE = 'msedgedriver'
2626
SHUTDOWN_SUPPORTED = true
27-
27+
DRIVER_PATH_ENV_KEY = 'SE_EDGEDRIVER'
2828
def log
2929
return @log unless @log.is_a? String
3030

rb/lib/selenium/webdriver/firefox/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Service < WebDriver::Service
2424
DEFAULT_PORT = 4444
2525
EXECUTABLE = 'geckodriver'
2626
SHUTDOWN_SUPPORTED = false
27+
DRIVER_PATH_ENV_KEY = 'SE_GECKODRIVER'
2728
end # Service
2829
end # Firefox
2930
end # WebDriver

rb/lib/selenium/webdriver/ie/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Service < WebDriver::Service
2424
DEFAULT_PORT = 5555
2525
EXECUTABLE = 'IEDriverServer'
2626
SHUTDOWN_SUPPORTED = true
27+
DRIVER_PATH_ENV_KEY = 'SE_IEDRIVER'
2728
end # Server
2829
end # IE
2930
end # WebDriver

rb/lib/selenium/webdriver/safari/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Service < WebDriver::Service
2424
DEFAULT_PORT = 7050
2525
EXECUTABLE = 'safaridriver'
2626
SHUTDOWN_SUPPORTED = false
27-
27+
DRIVER_PATH_ENV_KEY = 'SE_SAFARIDRIVER'
2828
def initialize(path: nil, port: nil, log: nil, args: nil)
2929
raise Error::WebDriverError, 'Safari Service does not support setting log output' if log
3030

rb/sig/lib/selenium/webdriver/chrome/service.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Selenium
22
module WebDriver
33
module Chrome
44
class Service < WebDriver::Service
5+
DRIVER_PATH_ENV_KEY: String
6+
57
@log: untyped
68

79
DEFAULT_PORT: Integer

rb/sig/lib/selenium/webdriver/common/service.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ module Selenium
4747

4848
attr_accessor args: untyped
4949

50+
def env_path: -> String
51+
5052
alias extra_args args
5153

5254
def initialize: (?path: untyped?, ?port: untyped?, ?log: untyped?, ?args: untyped?) -> void

rb/sig/lib/selenium/webdriver/edge/service.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Selenium
22
module WebDriver
33
module Edge
44
class Service < WebDriver::Service
5+
DRIVER_PATH_ENV_KEY: String
6+
57
@log: untyped
68

79
DEFAULT_PORT: Integer

rb/sig/lib/selenium/webdriver/firefox/service.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Selenium
44
class Service < WebDriver::Service
55
DEFAULT_PORT: 4444
66

7+
DRIVER_PATH_ENV_KEY: String
78
EXECUTABLE: "geckodriver"
89

910
SHUTDOWN_SUPPORTED: false

0 commit comments

Comments
 (0)