[フレーム]

Class: Selenium::WebDriver::Firefox::Profile

Inherits:
Object
  • Object
  • Selenium::WebDriver::Firefox::Profile
show all
Defined in:
lib/selenium/webdriver/firefox/profile.rb

Constant Summary collapse

ANONYMOUS_PROFILE_NAME =
"WEBDRIVER_ANONYMOUS_PROFILE"
EXTENSION_NAME =
"[email protected] "
EM_NAMESPACE_URI =
"http://www.mozilla.org/2004/em-rdf#"
WEBDRIVER_EXTENSION_PATH =
File.expand_path("#{WebDriver .root }/selenium/webdriver/firefox/extension/webdriver.xpi")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory = nil) ⇒ Profile

Create a new Profile instance

Examples:

User configured profile


profile = Selenium ::WebDriver ::Firefox ::Profile .new
profile['network.proxy.http'] = 'localhost'
profile['network.proxy.http_port'] = 9090
driver = Selenium ::WebDriver .for  :firefox, :profile => profile
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/selenium/webdriver/firefox/profile.rb', line 37
def initialize(directory = nil)
 @directory = directory ? create_tmp_copy(directory) : Dir .mktmpdir ("webdriver-profile")
 unless File.directory? @directory
 raise Error ::WebDriverError , "Profile directory does not exist: #{@directory.inspect}"
 end
 FileReaper  << @directory
 # TODO: replace constants with options hash
 @port = DEFAULT_PORT 
 @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 = {}
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.

11
12
13
# File 'lib/selenium/webdriver/firefox/profile.rb', line 11
def directory
 @directory
end

#load_no_focus_lib=(value) ⇒ Object (writeonly)

Sets the attribute load_no_focus_lib

Parameters:

  • value

    the value to set the attribute load_no_focus_lib to.

12
13
14
# File 'lib/selenium/webdriver/firefox/profile.rb', line 12
def load_no_focus_lib=(value)
 @load_no_focus_lib = value
end

#nameObject (readonly)

Returns the value of attribute name.

11
12
13
# File 'lib/selenium/webdriver/firefox/profile.rb', line 11
def name
 @name
end

#native_events=(value) ⇒ Object (writeonly)

Sets the attribute native_events

Parameters:

  • value

    the value to set the attribute native_events to.

12
13
14
# File 'lib/selenium/webdriver/firefox/profile.rb', line 12
def native_events=(value)
 @native_events = value
end

#portObject

Returns the value of attribute port.

13
14
15
# File 'lib/selenium/webdriver/firefox/profile.rb', line 13
def port
 @port
end

#secure_ssl=(value) ⇒ Object (writeonly)

Sets the attribute secure_ssl

Parameters:

  • value

    the value to set the attribute secure_ssl to.

12
13
14
# File 'lib/selenium/webdriver/firefox/profile.rb', line 12
def secure_ssl=(value)
 @secure_ssl = value
end

Class Method Details

.from_name(name) ⇒ Object

20
21
22
# File 'lib/selenium/webdriver/firefox/profile.rb', line 20
def from_name(name)
 ini[name]
end

.iniObject

16
17
18
# File 'lib/selenium/webdriver/firefox/profile.rb', line 16
def ini
 @ini ||= ProfilesIni .new 
end

Instance Method Details

#[]=(key, value) ⇒ Object

Set a preference for this particular profile.

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/selenium/webdriver/firefox/profile.rb', line 61
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

#absolute_pathObject

78
79
80
81
82
83
84
# File 'lib/selenium/webdriver/firefox/profile.rb', line 78
def absolute_path
 if Platform .win? 
 directory.gsub("/", "\\")
 else
 directory
 end
end

#add_extension(path) ⇒ Object

Aadd the extension (directory, .zip or .xpi) at the given path to the profile.

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/selenium/webdriver/firefox/profile.rb', line 119
def add_extension(path)
 unless File.exist?(path)
 raise Error ::WebDriverError , "could not find extension at #{path.inspect}"
 end
 if File.directory? path
 root  = path
 else
 unless %w[.zip.xpi].include? File.extname(path)
 raise Error ::WebDriverError , "expected .zip or .xpi extension, got #{path.inspect}"
 end
 root  = ZipHelper .unzip (path)
 end
 ext_path = File.join extensions_dir, read_id_from_install_rdf(root )
 FileUtils.rm_rf ext_path
 FileUtils.mkdir_p File.dirname(ext_path), :mode => 0700
 FileUtils.cp_r root , ext_path
end

#add_webdriver_extension(force_creation = false) ⇒ Object

104
105
106
107
108
109
110
111
112
113
# File 'lib/selenium/webdriver/firefox/profile.rb', line 104
def add_webdriver_extension(force_creation = false)
 ext_path = File.join(extensions_dir, EXTENSION_NAME )
 if File.exists? ext_path
 return unless force_creation
 end
 add_extension WEBDRIVER_EXTENSION_PATH 
 delete_extensions_cache
end

#assume_untrusted_certificate_issuer=(bool) ⇒ Object

170
171
172
# File 'lib/selenium/webdriver/firefox/profile.rb', line 170
def assume_untrusted_certificate_issuer=(bool)
 @untrusted_issuer = bool
end

#assume_untrusted_certificate_issuer?Boolean

Returns:

  • (Boolean)
166
167
168
# File 'lib/selenium/webdriver/firefox/profile.rb', line 166
def assume_untrusted_certificate_issuer?
 @untrusted_issuer == true
end

#delete_extensions_cacheObject

149
150
151
152
# File 'lib/selenium/webdriver/firefox/profile.rb', line 149
def delete_extensions_cache
 cache = File.join(directory, "extensions.cache")
 FileUtils.rm_f cache if File.exist?(cache)
end

#extensions_dirObject

141
142
143
# File 'lib/selenium/webdriver/firefox/profile.rb', line 141
def extensions_dir
 @extensions_dir ||= File.join(directory, "extensions")
end

#load_no_focus_lib?Boolean

Returns:

  • (Boolean)
158
159
160
# File 'lib/selenium/webdriver/firefox/profile.rb', line 158
def load_no_focus_lib?
 @load_no_focus_lib == true
end

#native_events?Boolean

Returns:

  • (Boolean)
154
155
156
# File 'lib/selenium/webdriver/firefox/profile.rb', line 154
def native_events?
 @native_events == true
end

#secure_ssl?Boolean

Returns:

  • (Boolean)
162
163
164
# File 'lib/selenium/webdriver/firefox/profile.rb', line 162
def secure_ssl?
 @secure_ssl == true
end

#update_user_prefsObject

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/selenium/webdriver/firefox/profile.rb', line 86
def update_user_prefs
 prefs = current_user_prefs
 prefs.merge! OVERRIDABLE_PREFERENCES
 prefs.merge! @additional_prefs
 prefs.merge! DEFAULT_PREFERENCES
 prefs['webdriver_firefox_port'] = @port
 prefs['webdriver_accept_untrusted_certs'] = !secure_ssl?
 prefs['webdriver_enable_native_events'] = native_events?
 prefs['webdriver_assume_untrusted_issuer'] = assume_untrusted_certificate_issuer?
 # 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
end

#user_prefs_pathObject

145
146
147
# File 'lib/selenium/webdriver/firefox/profile.rb', line 145
def user_prefs_path
 @user_prefs_path ||= File.join(directory, "user.js")
end

AltStyle によって変換されたページ (->オリジナル) /