Skip to content

Commit 32262cc

Browse files
committed
Remove legacy Firefox driver from Ruby bindings
Selenium 4 only supports W3C dialect, so legacy Firefox driver should be gone.
1 parent 85a96c4 commit 32262cc

File tree

24 files changed

+101
-778
lines changed

24 files changed

+101
-778
lines changed

rb/build.desc

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ rubygem(
66
"//rb:support",
77
"//rb:edge",
88
"//rb:firefox",
9-
"//rb:ff-esr",
109
"//rb:ie",
1110
"//rb:remote",
1211
"//rb:safari"
@@ -89,29 +88,6 @@ ruby_test(name = "edge",
8988
deps = [ ":edge" ]
9089
)
9190

92-
ruby_library(name = "ff-esr",
93-
srcs = [
94-
"lib/selenium/webdriver/firefox/**/*.rb",
95-
"lib/selenium/webdriver/firefox.rb"
96-
],
97-
resources = [
98-
{ "//third_party/js/selenium:webdriver" : "rb/lib/selenium/webdriver/firefox/extension/webdriver.xpi"},
99-
{ "//third_party/js/selenium:webdriver_prefs" : "rb/lib/selenium/webdriver/firefox/extension/prefs.json" },
100-
{ "//cpp:noblur" : "rb/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so" },
101-
{ "//cpp:noblur64" : "rb/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so" }
102-
],
103-
deps = [":common"]
104-
)
105-
106-
ruby_test(name = "ff-esr",
107-
srcs = [
108-
"spec/integration/selenium/webdriver/*_spec.rb",
109-
"spec/integration/selenium/webdriver/firefox/**/*_spec.rb"
110-
],
111-
include = ["rb/spec/integration", "build/rb/lib"],
112-
deps = [":ff-esr"]
113-
)
114-
11591
ruby_library(name = "firefox",
11692
srcs = [
11793
"lib/selenium/webdriver/firefox/**/*.rb",
@@ -181,19 +157,6 @@ ruby_test(name = "remote-chrome",
181157
":chrome"]
182158
)
183159

184-
ruby_test(name = "remote-ff-esr",
185-
srcs = [
186-
"spec/integration/selenium/webdriver/*_spec.rb",
187-
"spec/integration/selenium/webdriver/firefox/**/*_spec.rb",
188-
"spec/integration/selenium/webdriver/remote/**/*_spec.rb"
189-
],
190-
include = ["rb/spec/integration", "build/rb/lib"],
191-
deps = [
192-
":remote",
193-
":ff-esr"
194-
]
195-
)
196-
197160
ruby_test(name = "remote-firefox",
198161
srcs = [
199162
"spec/integration/selenium/webdriver/*_spec.rb",

rb/lib/selenium/webdriver/firefox.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@
2323

2424
require 'selenium/webdriver/firefox/driver'
2525

26-
require 'selenium/webdriver/firefox/util'
2726
require 'selenium/webdriver/firefox/extension'
2827
require 'selenium/webdriver/firefox/binary'
2928
require 'selenium/webdriver/firefox/profiles_ini'
3029
require 'selenium/webdriver/firefox/profile'
31-
require 'selenium/webdriver/firefox/launcher'
32-
require 'selenium/webdriver/firefox/legacy/driver'
33-
34-
require 'selenium/webdriver/firefox/marionette/bridge'
35-
require 'selenium/webdriver/firefox/marionette/driver'
30+
require 'selenium/webdriver/firefox/bridge'
31+
require 'selenium/webdriver/firefox/driver'
3632
require 'selenium/webdriver/firefox/options'
3733

3834
module Selenium

rb/lib/selenium/webdriver/firefox/binary.rb

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -22,83 +22,6 @@ module WebDriver
2222
module Firefox
2323
# @api private
2424
class Binary
25-
NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'
26-
NO_FOCUS_LIBRARIES = [
27-
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}",
28-
"amd64/#{NO_FOCUS_LIBRARY_NAME}"],
29-
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}",
30-
"x86/#{NO_FOCUS_LIBRARY_NAME}"]
31-
].freeze
32-
33-
WAIT_TIMEOUT = 90
34-
QUIT_TIMEOUT = 5
35-
36-
def start_with(profile, profile_path, *args)
37-
if Platform.cygwin?
38-
profile_path = Platform.cygwin_path(profile_path, windows: true)
39-
elsif Platform.windows?
40-
profile_path = Platform.windows_path(profile_path)
41-
end
42-
43-
ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
44-
ENV['XRE_PROFILE_PATH'] = profile_path
45-
ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
46-
ENV['MOZ_CRASHREPORTER_DISABLE'] = '1' # disable breakpad
47-
ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
48-
49-
modify_link_library_path profile_path if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
50-
51-
execute(*args)
52-
end
53-
54-
def quit
55-
return unless @process
56-
57-
@process.poll_for_exit QUIT_TIMEOUT
58-
rescue ChildProcess::TimeoutError
59-
# ok, force quit
60-
@process.stop QUIT_TIMEOUT
61-
end
62-
63-
def wait
64-
return unless @process
65-
66-
begin
67-
@process.poll_for_exit(WAIT_TIMEOUT)
68-
rescue ChildProcess::TimeoutError => e
69-
@process.stop
70-
raise e
71-
end
72-
end
73-
74-
private
75-
76-
def execute(*extra_args)
77-
args = [self.class.path, '-no-remote'] + extra_args
78-
@process = ChildProcess.build(*args)
79-
WebDriver.logger.debug("Executing Process #{args}")
80-
81-
@process.io.stdout = @process.io.stderr = WebDriver.logger.io if WebDriver.logger.debug?
82-
@process.start
83-
end
84-
85-
def modify_link_library_path(profile_path)
86-
paths = []
87-
88-
NO_FOCUS_LIBRARIES.each do |from, to|
89-
dest = File.join(profile_path, to)
90-
FileUtils.mkdir_p File.dirname(dest)
91-
FileUtils.cp from, dest
92-
93-
paths << File.expand_path(File.dirname(dest))
94-
end
95-
96-
paths += ENV['LD_LIBRARY_PATH'].to_s.split(File::PATH_SEPARATOR)
97-
98-
ENV['LD_LIBRARY_PATH'] = paths.uniq.join(File::PATH_SEPARATOR)
99-
ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
100-
end
101-
10225
class << self
10326
#
10427
# @api private

rb/lib/selenium/webdriver/firefox/util.rb renamed to rb/lib/selenium/webdriver/firefox/bridge.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@
2020
module Selenium
2121
module WebDriver
2222
module Firefox
23-
# @api private
24-
module Util
25-
module_function
23+
module Bridge
2624

27-
def app_data_path
28-
case Platform.os
29-
when :windows
30-
"#{ENV['APPDATA']}\\Mozilla\\Firefox"
31-
when :macosx
32-
"#{Platform.home}/Library/Application Support/Firefox"
33-
when :unix, :linux
34-
"#{Platform.home}/.mozilla/firefox"
35-
else
36-
raise "Unknown os: #{Platform.os}"
37-
end
25+
COMMANDS = {
26+
install_addon: [:post, 'session/:session_id/moz/addon/install'],
27+
uninstall_addon: [:post, 'session/:session_id/moz/addon/uninstall']
28+
}.freeze
29+
30+
def commands(command)
31+
COMMANDS[command] || super
32+
end
33+
34+
def install_addon(path, temporary)
35+
payload = {path: path}
36+
payload[:temporary] = temporary unless temporary.nil?
37+
execute :install_addon, {}, payload
3838
end
3939

40-
def stringified?(str)
41-
str =~ /^".*"$/
40+
def uninstall_addon(id)
41+
execute :uninstall_addon, {}, {id: id}
4242
end
43-
end # Util
43+
44+
end # Bridge
4445
end # Firefox
4546
end # WebDriver
4647
end # Selenium

rb/lib/selenium/webdriver/firefox/driver.rb

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,67 @@
2020
module Selenium
2121
module WebDriver
2222
module Firefox
23-
module Driver
24-
class << self
25-
26-
#
27-
# Instantiates correct Firefox driver implementation
28-
# @return [Marionette::Driver, Legacy::Driver]
29-
#
30-
31-
def new(**opts)
32-
if marionette?(opts)
33-
Firefox::Marionette::Driver.new(opts)
34-
else
35-
Firefox::Legacy::Driver.new(opts)
23+
24+
#
25+
# Driver implementation for Firefox using GeckoDriver.
26+
# @api private
27+
#
28+
29+
class Driver < WebDriver::Driver
30+
include DriverExtensions::HasAddons
31+
include DriverExtensions::HasWebStorage
32+
include DriverExtensions::TakesScreenshot
33+
34+
def initialize(opts = {})
35+
opts[:desired_capabilities] = create_capabilities(opts)
36+
37+
opts[:url] ||= service_url(opts)
38+
39+
listener = opts.delete(:listener)
40+
desired_capabilities = opts.delete(:desired_capabilities)
41+
42+
@bridge = Remote::Bridge.new(opts)
43+
@bridge.extend Bridge
44+
@bridge.create_session(desired_capabilities)
45+
46+
super(@bridge, listener: listener)
47+
end
48+
49+
def browser
50+
:firefox
51+
end
52+
53+
def quit
54+
super
55+
ensure
56+
@service&.stop
57+
end
58+
59+
private
60+
61+
def create_capabilities(opts)
62+
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.firefox }
63+
options = opts.delete(:options) { Options.new }
64+
65+
firefox_options = opts.delete(:firefox_options)
66+
if firefox_options
67+
WebDriver.logger.deprecate ':firefox_options', 'Selenium::WebDriver::Firefox::Options'
68+
firefox_options.each do |key, value|
69+
options.add_option(key, value)
3670
end
3771
end
3872

39-
private
40-
41-
def marionette?(opts)
42-
opts.delete(:marionette) != false && (opts.dig(:desired_capabilities, :marionette) != false)
73+
profile = opts.delete(:profile)
74+
if profile
75+
WebDriver.logger.deprecate ':profile', 'Selenium::WebDriver::Firefox::Options#profile='
76+
options.profile = profile
4377
end
44-
end
4578

79+
options = options.as_json
80+
caps.merge!(options) unless options.empty?
81+
82+
caps
83+
end
4684
end # Driver
4785
end # Firefox
4886
end # WebDriver

0 commit comments

Comments
 (0)