Best Selenium code snippet using Selenium.WebDriver.Firefox.add_extension
browser.rb
Source:browser.rb
...111 profile.log_file = browser_log_file_path("firefox")112 profile['network.cookie.cookieBehavior'] = 2 if @disable_cookies113 if ExecutionEnvironment::Features.noscript?114 untrusted = %w(bazaarvoice.com)115 profile.add_extension("vendor/firefox_extensions/noscript.xpi")116 profile["noscript.ABE.migration"] = 1117 profile["noscript.global"] = true118 profile["noscript.gtemp"] = ""119 profile["noscript.temp"] = ""120 profile["noscript.untrusted"] = untrusted.map { |domain| [domain, "http://#{domain}", "https://#{domain}"] }.flatten.join(' ')121 profile["noscript.version"] = "2.6.8.19"122 profile["noscript.visibleUIChecked"] = true123 Log.instance.debug "Running with 'noscript' plugin. Untrusted domains: #{untrusted}"124 end125 if ExecutionEnvironment::Features.akamai?126 profile.add_extension('vendor/firefox_extensions/modify_headers-0.7.1.1-fx.xpi', 'modifyheaders')127 profile.add_extension('vendor/firefox_extensions/firebug-2.0.4-fx.xpi', 'firebug')128 profile.add_extension('vendor/firefox_extensions/netExport-0.9b6.xpi', 'netexport')129 profile['modifyheaders.config.active'] = true130 profile['modifyheaders.config.alwaysOn'] = true131 profile['modifyheaders.config.openNewTab'] = true132 profile['modifyheaders.start'] = true133 headers = 'akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no, akamai-x-cache-remote-on'134 profile['modifyheaders.headers.count'] = 1135 profile['modifyheaders.headers.action0'] = 'Add'136 profile['modifyheaders.headers.name0'] = 'Pragma'137 profile['modifyheaders.headers.value0'] = headers138 profile['modifyheaders.headers.enabled0'] = true139 profile['extensions.firebug.currentVersion'] = '2.0.4'140 profile['extensions.firebug.addonBarOpened'] = true141 profile['extensions.firebug.console.enableSites'] = true142 profile['extensions.firebug.script.enableSites'] = true143 profile['extensions.firebug.net.enableSites'] = true144 profile['extensions.firebug.previousPlacement'] = 1145 profile['extensions.firebug.allPagesActivation'] = 'on'146 profile['extensions.firebug.onByDefault'] = true147 profile['extensions.firebug.defaultPanelName'] = 'net'148 profile['extensions.firebug.netexport.alwaysEnableAutoExport'] = true149 profile['extensions.firebug.netexport.autoExportToFile'] = true150 profile['extensions.firebug.netexport.Automation'] = true151 profile['extensions.firebug.netexport.showPreview'] = false152 profile['extensions.firebug.netexport.includeResponseBodies'] = false153 profile['extensions.firebug.netexport.secretToken'] = 'macys'154 if ExecutionEnvironment.host_os == :windows155 profile['extensions.firebug.netexport.defaultLogDir'] = ExecutionEnvironment.log_directory.gsub('/','\\')156 else157 profile['extensions.firebug.netexport.defaultLogDir'] = ExecutionEnvironment.log_directory158 end159 end160 profile.proxy = start_proxy if ExecutionEnvironment.proxy_enabled?161 profile.add_extension('vendor/firefox_extensions/JSErrorCollector.xpi')162 if ExecutionEnvironment.digital_analytics_enabled?('plugin')163 profile.add_extension("vendor/firefox_extensions/coremetricstools@coremetrics.xpi")164 end165 Selenium::WebDriver.for :firefox, :profile => profile166 else167 caps = Selenium::WebDriver::Remote::Capabilities.firefox(common_capabilities)168 Selenium::WebDriver.for(:remote, :url => ExecutionEnvironment.selenium_grid_hub, :desired_capabilities => caps)169 end170 end171 def setup_chrome172 unless ExecutionEnvironment.selenium_grid_hub.nil?173 caps = Selenium::WebDriver::Remote::Capabilities.chrome(common_capabilities)174 return Selenium::WebDriver.for :remote, :url => ExecutionEnvironment.selenium_grid_hub, :desired_capabilities => caps175 end176 if ExecutionEnvironment::Features.akamai?177 extensions = "--load-extension=#{Dir.getwd}/vendor/chrome_extensions/HTTP_Spy/,#{Dir.getwd}/vendor/chrome_extensions/Modify_Headers/"...
profile.rb
Source:profile.rb
...89 self[WEBDRIVER_PREFS[:log_file]] = file90 end91 def add_webdriver_extension92 unless @extensions.has_key?(:webdriver)93 add_extension(WEBDRIVER_EXTENSION_PATH, :webdriver)94 end95 end96 #97 # Add the extension (directory, .zip or .xpi) at the given path to the profile.98 #99 def add_extension(path, name = extension_name_for(path))100 @extensions[name] = Extension.new(path)101 end102 def native_events?103 @native_events == true104 end105 def load_no_focus_lib?106 @load_no_focus_lib == true107 end108 def secure_ssl?109 @secure_ssl == true110 end111 def assume_untrusted_certificate_issuer?112 @untrusted_issuer == true113 end...
env.rb
Source:env.rb
...10 profile['browser.download.manager.closeWhenDone'] = true11 profile['browser.startup.homepage_override.mstone'] = 'ignore'12 profile['browser.helperApps.neverAsk.saveToDisk'] = "text/plain;application/csv;text/csv;application/vnd.ms-excel;application/octet-stream;application/x-msdos-program;application/x-apple-diskimage;application/x-debian-package;application/x-redhat-package-manager;image/png"13 profile.assume_untrusted_certificate_issuer = false14 profile.add_extension("#{FileHelper.default_test_data_path}/hostadmin-1.4.9.2-fx.xpi")15 profile.add_extension("#{FileHelper.default_test_data_path}/empty_cache_button-2.7-fx.xpi")16 #profile.native_events = true17 profile18end19Capybara.register_driver :firefox do |app|20 Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => firefox_profile)21end22Capybara.register_driver :firefox_profile do |app|23 profile_address = "#{FileHelper.default_test_data_path}/#{CONFIGS['global']['profile_name']}"24 profile = Selenium::WebDriver::Firefox::Profile.new profile_address25 profile.add_extension("#{FileHelper.default_test_data_path}/autoauth-2.1-fx+fn.xpi")26 Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)27end28Capybara.register_driver :firefox_debug do |app|29 profile = Selenium::WebDriver::Firefox::Profile.new30 profile.add_extension("#{FileHelper.default_test_data_path}/firebug-2.0.9-fx.xpi")31 profile['browser.startup.homepage_override.mstone'] = 'ignore'32 profile["extensions.firebug.console.enableSites"] = true33 profile["extensions.firebug.net.enableSites"] = true34 profile["extensions.firebug.script.enableSites"] = true35 profile["extensions.firebug.cookies.enableSites"] = true36 profile["extensions.firebug.allPagesActivation"] = "on"37 profile["extensions.firebug.currentVersion"] = "2.0.9"38 Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)39end40def chrome_prefs41 prefs = {42 :download => {43 :prompt_for_download => false,44 :default_directory => FileHelper.ff_download_path...
driver_config.rb
Source:driver_config.rb
...9 #puts "Launching driver for firefox.........................."10 ENV['IS_UPA'] = "false" if ENV['IS_UPA'].nil?11 if ENV['IS_UPA']=="true"12 profile = Selenium::WebDriver::Firefox::Profile.new13 profile.add_extension("./data/har/firebug-2.0.13.xpi")14 profile.add_extension("./data/har/netExport-0.8.xpi")15 profile['extensions.firebug.allPagesActivation'] = "on"16 profile['extensions.firebug.defaultPanelName'] = "net"17 profile['extensions.firebug.net.enableSites'] = "true"18 profile['extensions.firebug.showFirstRunPage'] = "false"19 profile['extensions.firebug.netexport.alwaysEnableAutoExport'] = "true"20 profile['extensions.firebug.netexport.showPreview'] = "false"21 profile['extensions.firebug.netexport.defaultLogDir'] = File.absolute_path("./reports/upa")22 profile['extensions.firebug.netexport.defaultFileName'] = "upaReport.har"23 profile['extensions.firebug.netexport.jsonpCallback'] = "jsonCallback";24 @driver = Selenium::WebDriver.for :firefox, :profile => profile25 else26 @driver = Selenium::WebDriver.for :firefox27 end28 @driver.manage.timeouts.implicit_wait = 30...
taza_brower.rb
Source:taza_brower.rb
...46 #driver.manage.timeouts.page_load = 12047 browser = Watir::Browser.new driver48 elsif ENV['BROWSER'] == 'firefox'49 profile = add_firefox_download_directory(params[:profile])50 profile.add_extension File.expand_path("../../../../google/tools/extensions/firebug-1.11.2.xpi", __FILE__)51 profile.add_extension File.expand_path("../../../../google/tools/extensions/JSErrorCollector.xpi", __FILE__)52 profile['extensions.firebug.currentVersion'] = "1.9.2"53 browser = Watir::Browser.new params[:browser], :profile => profile54 else55 browser = Watir::Browser.new params[:browser]56 end57 browser58 end59 def self.add_chrome_download_directory(profile)60 custom_profile = profile.nil? ? Selenium::WebDriver::Chrome::Profile.new : profile61 custom_profile["download.default_directory"] = custom_profile["download.default_directory"] rescue File.expand_path("../onyx-automation/temp")62 custom_profile["download.prompt_for_download"] = false63 custom_profile64 end65 def self.add_firefox_download_directory(profile)...
ff_lzy.rb
Source:ff_lzy.rb
...7# https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings8#profile = Selenium::WebDriver::Firefox::Profile.new9#capabilities = Selenium::WebDriver::Remote::Capabilities.firefox10#capabilities['firefox.page.customHeaders.Accept-Language'] = 'zh-CN,zh;q=0.9'11#profile.add_extension('./headereditor.xpi')12##profile['browser.download.dir'] = 'C:\Users\Administrator\Downloads'13#profile['browser.download.dir'] = './'14#profile['browser.download.folderList'] = 215##profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/pdf'16#profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/zip'17#browser = Watir::Browser.new :firefox, profile: profile, desired_capabilities: capabilities18#browser = Watir::Browser.new :firefox, profile: 'default-release' 19#options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless', "-profile", "/home/lsq/.mozilla/firefox/3hxb38kg.lsq"])20# options = Selenium::WebDriver::Firefox::Options.new(args: ["-profile", "/home/lsq/.mozilla/firefox/3hxb38kg.lsq"])21# browser = Watir::Browser.new :firefox, options: options22################# test in windows can load extension ############23################ use firefox -p ###################24# browser = Watir::Browser.new :firefox, profile: 'lsq'25# browser = Watir::Browser.new :firefox, options: options
...
firefox.rb
Source:firefox.rb
...9 puts "=>=>=> Your HAR (UPA) files will be created here : #{ENV['HAR_DIR']}"10 firebug = File.absolute_path(File.dirname(__FILE__)+"/../../data/firebug-2.0.13.xpi")11 net_export = File.absolute_path(File.dirname(__FILE__)+"/../../data/netExport-0.8.xpi")12 profile = Selenium::WebDriver::Firefox::Profile.new13 profile.add_extension(firebug)14 profile.add_extension(net_export)15 profile['extensions.firebug.currentVersion'] = "2.0.13"16 profile['extensions.firebug.allPagesActivation'] = "on"17 profile['extensions.firebug.defaultPanelName'] = "net"18 profile['extensions.firebug.net.enableSites'] = "true"19 profile['extensions.firebug.netexport.alwaysEnableAutoExport'] = "true"20 profile['extensions.firebug.netexport.showPreview'] = "false"21 profile['extensions.firebug.netexport.defaultLogDir'] = ENV['HAR_DIR'].to_s22 profile['extensions.firebug.netexport.defaultFileName'] = "upaReport.har"23 profile['extensions.firebug.netexport.jsonpCallback'] = "jsonCallback"24 driver = Selenium::WebDriver.for(:firefox, :profile => profile, :desired_cpabilities => caps)25 else26 driver = Selenium::WebDriver.for(:firefox, :desired_cpabilities => caps)27 end28 driver.manage.timeouts.implicit_wait = 30...
browser_profiles.rb
Source:browser_profiles.rb
...3 def self.firefox_profile(uses_native_events=false)4 profile = Selenium::WebDriver::Firefox::Profile.new5 profile.secure_ssl=CONFIG.secure_ssl6 profile.assume_untrusted_certificate_issuer=CONFIG.untrust_ssl_cert7 profile.add_extension(File.dirname(__FILE__) + '/extensions/firebug-1.10.2.xpi')8 profile['extensions.firebug.currentVersion'] = '1.10.2' #Load without start page9 profile.native_events = uses_native_events10 profile11 end12 def self.firefox_with_proxy_profile(uses_native_events=false)13 profile = Selenium::WebDriver::Firefox::Profile.new14 profile.secure_ssl=CONFIG.secure_ssl15 profile.assume_untrusted_certificate_issuer=CONFIG.untrust_ssl_cert16 profile.add_extension(File.dirname(__FILE__) + '/extensions/firebug-1.10.2.xpi')17 profile['extensions.firebug.currentVersion'] = '1.10.2' #Load without start page18 profile.native_events = uses_native_events19 profile20 end21 def self.chrome_profile22 profile = Selenium::WebDriver::Chrome::Profile.new23 profile['download.prompt_for_download'] = false24 profile['download.default_directory'] = File.join("#{ENV['DOWNLOADS_DIR']}" || "#{REPO_ROOT}", 'tmp_downloads')25 profile26 end27 def self.chrome_with_ad_block_profile28 profile = Selenium::WebDriver::Chrome::Profile.new29 profile['download.prompt_for_download'] = false30 profile['download.default_directory'] = File.join("#{ENV["DOWNLOADS_DIR"]}" || "#{REPO_ROOT}", 'tmp_downloads')31 profile.add_extension(File.dirname(__FILE__) + '/extensions/AdBlock_v2.5.61.crx')32 profile33 end34 end#BrowserProfiles35end#AutomationFramework...
add_extension
Using AI Code Generation
1profile.add_extension('/path/to/extension.xpi')2profile.add_extension('/path/to/extension.xpi')3profile.add_extension('/path/to/extension.xpi')4profile.add_extension('/path/to/extension.xpi')
add_extension
Using AI Code Generation
1driver.add_extension('C:\Users\Kamal\Downloads\firebug-1.12.8-fx.xpi')2driver.add_extension('C:\Users\Kamal\Downloads\firebug-1.12.8-fx.xpi')3driver.add_extension('C:\Users\Kamal\Downloads\firebug-1.12.8-fx.xpi')4driver.add_extension('C:\Users\Kamal\Downloads\firebug-1.12.8-fx.xpi')5caps.add_extension('C:\Users\Kamal\Downloads\firebug-1.12.8-fx.xpi')6caps.add_extension('C:\Users\Kamal\Downloads\firebug-1.12.8-fx.xpi')
add_extension
Using AI Code Generation
1profile.add_extension("c:/path/to/extension.xpi")2profile.add_extension("c:/path/to/extension.xpi")3profile.add_extension("c:/path/to/extension.xpi")4profile.add_extension("c:/path/to/extension.xpi")5profile.add_extension("c:/path/to/extension.xpi")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!