Skip to content

Commit 5f641d3

Browse files
committed
[rb] update managing root paths for testing
1 parent c2c41b8 commit 5f641d3

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

rb/lib/selenium/webdriver/common/selenium_manager.rb

+5-11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'bundler'
2021
require 'open3'
2122

2223
module Selenium
@@ -28,12 +29,6 @@ module WebDriver
2829
#
2930
class SeleniumManager
3031
class << self
31-
attr_writer :bin_path
32-
33-
def bin_path
34-
@bin_path ||= '../../../../../bin'
35-
end
36-
3732
# @param [Options] options browser options.
3833
# @return [String] the path to the correct driver.
3934
def driver_path(options)
@@ -76,17 +71,16 @@ def generate_command(binary, options)
7671
def binary
7772
@binary ||= begin
7873
location = ENV.fetch('SE_MANAGER_PATH', begin
79-
directory = File.expand_path(bin_path, __FILE__)
8074
if Platform.windows?
81-
"#{directory}/windows/selenium-manager.exe"
75+
"#{Bundler.root}/bin/windows/selenium-manager.exe"
8276
elsif Platform.mac?
83-
"#{directory}/macos/selenium-manager"
77+
"#{Bundler.root}/bin/macos/selenium-manager"
8478
elsif Platform.linux?
85-
"#{directory}/linux/selenium-manager"
79+
"#{Bundler.root}/bin/linux/selenium-manager"
8680
elsif Platform.unix?
8781
WebDriver.logger.warn('Selenium Manager binary may not be compatible with Unix; verify settings',
8882
id: %i[selenium_manager unix_binary])
89-
"#{directory}/linux/selenium-manager"
83+
"#{Bundler.root}/bin/linux/selenium-manager"
9084
end
9185
rescue Error::WebDriverError => e
9286
raise Error::WebDriverError, "Unable to obtain Selenium Manager binary for #{e.message}"

rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb

+15-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'bundler'
21+
2022
module Selenium
2123
module WebDriver
2224
module SpecSupport
@@ -27,10 +29,17 @@ def initialize
2729
@create_driver_error = nil
2830
@create_driver_error_count = 0
2931

30-
$LOAD_PATH.insert(0, root.join('bazel-bin/rb/lib').to_s) if File.exist?(root.join('bazel-bin/rb/lib'))
31-
WebDriver.logger.ignore(%i[logger_info])
32-
SeleniumManager.bin_path = root.join('bazel-bin/rb/bin').to_s if File.exist?(root.join('bazel-bin/rb/bin'))
33-
32+
bazel_path = Bundler.root.join('bazel-bin/rb/').to_s
33+
$LOAD_PATH.insert(0, "#{bazel_path}/lib").to_s
34+
ENV['SE_MANAGER_PATH'] = if Platform.windows?
35+
"#{bazel_path}/bin/windows/selenium-manager.exe"
36+
elsif Platform.mac?
37+
"#{bazel_path}/bin/macos/selenium-manager"
38+
elsif Platform.linux?
39+
"#{bazel_path}/bin/linux/selenium-manager"
40+
end
41+
42+
WebDriver.logger.ignore(:logger_info)
3443
@driver = ENV.fetch('WD_SPEC_DRIVER', 'chrome').tr('-', '_').to_sym
3544
@driver_instance = nil
3645
@remote_server = nil
@@ -77,7 +86,7 @@ def quit_driver
7786

7887
def app_server
7988
@app_server ||= begin
80-
app_server = RackServer.new(root.join('common/src/web').to_s, random_port)
89+
app_server = RackServer.new(Bundler.root.join('common/src/web').to_s, random_port)
8190
app_server.start
8291

8392
app_server
@@ -108,7 +117,7 @@ def remote_server?
108117
def remote_server_jar
109118
jar = 'java/src/org/openqa/selenium/grid/selenium_server_deploy.jar'
110119
test_jar = Pathname.new(Dir.pwd).join(jar)
111-
built_jar = root.join("bazel-bin/#{jar}")
120+
built_jar = Bundler.root.join("bazel-bin/#{jar}")
112121
jar = if File.exist?(test_jar) && ENV['DOWNLOAD_SERVER'].nil?
113122
test_jar
114123
elsif File.exist?(built_jar) && ENV['DOWNLOAD_SERVER'].nil?
@@ -133,12 +142,6 @@ def url_for(filename)
133142
app_server.where_is filename
134143
end
135144

136-
def root
137-
# prefer #realpath over #expand_path to avoid problems with UNC
138-
# see https://bugs.ruby-lang.org/issues/13515
139-
@root ||= Pathname.new('../../../../../../../').realpath(__FILE__)
140-
end
141-
142145
def create_driver!(listener: nil, **opts, &block)
143146
check_for_previous_error
144147

0 commit comments

Comments
 (0)