Class: Selenium::WebDriver::Firefox::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Firefox::Profile
- Defined in:
- lib/selenium/webdriver/firefox/profile.rb
Constant Summary collapse
- ANONYMOUS_PROFILE_NAME =
"WEBDRIVER_ANONYMOUS_PROFILE"
- EXTENSION_NAME =
"[email protected]"
- WEBDRIVER_EXTENSION_PATH =
File.("#{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' }
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.
-
#native_events ⇒ Object
writeonly
Sets the attribute native_events.
-
#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.
- #add_webdriver_extension ⇒ Object
- #as_json(opts = nil) ⇒ Object
- #assume_untrusted_certificate_issuer=(bool) ⇒ Object
- #assume_untrusted_certificate_issuer? ⇒ Boolean
-
#initialize(model = nil) ⇒ Profile
constructor
Create a new Profile instance.
- #layout_on_disk ⇒ Object
- #load_no_focus_lib? ⇒ Boolean
- #native_events? ⇒ Boolean
- #port=(port) ⇒ Object
- #secure_ssl? ⇒ Boolean
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(model = nil) ⇒ Profile
Create a new Profile instance
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 42 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 else @native_events = model_prefs[WEBDRIVER_PREFS[:native_events]] == "true" @secure_ssl = model_prefs[WEBDRIVER_PREFS[:untrusted_certs]] != "true" # FIXME: 'untrusted_certs' vs 'secure_ssl' @untrusted_issuer = model_prefs[WEBDRIVER_PREFS[:untrusted_issuer]] == "true" @load_no_focus_lib = model_prefs[WEBDRIVER_PREFS[:load_no_focus_lib]] == "true" # not stored in profile atm, so will always be false. end @additional_prefs = {} @extensions = {} end |
Instance Attribute Details
#load_no_focus_lib=(value) ⇒ Object (writeonly)
Sets the attribute load_no_focus_lib
18 19 20 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 18 def load_no_focus_lib=(value) @load_no_focus_lib = value end |
#log_file ⇒ Object
Returns the value of attribute log_file.
17 18 19 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 17 def log_file @log_file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 17 def name @name end |
#native_events=(value) ⇒ Object (writeonly)
Sets the attribute native_events
18 19 20 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 18 def native_events=(value) @native_events = value end |
#secure_ssl=(value) ⇒ Object (writeonly)
Sets the attribute secure_ssl
18 19 20 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 18 def secure_ssl=(value) @secure_ssl = value end |
Class Method Details
.from_json(json) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 83 def self.from_json(json) zip_file = Tempfile.new("webdriver-profile-duplicate-#{json.hash}") zip_file << JSON.parse(json)['zip'].unpack("m")[0] zip_file.close new(Zipper.unzip(zip_file.path)) ensure zip_file.delete if zip_file end |
.from_name(name) ⇒ Object
25 26 27 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 25 def from_name(name) ini[name] end |
.ini ⇒ Object
21 22 23 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 21 def ini @ini ||= ProfilesIni.new end |
Instance Method Details
#[]=(key, value) ⇒ Object
Set a preference for this particular profile.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 99 def []=(key, value) case value when String if Util.stringified?(value) raise ArgumentError, "preference values must be plain strings: #{key.inspect} => #{value.inspect}" end value = %{"#{value}"} when TrueClass, FalseClass, Integer, Float value = value.to_s else raise TypeError, "invalid preference: #{value.inspect}:#{value.class}" 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.
135 136 137 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 135 def add_extension(path, name = extension_name_for(path)) @extensions[name] = Extension.new(path) end |
#add_webdriver_extension ⇒ Object
125 126 127 128 129 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 125 def add_webdriver_extension unless @extensions.has_key?(:webdriver) add_extension(WEBDRIVER_EXTENSION_PATH, :webdriver) end end |
#as_json(opts = nil) ⇒ Object
75 76 77 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 75 def as_json(opts = nil) {'zip' => Zipper.zip(layout_on_disk)} end |
#assume_untrusted_certificate_issuer=(bool) ⇒ Object
155 156 157 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 155 def assume_untrusted_certificate_issuer=(bool) @untrusted_issuer = bool end |
#assume_untrusted_certificate_issuer? ⇒ Boolean
151 152 153 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 151 def assume_untrusted_certificate_issuer? @untrusted_issuer == true end |
#layout_on_disk ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 63 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
143 144 145 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 143 def load_no_focus_lib? @load_no_focus_lib == true end |
#native_events? ⇒ Boolean
139 140 141 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 139 def native_events? @native_events == true end |
#port=(port) ⇒ Object
116 117 118 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 116 def port=(port) self[WEBDRIVER_PREFS[:port]] = port end |
#secure_ssl? ⇒ Boolean
147 148 149 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 147 def secure_ssl? @secure_ssl == true end |
#to_json(*args) ⇒ Object
79 80 81 |
# File 'lib/selenium/webdriver/firefox/profile.rb', line 79 def to_json(*args) as_json.to_json(*args) end |