Class: Selenium::WebDriver::Firefox::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Firefox::Profile
show all
- Includes:
- ProfileHelper
- Defined in:
- lib/selenium/webdriver/firefox/profile.rb
Constant Summary
collapse
- VALID_PREFERENCE_TYPES =
[TrueClass, FalseClass, Integer, Float, String].freeze
- WEBDRIVER_EXTENSION_PATH =
File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/webdriver.xpi")
- WEBDRIVER_PREFS =
{
native_events: 'webdriver_enable_native_events',
untrusted_certs: 'webdriver_accept_untrusted_certs',
untrusted_issuer: 'webdriver_assume_untrusted_issuer',
port: 'webdriver_firefox_port',
log_file: 'webdriver.log.file'
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#as_json, included, #to_json
Constructor Details
#initialize(model = nil) ⇒ Profile
Create a new Profile instance
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 70
def initialize(model = nil)
@model = verify_model(model)
model_prefs = read_model_prefs
if model_prefs.empty?
@native_events = DEFAULT_ENABLE_NATIVE_EVENTS
@secure_ssl = DEFAULT_SECURE_SSL
@untrusted_issuer = DEFAULT_ASSUME_UNTRUSTED_ISSUER
@load_no_focus_lib = DEFAULT_LOAD_NO_FOCUS_LIB
@additional_prefs = {}
else
@native_events = model_prefs.delete(WEBDRIVER_PREFS[:native_events]) == 'true'
@secure_ssl = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_certs]) != 'true'
@untrusted_issuer = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_issuer]) == 'true'
@load_no_focus_lib = model_prefs.delete(WEBDRIVER_PREFS[:load_no_focus_lib]) == 'true'
@additional_prefs = model_prefs
end
@extensions = {}
end
|
Instance Attribute Details
#load_no_focus_lib=(value) ⇒ Object
Sets the attribute load_no_focus_lib
37
38
39
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 37
def load_no_focus_lib=(value)
@load_no_focus_lib = value
end
|
#log_file ⇒ Object
Returns the value of attribute log_file.
36
37
38
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 36
def log_file
@log_file
end
|
#name ⇒ Object
Returns the value of attribute name.
36
37
38
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 36
def name
@name
end
|
#native_events=(value) ⇒ Object
Sets the attribute native_events
37
38
39
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 37
def native_events=(value)
@native_events = value
end
|
#secure_ssl=(value) ⇒ Object
Sets the attribute secure_ssl
37
38
39
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 37
def secure_ssl=(value)
@secure_ssl = value
end
|
Class Method Details
.default_preferences ⇒ Object
51
52
53
54
55
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 51
def default_preferences
@default_preferences ||= JSON.parse(
File.read(File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/prefs.json"))
).freeze
end
|
.from_name(name) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 44
def from_name(name)
profile = ini[name]
return profile if profile
raise Error::WebDriverError, "unable to find profile named: #{name.inspect}"
end
|
.ini ⇒ Object
40
41
42
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 40
def ini
@ini ||= ProfilesIni.new
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
Set a preference for this particular profile.
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 114
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.
145
146
147
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 145
def add_extension(path, name = extension_name_for(path))
@extensions[name] = Extension.new(path)
end
|
#add_webdriver_extension ⇒ Object
135
136
137
138
139
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 135
def add_webdriver_extension
return if @extensions.key?(:webdriver)
add_extension(WEBDRIVER_EXTENSION_PATH, :webdriver)
end
|
#assume_untrusted_certificate_issuer=(bool) ⇒ Object
165
166
167
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 165
def assume_untrusted_certificate_issuer=(bool)
@untrusted_issuer = bool
end
|
#assume_untrusted_certificate_issuer? ⇒ Boolean
161
162
163
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 161
def assume_untrusted_certificate_issuer?
@untrusted_issuer == true
end
|
#encoded ⇒ Object
192
193
194
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 192
def encoded
Zipper.zip(layout_on_disk)
end
|
#layout_on_disk ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 95
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
|
#load_no_focus_lib? ⇒ Boolean
153
154
155
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 153
def load_no_focus_lib?
@load_no_focus_lib == true
end
|
#native_events? ⇒ Boolean
149
150
151
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 149
def native_events?
@native_events == true
end
|
#port=(port) ⇒ Object
126
127
128
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 126
def port=(port)
self[WEBDRIVER_PREFS[:port]] = port
end
|
#proxy=(proxy) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 169
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? ⇒ Boolean
157
158
159
|
# File 'lib/selenium/webdriver/firefox/profile.rb', line 157
def secure_ssl?
@secure_ssl == true
end
|