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_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 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 12 def initialize(model = nil) @model = verify_model(model) @extensions = [] end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 39 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 36 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
31 32 33 34 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 31 def []=(key, value) parts = key.split(".") parts[0..-2].inject(prefs) { |pr, k| pr[k] ||= {} }[parts.last] = value end |
#add_extension(path) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 17 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
50 51 52 53 54 55 56 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 50 def as_json(opts = nil) extensions = @extensions.map do |crx_path| Base64.strict_encode64 File.read(crx_path) end super.merge('extensions' => extensions) end |
#layout_on_disk ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 41 def layout_on_disk dir = @model ? create_tmp_copy(@model) : Dir.mktmpdir("webdriver-chrome-profile") FileReaper << dir write_prefs_to dir dir end |