Skip to content

Commit 7652b57

Browse files
committed
rb: Allow altering driver path in public API
The commit adds following public accessors: Selenium::WebDriver::Chrome.driver_path Selenium::WebDriver::Edge.driver_path Selenium::WebDriver::Firefox.driver_path (marionette-only) All the previously used Selenium::WebDriver::<browser>::Service.executable_path methods are now deprecated (even though they were part of private API)
1 parent 29fc6d7 commit 7652b57

File tree

10 files changed

+69
-50
lines changed

10 files changed

+69
-50
lines changed

rb/lib/selenium/webdriver/chrome.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,22 @@
2525

2626
module Selenium
2727
module WebDriver
28-
2928
module Chrome
29+
MISSING_TEXT = "Unable to find the chromedriver executable. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver."
30+
3031
def self.driver_path=(path)
31-
Service.executable_path = path
32+
Platform.assert_executable path
33+
@driver_path = path
34+
end
35+
36+
def self.driver_path
37+
@driver_path ||= begin
38+
path = Platform.find_binary("chromedriver")
39+
path or raise Error::WebDriverError, MISSING_TEXT
40+
Platform.assert_executable path
41+
42+
path
43+
end
3244
end
3345

3446
def self.path=(path)

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@ module Chrome
2727

2828
class Service < WebDriver::Service
2929
DEFAULT_PORT = 9515
30-
MISSING_TEXT = "Unable to find the chromedriver executable. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH. More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver."
3130

3231
def self.executable_path
33-
@executable_path ||= (
34-
path = Platform.find_binary "chromedriver"
35-
path or raise Error::WebDriverError, MISSING_TEXT
36-
Platform.assert_executable path
37-
38-
path
39-
)
32+
warn "Selenium::WebDriver::Chrome::Service.executable_path is deprecated, please use Selenium::WebDriver::Chrome.driver_path instead"
33+
Chrome.driver_path
4034
end
4135

4236
def self.default_service(*extra_args)
43-
new executable_path, DEFAULT_PORT, *extra_args
37+
new Chrome.driver_path, DEFAULT_PORT, *extra_args
4438
end
4539

4640
private

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class Service
3737
SOCKET_LOCK_TIMEOUT = 45
3838
STOP_TIMEOUT = 5
3939

40-
def self.executable_path=(path)
41-
Platform.assert_executable path
42-
@executable_path = path
43-
end
44-
4540
def initialize(executable_path, port, *extra_args)
4641
@executable_path = executable_path
4742
@host = Platform.localhost

rb/lib/selenium/webdriver/edge.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@
2424

2525
module Selenium
2626
module WebDriver
27-
2827
module Edge
28+
MISSING_TEXT = "Unable to find MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver."
29+
2930
def self.driver_path=(path)
30-
Service.executable_path = path
31+
Platform.assert_executable path
32+
@driver_path = path
33+
end
34+
35+
def self.driver_path
36+
@driver_path ||= begin
37+
path = Platform.find_binary("MicrosoftWebDriver")
38+
path or raise Error::WebDriverError, MISSING_TEXT
39+
Platform.assert_executable path
40+
41+
path
42+
end
3143
end
3244

3345
def self.path=(path)

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ module Edge
2626
#
2727

2828
class Service
29-
DEFAULT_PORT = 17556
30-
MISSING_TEXT = "Unable to find MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver."
29+
DEFAULT_PORT = 17556
3130

3231
def self.executable_path
33-
@executable_path ||= (
34-
path = Platform.find_binary "MicrosoftWebDriver"
35-
path or raise Error::WebDriverError, MISSING_TEXT
36-
Platform.assert_executable path
37-
38-
path
39-
)
32+
warn "Selenium::WebDriver::Edge::Service.executable_path is deprecated, please use Selenium::WebDriver::Edge.driver_path instead"
33+
Edge.driver_path
4034
end
4135

4236
def self.default_service(*extra_args)
43-
new executable_path, DEFAULT_PORT, *extra_args
37+
new Edge.driver_path, DEFAULT_PORT, *extra_args
4438
end
4539

4640
private

rb/lib/selenium/webdriver/firefox.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,29 @@
3535
module Selenium
3636
module WebDriver
3737
module Firefox
38-
3938
DEFAULT_PORT = 7055
4039
DEFAULT_ENABLE_NATIVE_EVENTS = Platform.os == :windows
4140
DEFAULT_SECURE_SSL = false
4241
DEFAULT_ASSUME_UNTRUSTED_ISSUER = true
4342
DEFAULT_LOAD_NO_FOCUS_LIB = false
4443

44+
MISSING_TEXT = "Unable to find Mozilla Wires. Please download the executable from https://github.com/jgraham/wires/releases"
45+
46+
def self.driver_path=(path)
47+
Platform.assert_executable path
48+
@driver_path = path
49+
end
50+
51+
def self.driver_path
52+
@driver_path ||= begin
53+
path = Platform.find_binary("wires")
54+
path or raise Error::WebDriverError, MISSING_TEXT
55+
Platform.assert_executable path
56+
57+
path
58+
end
59+
end
60+
4561
def self.path=(path)
4662
Binary.path = path
4763
end

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@ module Firefox
2727

2828
class Service < WebDriver::Service
2929
DEFAULT_PORT = 4444
30-
MISSING_TEXT = "Unable to find Mozilla Wires. Please download the executable from https://github.com/jgraham/wires/releases"
3130

3231
def self.executable_path
33-
@executable_path ||= (
34-
path = Platform.find_binary "wires"
35-
path or raise Error::WebDriverError, MISSING_TEXT
36-
Platform.assert_executable path
37-
38-
path
39-
)
32+
warn "Selenium::WebDriver::Firefox::Service.executable_path is deprecated, please use Selenium::WebDriver::Firefox.driver_path instead"
33+
Firefox.driver_path
4034
end
4135

4236
def self.default_service(*extra_args)
43-
new executable_path, DEFAULT_PORT, *extra_args
37+
new Firefox.driver_path, DEFAULT_PORT, *extra_args
4438
end
4539

4640
private

rb/lib/selenium/webdriver/phantomjs.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@
2424

2525
module Selenium
2626
module WebDriver
27-
2827
module PhantomJS
28+
MISSING_TEXT = "Unable to find phantomjs executable."
2929

3030
def self.path=(path)
3131
Platform.assert_executable path
3232
@path = path
3333
end
3434

3535
def self.path
36-
@path ||= Platform.find_binary("phantomjs")
36+
@path ||= begin
37+
path = Platform.find_binary("phantomjs")
38+
path or raise Error::WebDriverError, MISSING_TEXT
39+
Platform.assert_executable path
40+
41+
path
42+
end
3743
end
3844

3945
end # PhantomJS

rb/lib/selenium/webdriver/phantomjs/bridge.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ module Selenium
2121
module WebDriver
2222
module PhantomJS
2323

24-
24+
#
2525
# @api private
26+
#
27+
2628
class Bridge < Remote::Bridge
2729

2830
def initialize(opts = {})

rb/lib/selenium/webdriver/phantomjs/service.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@ module PhantomJS
2727

2828
class Service < WebDriver::Service
2929
DEFAULT_PORT = 8910
30-
MISSING_TEXT = "Unable to find phantomjs executable."
3130

3231
def self.executable_path
33-
@executable_path ||= (
34-
path = PhantomJS.path
35-
path or raise Error::WebDriverError, MISSING_TEXT
36-
Platform.assert_executable path
37-
38-
path
39-
)
32+
warn "Selenium::WebDriver::PhantomJS::Service.executable_path is deprecated, please use Selenium::WebDriver::PhantomJS.path instead"
33+
PhantomJS.path
4034
end
4135

4236
def self.default_service(*extra_args)
43-
new executable_path, DEFAULT_PORT, *extra_args
37+
new PhantomJS.path, DEFAULT_PORT, *extra_args
4438
end
4539

4640
private

0 commit comments

Comments
 (0)