Skip to content

Commit ba0a025

Browse files
TamsilAmanititusfortner
authored andcommitted
[rb] support sending firefox addon directory as temporary in remote session
1 parent 45e4e29 commit ba0a025

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

rb/lib/selenium/webdriver/firefox/features.rb

Lines changed: 19 additions & 1 deletion
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 'zip'
21+
2022
module Selenium
2123
module WebDriver
2224
module Firefox
@@ -35,7 +37,23 @@ def commands(command)
3537
end
3638

3739
def install_addon(path, temporary)
38-
addon = File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
40+
if File.directory?(path)
41+
zip = "#{path}.zip"
42+
# Delete zip file if it already exists
43+
File.delete(zip) if File.file?(zip)
44+
45+
Zip::File.open(zip, Zip::File::CREATE) do |z_file|
46+
Dir[File.join(path, "**", "**")].each do |file|
47+
z_file.add(file.sub("#{path}/", ""), file)
48+
end
49+
end
50+
51+
addon = File.open(zip, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
52+
# Delete the zip file
53+
File.delete(zip)
54+
else
55+
addon = File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
56+
end
3957

4058
payload = {addon: addon}
4159
payload[:temporary] = temporary unless temporary.nil?

rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module WebDriver
2424
module Firefox
2525
describe Driver, exclusive: {browser: :firefox} do
2626
let(:extension) { '../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi' }
27+
let(:extension_dir) { '../../../../../../common/extensions/webextensions-selenium-example' }
2728

2829
describe '#print_options' do
2930
let(:magic_number) { 'JVBER' }
@@ -74,6 +75,11 @@ module Firefox
7475
ext = File.expand_path(extension, __dir__)
7576
driver.install_addon(ext, true)
7677
end
78+
79+
it 'with path as unpacked directory' do
80+
ext = File.expand_path(extension_dir, __dir__)
81+
driver.install_addon(ext, true)
82+
end
7783
end
7884

7985
describe '#uninstall_addon' do

0 commit comments

Comments
 (0)