Class: Selenium::WebDriver::Chrome::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Chrome::Profile
- Includes:
- ProfileHelper
- Defined in:
- lib/selenium/webdriver/chrome/profile.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
Set a preference in the profile.
- #add_encoded_extension(encoded) ⇒ Object
- #add_extension(path) ⇒ Object
- #as_json(opts = nil) ⇒ Object
-
#initialize(model = nil) ⇒ Profile
constructor
A new instance of Profile.
- #layout_on_disk ⇒ Object
Methods included from ProfileHelper
Constructor Details
#initialize(model = nil) ⇒ Profile
Returns a new instance of Profile.
12 13 14 15 16 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 12 def initialize(model = nil) @model = verify_model(model) @extensions = [] @encoded_extensions = [] end |
Instance Method Details
#[](key) ⇒ Object
41 42 43 44 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 41 def [](key) parts = key.split(".") parts.inject(prefs) { |pr, k| pr.fetch(k) } end |
#[]=(key, value) ⇒ Object
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 '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 |
#add_encoded_extension(encoded) ⇒ Object
26 27 28 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 26 def add_encoded_extension(encoded) @encoded_extensions << encoded end |
#add_extension(path) ⇒ Object
18 19 20 21 22 23 24 |
# File '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 |
#as_json(opts = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File '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 |
#layout_on_disk ⇒ Object
46 47 48 49 50 51 52 53 |
# File '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 |