Skip to content

Commit

Permalink
[rb] support sending firefox addon directory as temporary in remote s…
Browse files Browse the repository at this point in the history
…ession
  • Loading branch information
TamsilAmani authored and titusfortner committed Sep 13, 2022
1 parent 45e4e29 commit ba0a025
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion rb/lib/selenium/webdriver/firefox/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# specific language governing permissions and limitations
# under the License.

require 'zip'

module Selenium
module WebDriver
module Firefox
Expand All @@ -35,7 +37,23 @@ def commands(command)
end

def install_addon(path, temporary)
addon = File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
if File.directory?(path)
zip = "#{path}.zip"
# Delete zip file if it already exists
File.delete(zip) if File.file?(zip)

Zip::File.open(zip, Zip::File::CREATE) do |z_file|
Dir[File.join(path, "**", "**")].each do |file|
z_file.add(file.sub("#{path}/", ""), file)
end
end

addon = File.open(zip, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
# Delete the zip file
File.delete(zip)
else
addon = File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
end

payload = {addon: addon}
payload[:temporary] = temporary unless temporary.nil?
Expand Down
6 changes: 6 additions & 0 deletions rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module WebDriver
module Firefox
describe Driver, exclusive: {browser: :firefox} do
let(:extension) { '../../../../../../third_party/firebug/favourite_colour-1.1-an+fx.xpi' }
let(:extension_dir) { '../../../../../../common/extensions/webextensions-selenium-example' }

describe '#print_options' do
let(:magic_number) { 'JVBER' }
Expand Down Expand Up @@ -74,6 +75,11 @@ module Firefox
ext = File.expand_path(extension, __dir__)
driver.install_addon(ext, true)
end

it 'with path as unpacked directory' do
ext = File.expand_path(extension_dir, __dir__)
driver.install_addon(ext, true)
end
end

describe '#uninstall_addon' do
Expand Down

0 comments on commit ba0a025

Please sign in to comment.