Skip to content

Commit 26fa936

Browse files
committed
Support GeckoDriver addon install/uninstall commands
Adds support for the following commands introduced in GeckoDriver 0.17: * POST /session/{session id}/moz/addon/install * POST /session/{session id}/moz/addon/uninstall For Ruby, implemented as a role-based interface (though I'm not sure it was really needed in this case since it's unlikely that any other driver will ever support these commands). For Python, implemented directly in Firefox webdriver. Tests are missing because all the extension files available for Selenium build (legacy Firefox driver extension, Firebug in third_party) fail to install on latest versions of Firefox. Related to #4215.
1 parent 78d7a3b commit 26fa936

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

py/selenium/webdriver/firefox/remote_connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ def __init__(self, remote_server_addr, keep_alive=True):
2828
("POST", "/session/$sessionId/moz/xbl/$id/anonymous_children")
2929
self._commands["ELEMENT_FIND_ANONYMOUS_ELEMENTS_BY_ATTRIBUTE"] = \
3030
("POST", "/session/$sessionId/moz/xbl/$id/anonymous_by_attribute")
31+
self._commands["INSTALL_ADDON"] = \
32+
("POST", "/session/$sessionId/moz/addon/install")
33+
self._commands["UNINSTALL_ADDON"] = \
34+
("POST", "/session/$sessionId/moz/addon/uninstall")

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,27 @@ def context(self, context):
227227
yield
228228
finally:
229229
self.set_context(initial_context)
230+
231+
def install_addon(self, path, temporary=None):
232+
"""
233+
Installs Firefox addon.
234+
235+
Returns identifier of installed addon. This identifier can later
236+
be used to uninstall addon.
237+
238+
:Usage:
239+
driver.install_addon('firebug.xpi')
240+
"""
241+
payload = {"path": path}
242+
if temporary is not None:
243+
payload["temporary"] = temporary
244+
return self.execute("INSTALL_ADDON", payload)["value"]
245+
246+
def uninstall_addon(self, identifier):
247+
"""
248+
Uninstalls Firefox addon using its identifier.
249+
250+
:Usage:
251+
driver.uninstall_addon('addon@foo.com')
252+
"""
253+
self.execute("UNINSTALL_ADDON", {"id": identifier})

rb/lib/selenium/webdriver/common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
require 'selenium/webdriver/common/driver_extensions/has_remote_status'
6060
require 'selenium/webdriver/common/driver_extensions/has_network_connection'
6161
require 'selenium/webdriver/common/driver_extensions/uploads_files'
62+
require 'selenium/webdriver/common/driver_extensions/has_addons'
6263
require 'selenium/webdriver/common/interactions/interactions'
6364
require 'selenium/webdriver/common/interactions/input_device'
6465
require 'selenium/webdriver/common/interactions/interaction'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# encoding: utf-8
2+
#
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module DriverExtensions
23+
module HasAddons
24+
25+
#
26+
# Installs addon.
27+
#
28+
# @param [String] path Full path to addon file
29+
# @param [Boolean] temporary
30+
# @return [String] identifier of installed addon
31+
#
32+
33+
def install_addon(path, temporary = nil)
34+
@bridge.install_addon(path, temporary)
35+
end
36+
37+
#
38+
# Uninstalls addon.
39+
#
40+
# @param [String] id Identifier of installed addon
41+
#
42+
43+
def uninstall_addon(id)
44+
@bridge.uninstall_addon(id)
45+
end
46+
47+
end # HasAddons
48+
end # DriverExtensions
49+
end # WebDriver
50+
end # Selenium

rb/lib/selenium/webdriver/firefox.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
require 'selenium/webdriver/firefox/launcher'
3232
require 'selenium/webdriver/firefox/legacy/driver'
3333

34+
require 'selenium/webdriver/firefox/marionette/bridge'
3435
require 'selenium/webdriver/firefox/marionette/driver'
3536
require 'selenium/webdriver/firefox/options'
3637
require 'selenium/webdriver/firefox/service'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# encoding: utf-8
2+
#
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
module Selenium
21+
module WebDriver
22+
module Firefox
23+
module Marionette
24+
module Bridge
25+
26+
COMMANDS = {
27+
install_addon: [:post, 'session/:session_id/moz/addon/install'.freeze],
28+
uninstall_addon: [:post, 'session/:session_id/moz/addon/uninstall'.freeze]
29+
}.freeze
30+
31+
def commands(command)
32+
COMMANDS[command] || super
33+
end
34+
35+
def install_addon(path, temporary)
36+
payload = {path: path}
37+
payload.merge!(temporary: temporary) unless temporary.nil?
38+
execute :install_addon, {}, payload
39+
end
40+
41+
def uninstall_addon(id)
42+
execute :uninstall_addon, {}, {id: id}
43+
end
44+
45+
end # Bridge
46+
end # Marionette
47+
end # Firefox
48+
end # WebDriver
49+
end # Selenium

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Marionette
2828
#
2929

3030
class Driver < WebDriver::Driver
31+
include DriverExtensions::HasAddons
3132
include DriverExtensions::HasWebStorage
3233
include DriverExtensions::TakesScreenshot
3334

@@ -55,6 +56,7 @@ def initialize(opts = {})
5556
bridge = Remote::Bridge.new(opts)
5657
capabilities = bridge.create_session(desired_capabilities)
5758
@bridge = Remote::W3C::Bridge.new(capabilities, bridge.session_id, opts)
59+
@bridge.extend Marionette::Bridge
5860

5961
super(@bridge, listener: listener)
6062
end

0 commit comments

Comments
 (0)