Class: Selenium::WebDriver::Firefox::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Firefox::Profile
- Includes:
- ProfileHelper
- Defined in:
- lib/selenium/webdriver/firefox/profile.rb
Constant Summary collapse
- VALID_PREFERENCE_TYPES =
[TrueClass, FalseClass, Integer, Float, String].freeze
- WEBDRIVER_PREFS =
{ port: 'webdriver_firefox_port', log_file: 'webdriver.log.file' }.freeze
- DEFAULT_PREFERENCES =
{ '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 =
%w[.parentlock parent.lock lock].freeze
Instance Attribute Summary collapse
-
#load_no_focus_lib ⇒ Object
writeonly
Sets the attribute load_no_focus_lib.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#secure_ssl ⇒ Object
writeonly
Sets the attribute secure_ssl.
Class Method Summary collapse
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Set a preference for this particular profile.
-
#add_extension(path, name = extension_name_for(path)) ⇒ Object
Add the extension (directory, .zip or .xpi) at the given path to the profile.
-
#initialize(model = nil) ⇒ Profile
constructor
Create a new Profile instance.
- #layout_on_disk ⇒ Object
- #port=(port) ⇒ Object
- #proxy=(proxy) ⇒ Object
Methods included from ProfileHelper
Constructor Details
#initialize(model = nil) ⇒ Profile
Create a new Profile instance
74 75 76 77 78 79 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 74 def initialize(model = nil) @model = verify_model(model) @additional_prefs = read_model_prefs @extensions = {} end |
Instance Attribute Details
#load_no_focus_lib=(value) ⇒ Object (writeonly)
Sets the attribute load_no_focus_lib
43 44 45 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 43 def load_no_focus_lib=(value) @load_no_focus_lib = value end |
#log_file ⇒ Object
Returns the value of attribute log_file.
42 43 44 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 42 def log_file @log_file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
42 43 44 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 42 def name @name end |
#secure_ssl=(value) ⇒ Object (writeonly)
Sets the attribute secure_ssl
43 44 45 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 43 def secure_ssl=(value) @secure_ssl = value end |
Class Method Details
.decoded(json) ⇒ Object
57 58 59 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 57 def decoded(json) JSON.parse(json) end |
.from_name(name) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 50 def from_name(name) profile = ini[name] return profile if profile raise Error::WebDriverError, "unable to find profile named: #{name.inspect}" end |
.ini ⇒ Object
46 47 48 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 46 def ini @ini ||= ProfilesIni.new end |
Instance Method Details
#[]=(key, value) ⇒ Object
Set a preference for this particular profile.
100 101 102 103 104 105 106 107 108 109 110 |
# File '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)) ⇒ Object
Add the extension (directory, .zip or .xpi) at the given path to the profile.
125 126 127 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 125 def add_extension(path, name = extension_name_for(path)) @extensions[name] = Extension.new(path) end |
#layout_on_disk ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File '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 |
#port=(port) ⇒ Object
112 113 114 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 112 def port=(port) self[WEBDRIVER_PREFS[:port]] = port end |
#proxy=(proxy) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File '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 |