Class: Selenium::WebDriver::Chrome::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Chrome::Profile
- Includes:
- ProfileHelper
- Defined in:
- rb/lib/selenium/webdriver/chrome/profile.rb
Instance Method Summary (collapse)
- - (Object) [](key)
-
- (Object) []=(key, value)
Set a preference in the profile.
- - (Object) add_encoded_extension(encoded)
- - (Object) add_extension(path)
- - (Object) as_json(opts = nil)
-
- (Profile) initialize(model = nil)
constructor
A new instance of Profile.
- - (Object) layout_on_disk
Methods included from ProfileHelper
Constructor Details
- (Profile) initialize(model = nil)
Returns a new instance of Profile
12 13 14 15 16 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 12 def initialize(model = nil) @model = verify_model(model) @extensions = [] @encoded_extensions = [] end |
Instance Method Details
- (Object) [](key)
41 42 43 44 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 41 def [](key) parts = key.split(".") parts.inject(prefs) { |pr, k| pr.fetch(k) } end |
- (Object) []=(key, value)
Set a preference in the profile.
See codesearch.google.com/codesearch#OAMlx_jo-ck/src/chrome/common/pref_names.cc&exact_package=chromium
36 37 38 39 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 36 def []=(key, value) parts = key.split(".") parts[0..-2].inject(prefs) { |pr, k| pr[k] ||= {} }[parts.last] = value end |
- (Object) add_encoded_extension(encoded)
26 27 28 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 26 def add_encoded_extension(encoded) @encoded_extensions << encoded end |
- (Object) add_extension(path)
18 19 20 21 22 23 24 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 18 def add_extension(path) unless File.file?(path) raise Error::WebDriverError, "could not find extension at #{path.inspect}" end @extensions << path end |
- (Object) as_json(opts = nil)
55 56 57 58 59 60 61 62 63 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 55 def as_json(opts = nil) extensions = @extensions.map do |crx_path| File.open(crx_path, "rb") { |crx_file| Base64.strict_encode64 crx_file.read } end extensions.concat(@encoded_extensions) super.merge('extensions' => extensions) end |
- (Object) layout_on_disk
46 47 48 49 50 51 52 53 |
# File 'rb/lib/selenium/webdriver/chrome/profile.rb', line 46 def layout_on_disk dir = @model ? create_tmp_copy(@model) : Dir.mktmpdir("webdriver-chrome-profile") FileReaper << dir write_prefs_to dir dir end |