Class: Selenium::WebDriver::Chrome::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Chrome::Profile
- Includes:
- ProfileHelper
- Defined in:
- lib/selenium/webdriver/chrome/profile.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
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 ⇒ 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.
32 33 34 35 36 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 32 def initialize(model = nil) @model = verify_model(model) @extensions = [] @encoded_extensions = [] end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory
30 31 32 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 30 def directory @directory end |
Instance Method Details
#[](key) ⇒ Object
61 62 63 64 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 61 def [](key) parts = key.split('.') parts.inject(prefs) { |a, e| a.fetch(e) } end |
#[]=(key, value) ⇒ Object
Set a preference in the profile.
See src.chromium.org/svn/trunk/src/chrome/common/pref_names.cc
56 57 58 59 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 56 def []=(key, value) parts = key.split('.') parts[0..-2].inject(prefs) { |a, e| a[e] ||= {} }[parts.last] = value end |
#add_encoded_extension(encoded) ⇒ Object
46 47 48 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 46 def add_encoded_extension(encoded) @encoded_extensions << encoded end |
#add_extension(path) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 38 def add_extension(path) unless File.file?(path) raise Error::WebDriverError, "could not find extension at #{path.inspect}" end @extensions << path end |
#as_json ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 75 def as_json(*) extensions = @extensions.map do |crx_path| File.open(crx_path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read } end extensions.concat(@encoded_extensions) opts = {directory: @directory || layout_on_disk} opts[:extensions] = extensions if extensions opts end |
#layout_on_disk ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/selenium/webdriver/chrome/profile.rb', line 66 def layout_on_disk @directory = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-chrome-profile') FileReaper << @directory write_prefs_to @directory @directory end |