Skip to content

Commit

Permalink
Remove legacy Firefox driver from Ruby bindings
Browse files Browse the repository at this point in the history
Selenium 4 only supports W3C dialect, so legacy Firefox driver should be
gone.
  • Loading branch information
p0deje committed Jan 10, 2019
1 parent 139900b commit b1a8627
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 782 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,12 @@ matrix:
- env: MARIONETTE=1 TASK=//rb:firefox-test
<<: *ruby
<<: *firefox-latest
- env: TASK=//rb:ff-esr-test
<<: *ruby
<<: *firefox-esr
- env: CHROME=1 TASK=//rb:remote-chrome-test
<<: *ruby
<<: *chrome
- env: MARIONETTE=1 TASK=//rb:remote-firefox-test
<<: *ruby
<<: *firefox-latest
- env: TASK=//rb:remote-ff-esr-test
<<: *ruby
<<: *firefox-esr
- env: TASK=//rb:docs
<<: *ruby
- env: TASK=//rb:lint
Expand Down
37 changes: 0 additions & 37 deletions rb/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ rubygem(
"//rb:support",
"//rb:edge",
"//rb:firefox",
"//rb:ff-esr",
"//rb:ie",
"//rb:remote",
"//rb:safari"
Expand Down Expand Up @@ -89,29 +88,6 @@ ruby_test(name = "edge",
deps = [ ":edge" ]
)

ruby_library(name = "ff-esr",
srcs = [
"lib/selenium/webdriver/firefox/**/*.rb",
"lib/selenium/webdriver/firefox.rb"
],
resources = [
{ "//third_party/js/selenium:webdriver" : "rb/lib/selenium/webdriver/firefox/extension/webdriver.xpi"},
{ "//third_party/js/selenium:webdriver_prefs" : "rb/lib/selenium/webdriver/firefox/extension/prefs.json" },
{ "//cpp:noblur" : "rb/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so" },
{ "//cpp:noblur64" : "rb/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so" }
],
deps = [":common"]
)

ruby_test(name = "ff-esr",
srcs = [
"spec/integration/selenium/webdriver/*_spec.rb",
"spec/integration/selenium/webdriver/firefox/**/*_spec.rb"
],
include = ["rb/spec/integration", "build/rb/lib"],
deps = [":ff-esr"]
)

ruby_library(name = "firefox",
srcs = [
"lib/selenium/webdriver/firefox/**/*.rb",
Expand Down Expand Up @@ -181,19 +157,6 @@ ruby_test(name = "remote-chrome",
":chrome"]
)

ruby_test(name = "remote-ff-esr",
srcs = [
"spec/integration/selenium/webdriver/*_spec.rb",
"spec/integration/selenium/webdriver/firefox/**/*_spec.rb",
"spec/integration/selenium/webdriver/remote/**/*_spec.rb"
],
include = ["rb/spec/integration", "build/rb/lib"],
deps = [
":remote",
":ff-esr"
]
)

ruby_test(name = "remote-firefox",
srcs = [
"spec/integration/selenium/webdriver/*_spec.rb",
Expand Down
8 changes: 2 additions & 6 deletions rb/lib/selenium/webdriver/firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@

require 'selenium/webdriver/firefox/driver'

require 'selenium/webdriver/firefox/util'
require 'selenium/webdriver/firefox/extension'
require 'selenium/webdriver/firefox/binary'
require 'selenium/webdriver/firefox/profiles_ini'
require 'selenium/webdriver/firefox/profile'
require 'selenium/webdriver/firefox/launcher'
require 'selenium/webdriver/firefox/legacy/driver'

require 'selenium/webdriver/firefox/marionette/bridge'
require 'selenium/webdriver/firefox/marionette/driver'
require 'selenium/webdriver/firefox/bridge'
require 'selenium/webdriver/firefox/driver'
require 'selenium/webdriver/firefox/options'
require 'selenium/webdriver/firefox/service'

Expand Down
78 changes: 0 additions & 78 deletions rb/lib/selenium/webdriver/firefox/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,84 +20,6 @@ module WebDriver
module Firefox
# @api private
class Binary
NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'.freeze
NO_FOCUS_LIBRARIES = [
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}",
"amd64/#{NO_FOCUS_LIBRARY_NAME}"],
["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}",
"x86/#{NO_FOCUS_LIBRARY_NAME}"]
].freeze

WAIT_TIMEOUT = 90
QUIT_TIMEOUT = 5

def start_with(profile, profile_path, *args)
if Platform.cygwin?
profile_path = Platform.cygwin_path(profile_path, windows: true)
elsif Platform.windows?
profile_path = Platform.windows_path(profile_path)
end

ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
ENV['XRE_PROFILE_PATH'] = profile_path
ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
ENV['MOZ_CRASHREPORTER_DISABLE'] = '1' # disable breakpad
ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console

if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
modify_link_library_path profile_path
end

execute(*args)
end

def quit
return unless @process
@process.poll_for_exit QUIT_TIMEOUT
rescue ChildProcess::TimeoutError
# ok, force quit
@process.stop QUIT_TIMEOUT
end

def wait
return unless @process

begin
@process.poll_for_exit(WAIT_TIMEOUT)
rescue ChildProcess::TimeoutError => e
@process.stop
raise e
end
end

private

def execute(*extra_args)
args = [self.class.path, '-no-remote'] + extra_args
@process = ChildProcess.build(*args)
WebDriver.logger.debug("Executing Process #{args}")

@process.io.stdout = @process.io.stderr = WebDriver.logger.io if WebDriver.logger.debug?
@process.start
end

def modify_link_library_path(profile_path)
paths = []

NO_FOCUS_LIBRARIES.each do |from, to|
dest = File.join(profile_path, to)
FileUtils.mkdir_p File.dirname(dest)
FileUtils.cp from, dest

paths << File.expand_path(File.dirname(dest))
end

paths += ENV['LD_LIBRARY_PATH'].to_s.split(File::PATH_SEPARATOR)

ENV['LD_LIBRARY_PATH'] = paths.uniq.join(File::PATH_SEPARATOR)
ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
end

class << self
#
# @api private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@
module Selenium
module WebDriver
module Firefox
# @api private
module Util
module_function
module Bridge

def app_data_path
case Platform.os
when :windows
"#{ENV['APPDATA']}\\Mozilla\\Firefox"
when :macosx
"#{Platform.home}/Library/Application Support/Firefox"
when :unix, :linux
"#{Platform.home}/.mozilla/firefox"
else
raise "Unknown os: #{Platform.os}"
end
COMMANDS = {
install_addon: [:post, 'session/:session_id/moz/addon/install'.freeze],
uninstall_addon: [:post, 'session/:session_id/moz/addon/uninstall'.freeze]
}.freeze

def commands(command)
COMMANDS[command] || super
end

def install_addon(path, temporary)
payload = {path: path}
payload[:temporary] = temporary unless temporary.nil?
execute :install_addon, {}, payload
end

def stringified?(str)
str =~ /^".*"$/
def uninstall_addon(id)
execute :uninstall_addon, {}, {id: id}
end
end # Util

end # Bridge
end # Firefox
end # WebDriver
end # Selenium
83 changes: 64 additions & 19 deletions rb/lib/selenium/webdriver/firefox/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,75 @@
module Selenium
module WebDriver
module Firefox
module Driver
class << self

#
# Instantiates correct Firefox driver implementation
# @return [Marionette::Driver, Legacy::Driver]
#

def new(**opts)
if marionette?(opts)
Firefox::Marionette::Driver.new(opts)
else
Firefox::Legacy::Driver.new(opts)
end
end

private
#
# Driver implementation for Firefox using GeckoDriver.
# @api private
#

class Driver < WebDriver::Driver
include DriverExtensions::HasAddons
include DriverExtensions::HasWebStorage
include DriverExtensions::TakesScreenshot

def marionette?(opts)
opts.delete(:marionette) != false &&
(!opts[:desired_capabilities] || opts[:desired_capabilities][:marionette] != false)
def initialize(opts = {})
opts[:desired_capabilities] = create_capabilities(opts)

unless opts.key?(:url)
driver_path = opts.delete(:driver_path) || Firefox.driver_path
driver_opts = opts.delete(:driver_opts) || {}
port = opts.delete(:port) || Service::DEFAULT_PORT

@service = Service.new(driver_path, port, driver_opts)
@service.start
opts[:url] = @service.uri
end

listener = opts.delete(:listener)
desired_capabilities = opts.delete(:desired_capabilities)

@bridge = Remote::Bridge.new(opts)
@bridge.extend Bridge
@bridge.create_session(desired_capabilities)

super(@bridge, listener: listener)
end

def browser
:firefox
end

def quit
super
ensure
@service&.stop
end

private

def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.firefox }
options = opts.delete(:options) { Options.new }

firefox_options = opts.delete(:firefox_options)
if firefox_options
WebDriver.logger.deprecate ':firefox_options', 'Selenium::WebDriver::Firefox::Options'
firefox_options.each do |key, value|
options.add_option(key, value)
end
end

profile = opts.delete(:profile)
if profile
WebDriver.logger.deprecate ':profile', 'Selenium::WebDriver::Firefox::Options#profile='
options.profile = profile
end

options = options.as_json
caps.merge!(options) unless options.empty?

caps
end
end # Driver
end # Firefox
end # WebDriver
Expand Down
Loading

0 comments on commit b1a8627

Please sign in to comment.