Class: Selenium::WebDriver::Firefox::Profile
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/firefox/profile.rb |
Constant Summary
-
DEFAULT_PREFERENCES =
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 32{ 'browser.newtabpage.enabled' => false, 'browser.startup.homepage' => 'about:blank', 'browser.usedOnWindows10.introURL' => 'about:blank', 'network.captive-portal-service.enabled' => false, 'security.csp.enable' => false }.freeze
-
LOCK_FILES =
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 40%w[.parentlock parent.lock lock].freeze
-
VALID_PREFERENCE_TYPES =
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 26[TrueClass, FalseClass, Integer, Float, String].freeze
-
WEBDRIVER_PREFS =
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 27{ port: 'webdriver_firefox_port', log_file: 'webdriver.log.file' }.freeze
Class Method Summary
- .decoded(json)
- .from_name(name)
- .ini
-
.new(model = nil) ⇒ Profile
constructor
Create a new
Profile
instance.
Instance Attribute Summary
- #load_no_focus_lib=(value) writeonly
- #log_file rw
- #log_file=(file) rw
- #name readonly
- #port=(port) writeonly
- #proxy=(proxy) writeonly
- #secure_ssl=(value) writeonly
Instance Method Summary
-
#[]=(key, value)
Set a preference for this particular profile.
-
#add_extension(path, name = extension_name_for(path))
Add the extension (directory,
.zip
or.xpi
) at the given path to the profile. - #as_json
- #layout_on_disk
- #delete_extensions_cache(directory) private
- #delete_lock_files(directory) private
- #extension_name_for(path) private
- #install_extensions(directory) private
- #read_model_prefs private
- #read_user_prefs(path) private
- #set_manual_proxy_preference(key, value) private
- #update_user_prefs_in(directory) private
- #write_prefs(prefs, path) private
::Selenium::WebDriver::ProfileHelper
- Included
Constructor Details
.new(model = nil) ⇒ Profile
Create a new Profile
instance
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 74
def initialize(model = nil) @model = verify_model(model) @additional_prefs = read_model_prefs @extensions = {} end
Class Method Details
.decoded(json)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 57
def decoded(json) JSON.parse(json) end
.from_name(name)
.ini
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 46
def ini @ini ||= ProfilesIni.new end
Instance Attribute Details
#load_no_focus_lib=(value) (writeonly)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 43
attr_writer :secure_ssl, :load_no_focus_lib
#log_file (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 42
attr_reader :name, :log_file
#log_file=(file) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 116
def log_file=(file) @log_file = file self[WEBDRIVER_PREFS[:log_file]] = file end
#name (readonly)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 42
attr_reader :name, :log_file
#port=(port) (writeonly)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 112
def port=(port) self[WEBDRIVER_PREFS[:port]] = port end
#proxy=(proxy) (writeonly)
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 129
def proxy=(proxy) raise TypeError, "expected #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}" unless proxy.is_a? Proxy case proxy.type when :manual self['network.proxy.type'] = 1 set_manual_proxy_preference 'ftp', proxy.ftp set_manual_proxy_preference 'http', proxy.http set_manual_proxy_preference 'ssl', proxy.ssl set_manual_proxy_preference 'socks', proxy.socks self['network.proxy.no_proxies_on'] = proxy.no_proxy || '' when :pac self['network.proxy.type'] = 2 self['network.proxy.autoconfig_url'] = proxy.pac when :auto_detect self['network.proxy.type'] = 4 else raise ArgumentError, "unsupported proxy type #{proxy.type}" end end
#secure_ssl=(value) (writeonly)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 43
attr_writer :secure_ssl, :load_no_focus_lib
Instance Method Details
#[]=(key, value)
Set a preference for this particular profile.
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 100
def []=(key, value) unless VALID_PREFERENCE_TYPES.any? { |e| value.is_a? e } raise TypeError, "expected one of #{VALID_PREFERENCE_TYPES.inspect}, got #{value.inspect}:#{value.class}" end if value.is_a?(String) && Util.stringified?(value) raise ArgumentError, "preference values must be plain strings: #{key.inspect} => #{value.inspect}" end @additional_prefs[key.to_s] = value end
#add_extension(path, name = extension_name_for(path))
Add the extension (directory, .zip
or .xpi
) at the given path to the profile.
#as_json
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 152
alias as_json encoded
#delete_extensions_cache(directory) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 180
def delete_extensions_cache(directory) FileUtils.rm_f File.join(directory, 'extensions.cache') end
#delete_lock_files(directory) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 184
def delete_lock_files(directory) LOCK_FILES.each do |name| FileUtils.rm_f File.join(directory, name) end end
#extension_name_for(path) (private)
[ GitHub ]#install_extensions(directory) (private)
[ GitHub ]#layout_on_disk
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 81
def layout_on_disk profile_dir = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-profile') FileReaper << profile_dir install_extensions(profile_dir) delete_lock_files(profile_dir) delete_extensions_cache(profile_dir) update_user_prefs_in(profile_dir) profile_dir end
#read_model_prefs (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 174
def read_model_prefs return {} unless @model read_user_prefs(File.join(@model, 'user.js')) end
#read_user_prefs(path) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 206
def read_user_prefs(path) prefs = {} return prefs unless File.exist?(path) File.read(path).split("\n").each do |line| next unless line =~ /user_pref\("([^"])"\s*,\s*(.?)\);/ key = Regexp.last_match(1)&.strip value = Regexp.last_match(2)&.strip # wrap the value in an array to make it a valid JSON string. prefs[key] = JSON.parse("[#{value}]").first end prefs end
#set_manual_proxy_preference(key, value) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 156
def set_manual_proxy_preference(key, value) return unless value host, port = value.to_s.split(':', 2) self["network.proxy.#{key}"] = host self["network.proxy.#{key}_port"] = Integer(port) if port end
#update_user_prefs_in(directory) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 194
def update_user_prefs_in(directory) path = File.join(directory, 'user.js') prefs = read_user_prefs(path) prefs.merge! self.class::DEFAULT_PREFERENCES prefs.merge!(@additional_prefs) # If the user sets the home page, we should also start up there prefs['startup.homepage_welcome_url'] ||= prefs['browser.startup.homepage'] write_prefs prefs, path end