File tree Expand file tree Collapse file tree
lib/selenium/webdriver/firefox
spec/integration/selenium/webdriver/firefox Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717# specific language governing permissions and limitations
1818# under the License.
1919
20+ require 'zip'
21+
2022module 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?
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments