How to use add_preference method of Selenium.WebDriver.Firefox Package

Best Selenium code snippet using Selenium.WebDriver.Firefox.add_preference

driver_test.rb

Source:driver_test.rb Github

copy

Full Screen

...46 test "define extra capabilities using chrome" do47 driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :chrome) do |option|48 option.add_argument("start-maximized")49 option.add_emulation(device_name: "iphone 6")50 option.add_preference(:detach, true)51 end52 driver.use53 browser_options = driver.__send__(:browser_options)54 expected = {55 "goog:chromeOptions" => {56 "args" => ["start-maximized"],57 "mobileEmulation" => { "deviceName" => "iphone 6" },58 "prefs" => { "detach" => true }59 },60 "browserName" => "chrome"61 }62 assert_equal expected, browser_options[:options].as_json63 end64 test "define extra capabilities using headless_chrome" do65 driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :headless_chrome) do |option|66 option.add_argument("start-maximized")67 option.add_emulation(device_name: "iphone 6")68 option.add_preference(:detach, true)69 end70 driver.use71 browser_options = driver.__send__(:browser_options)72 expected = {73 "goog:chromeOptions" => {74 "args" => ["--headless", "start-maximized"],75 "mobileEmulation" => { "deviceName" => "iphone 6" },76 "prefs" => { "detach" => true }77 },78 "browserName" => "chrome"79 }80 assert_equal expected, browser_options[:options].as_json81 end82 test "define extra capabilities using firefox" do83 driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :firefox) do |option|84 option.add_preference("browser.startup.homepage", "http://www.seleniumhq.com/")85 option.add_argument("--host=127.0.0.1")86 end87 driver.use88 browser_options = driver.__send__(:browser_options)89 expected = {90 "moz:firefoxOptions" => {91 "args" => ["--host=127.0.0.1"],92 "prefs" => { "browser.startup.homepage" => "http://www.seleniumhq.com/" }93 },94 "browserName" => "firefox"95 }96 assert_equal expected, browser_options[:options].as_json97 end98 test "define extra capabilities using headless_firefox" do99 driver = ActionDispatch::SystemTesting::Driver.new(:selenium, screen_size: [1400, 1400], using: :headless_firefox) do |option|100 option.add_preference("browser.startup.homepage", "http://www.seleniumhq.com/")101 option.add_argument("--host=127.0.0.1")102 end103 driver.use104 browser_options = driver.__send__(:browser_options)105 expected = {106 "moz:firefoxOptions" => {107 "args" => ["-headless", "--host=127.0.0.1"],108 "prefs" => { "browser.startup.homepage" => "http://www.seleniumhq.com/" }109 },110 "browserName" => "firefox"111 }112 assert_equal expected, browser_options[:options].as_json113 end114 test "does not define extra capabilities" do...

Full Screen

Full Screen

options.rb

Source:options.rb Github

copy

Full Screen

...73 # Add a preference that is only applied to the user profile in use.74 #75 # @example Set the default homepage76 # options = Selenium::WebDriver::Firefox::Options.new77 # options.add_preference('browser.startup.homepage', 'http://www.seleniumhq.com/')78 #79 # @param [String] name Key of the preference80 # @param [Boolean, String, Integer] value Value of the preference81 #82 def add_preference(name, value)83 prefs[name] = value84 end85 #86 # Run Firefox in headless mode.87 #88 # @example Enable headless mode89 # options = Selenium::WebDriver::Firefox::Options.new90 # options.headless!91 #92 def headless!93 add_argument '-headless'94 end95 #96 # Sets Firefox profile....

Full Screen

Full Screen

webdriver_run.rb

Source:webdriver_run.rb Github

copy

Full Screen

...42 end43 elsif %i[firefox firefox_headless].include? TestBench.browser44 Webdrivers::Geckodriver.update45 options = Selenium::WebDriver::Firefox::Options.new46 options.add_preference("download.prompt_for_download", false)47 options.add_preference("profile.content_settings.exceptions.automatic_downloads.*.setting", 1)48 options.add_preference("profile.content_settings.popups", 0)49 options.add_preference("browser.download.dir", DownloadHelper.path)50 options.add_preference("browser.download.folderList", 2)51 options.add_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv,text/tsv,application/pdf,application/doc,application/docx,image/jpeg,application/octet-stream doc xls pdf txt")52 # profile.native_events = true53 if TestBench.browser == :firefox54 puts "Using Firefox"55 else56 puts "Using Firefox Headless"57 options.headless!58 end59 Capybara::Selenium::Driver.new(60 app,61 browser: :firefox,62 http_client: client,63 options: options,64 )65 end...

Full Screen

Full Screen

retrieveList.rb

Source:retrieveList.rb Github

copy

Full Screen

...27 def configure_capybara(app_host)28 Capybara.register_driver :golden do |app|29 # The new way will be something like this30 ###options = Selenium::WebDriver::Firefox::Options.new31 ###options.add_preference('browser.download.folderList', 2) # magic number32 ###options.add_preference('browser.download.dir', download_dir)33 ###options.add_preference('browser.helperApps.neverAsk.saveToDisk',34 ### 'text/plain, application/octet-stream')35 ###Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)36 #### That last line does not work as hoped37 # This way is deprecated in lib/selenium/webdriver/firefox/marionette/driver.rb38 # but still works39 # You can view the list of Firefox preferences by typing "about:config"40 # into the Firefox address bar41 # Much web searching and experimentation yields these settings42 profile = Selenium::WebDriver::Firefox::Profile.new43 profile['browser.download.folderList'] = 2 # magic number44 profile['browser.download.dir'] = download_dir45 profile['browser.download.useDownloadDir'] = true46 profile['browser.helperApps.neverAsk.saveToDisk'] =47 'text/plain, application/octet-stream'...

Full Screen

Full Screen

web.rb

Source:web.rb Github

copy

Full Screen

...8Capybara.register_driver :firefox do |app|9 profile = Selenium::WebDriver::Firefox::Profile.new10 profile['general.useragent.override'] = user_agent11 options = Selenium::WebDriver::Firefox::Options.new12 options.add_preference 'dom.webdriver.enabled', false13 options.add_preference 'dom.webnotifications.enabled', false14 options.add_preference 'dom.push.enabled', false15 options.profile = profile16 client = Selenium::WebDriver::Remote::Http::Default.new17 client.open_timeout = wait_time18 client.read_timeout = wait_time19 Capybara::Selenium::Driver.new(20 app,21 browser: :firefox,22 options: options,23 http_client: client24 )25end26Capybara.register_driver :chrome do |app|27 options = Selenium::WebDriver::Chrome::Options.new28 options.add_argument("--user-agent=#{user_agent}")...

Full Screen

Full Screen

portal_env.rb

Source:portal_env.rb Github

copy

Full Screen

...43 # options = Selenium::WebDriver::Ie::Options.new44 # options = Selenium::WebDriver::Edge::Options.new45 # options = Selenium::WebDriver::Safari::Options.new46 # options.add_argument('--headless') # configure the driver to run in headless mode47 options.add_preference('profile.managed_default_content_settings.notifications', 1)48 options.add_preference('profile.managed_default_content_settings.cookies', 1)49 options.add_preference('profile.managed_default_content_settings.plugins', 1)50 options.add_preference('profile.managed_default_content_settings.geolocation', 1)51 options.add_preference('profile.managed_default_content_settings.images', 1)52 options.add_preference('profile.managed_default_content_settings.media_stream', 1)53 options.add_preference('profile.managed_default_content_settings.popups', 1)54 $web_driver = Selenium::WebDriver.for :chrome, options: options55 #$web_driver = Selenium::WebDriver.for :firefox, options: options, prefs: preferences56 # $web_driver = Selenium::WebDriver.for :ie, options: options, prefs: preferences57 # $web_driver = Selenium::WebDriver.for :edge, options: options, prefs: preferences58 # $web_driver = Selenium::WebDriver.for :safari, options: options, prefs: preferences59 $web_driver.manage.timeouts.page_load = 36060 $web_driver.manage.window.maximize61 Selenium::WebDriver::Wait.new(timeout: 10)62 $web_driver.manage.timeouts.implicit_wait = 1063 $web_driver.navigate.to "https://#{ENV['HOST']}.hi.guru/"64 $web_driver.navigate.to "https://google.com/"65end...

Full Screen

Full Screen

fuckcisco.rb

Source:fuckcisco.rb Github

copy

Full Screen

...18 profile['browser.download.folderList'] = 219 profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/vnd.debian.binary-package, application/zip, binary/octet-stream'20 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)21 options.add_argument('--headless')22 options.add_preference('download.directory_upgrade', true)23 options.add_preference('download.folderList', 2)24 options.add_preference('download.prompt_for_download', false)25 options.add_preference('download.dir', DIR)26 options.add_preference('download.default_directory', DIR)27 options.add_preference('browser.helperApps.neverAsk.saveToDisk', 'application/vnd.debian.binary-package, application/zip, binary/octet-stream')28 29 @dr = Selenium::WebDriver.for :firefox, capabilities: options30 @cred = JSON.parse(File.read('./credentials.json'))31 @dr.navigate.to URL 32 end33 def wait34 Selenium::WebDriver::Wait.new(:timeout => 60)35 end36 37 def run38 puts "logging in."39 email = wait.until { @dr.find_element(:id => EMAIL_FIELD_ID) }40 submit = wait.until { @dr.find_element(:id => EMAIL_SUBMIT_ID) }41 email.send_keys @cred["email"]...

Full Screen

Full Screen

env.rb

Source:env.rb Github

copy

Full Screen

...26puts "Browser : #{browser}"27Capybara.register_driver :firefox do |app|28 profile = Selenium::WebDriver::Firefox::Profile.new29 options = Selenium::WebDriver::Firefox::Options.new30 options.add_preference 'dom.webdriver.enabled', false31 options.add_preference 'dom.webnotifications.enabled', false32 options.add_preference 'dom.push.enabled', false33 options.profile = profile34 client = Selenium::WebDriver::Remote::Http::Default.new35 client.open_timeout = wait_time36 client.read_timeout = wait_time37 Capybara::Selenium::Driver.new(38 app,39 browser: :firefox,40 options: options,41 http_client: client42 )43end44Capybara.register_driver :chrome do |app|45 options = Selenium::WebDriver::Chrome::Options.new46 options.add_argument('--no-sandbox')...

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1profile.add_preference('browser.startup.homepage', 'http://www.google.com')2profile.add_preference('startup.homepage_welcome_url', 'http://www.google.com')3profile.add_preference('startup.homepage_welcome_url.additional', 'http://www.google.com')4profile.add_extension("FireBug-1.6.1.xpi")5profile.set_preference('browser.startup.homepage', 'http://www.google.com')6profile.set_preference('startup.homepage_welcome_url', 'http://www.google.com')7profile.set_preference('startup.homepage_welcome_url.additional', 'http://www.google.com')8profile.set_proxy(:http => 'proxy.example.com:8080', :ftp => 'proxy.example.com:8080')9profile.set_proxy(:http => 'proxy.example.com:8080', :ftp => 'proxy.example.com:8080')

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1profile.add_extension File.join(Dir.pwd, "1.xpi")2profile.add_certificate File.join(Dir.pwd, "1.pem"), "1"3profile.add_encoded_extension File.read(File.join(Dir.pwd, "1.xpi"))

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1driver.add_preference("browser.startup.homepage", "http://www.google.com")2driver.add_preference("browser.startup.page", 1)3binary = Selenium::WebDriver::Firefox::Binary.new("/usr/bin/firefox")4binary = Selenium::WebDriver::Firefox::Binary.new("/usr/bin/firefox")

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1driver.manage.add_cookie(:name => "cookie1", :value => "value1")2driver.manage.add_cookie(:name => "cookie2", :value => "value2")3{:name=>"cookie1", :value=>"value1", :path=>"/", :domain=>"www.google.com", :expires=>nil, :secure=>false}4{:name=>"cookie2", :value=>"value2", :path=>"/", :domain=>"www.google.com", :expires=>nil, :secure=>false}5driver.manage.delete_cookie(name)6driver.manage.add_cookie(:name => "cookie1", :value => "value1")7driver.manage.add_cookie(:name => "cookie2", :value => "value2")8driver.manage.delete_cookie("cookie1")9{:name=>"cookie1", :value=>"value1", :path=>"/", :domain=>"www.google.com", :expires=>nil, :secure=>false}10{:name=>"cookie2", :value=>"value2", :path=>"/", :domain=>"www.google.com", :expires=>nil, :secure=>false}11{:name=>"cookie2", :value=>"value2", :path=>"/", :domain=>"www.google.com", :expires=>nil, :secure=>false}

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2element = driver.find_element(:name, 'q')3element = driver.find_element(:name, 'q')

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1profile.add_preference('browser.startup.homepage', 'http://www.google.com')2profile.add_preference('browser.startup.homepage_override.mstone', 'ignore')3driver = Selenium::WebDriver.for(:firefox, :profile => profile)4profile.add_extension('C:\path\to\extension.xpi')5driver = Selenium::WebDriver.for(:firefox, :profile => profile)6profile.add_certificate('C:\path\to\certificate.pem')7driver = Selenium::WebDriver.for(:firefox, :profile => profile)8profile.set_proxy(:http => 'server:port',9driver = Selenium::WebDriver.for(:firefox, :profile => profile)

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1fp.add_preference('network.proxy.type', 1)2fp.add_preference('network.proxy.http', 'proxy.example.com')3fp.add_preference('network.proxy.http_port', 8080)4fp.add_extension('/path/to/extension.xpi')5element = driver.find_element(:name, 'q')6element = driver.find_element(:name, 'q')

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1profile.add_preference('browser.startup.homepage', 'http://www.google.com')2profile.add_preference('browser.startup.homepage_override.mstone', 'ignore')3driver = Selenium::WebDriver.for(:firefox, :profile => profile)4profile.add_extension('C:\path\to\extension.xpi')5driver = Selenium::WebDriver.for(:firefox, :profile => profile)6profile.add_certificate('C:\path\to\certificate.pem')7driver = Selenium::WebDriver.for(:firefox, :profile => profile)8profile.set_proxy(:http => 'server:port',9driver = Selenium::WebDriver.for(:firefox, :profile => profile)

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1fp.add_preference('network.proxy.type', 1)2fp.add_preference('network.proxy.http', 'proxy.example.com')3fp.add_preference('network.proxy.http_port', 8080)4fp.add_extension('/path/to/extension.xpi')

Full Screen

Full Screen

add_preference

Using AI Code Generation

copy

Full Screen

1fp.add_preference('network.proxy.type', 1)2fp.add_preference('network.proxy.http', 'proxy.example.com')3fp.add_preference('network.proxy.http_port', 8080)4fp.add_extension('/path/to/extension.xpi')

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful