Class: Selenium::WebDriver::Chromium::Profile
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Chromium::Profile
show all
- Includes:
- ProfileHelper
- Defined in:
- lib/selenium/webdriver/chromium/profile.rb
Instance Method Summary
collapse
decoded, #encoded, included, #to_json
Constructor Details
#initialize(model = nil) ⇒ Profile
Returns a new instance of Profile.
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 30
def initialize(model = nil)
WebDriver.logger.deprecate(
'Chromium::Profile (including Chrome::Profile and Edge::Profile)',
"Options#add_argument('--user-data-dir=...'), Options#add_preference, and Options#add_extension",
id: :chromium_profile
)
@model = verify_model(model)
@extensions = []
@encoded_extensions = []
@directory = nil
end
|
Instance Method Details
#[](key) ⇒ Object
68
69
70
71
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 68
def [](key)
parts = key.split('.')
parts.inject(prefs) { |a, e| a.fetch(e) }
end
|
#[]=(key, value) ⇒ Object
63
64
65
66
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 63
def []=(key, value)
parts = key.split('.')
parts[0..-2].inject(prefs) { |a, e| a[e] ||= {} }[parts.last] = value
end
|
#add_encoded_extension(encoded) ⇒ Object
49
50
51
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 49
def add_encoded_extension(encoded)
@encoded_extensions << encoded
end
|
#add_extension(path) ⇒ Object
43
44
45
46
47
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 43
def add_extension(path)
raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
@extensions << path
end
|
#as_json ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 82
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.any?
opts
end
|
#directory ⇒ Object
53
54
55
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 53
def directory
@directory || layout_on_disk
end
|
#layout_on_disk ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/selenium/webdriver/chromium/profile.rb', line 73
def layout_on_disk
@directory = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-chrome-profile')
FileReaper << @directory
write_prefs_to @directory
@directory
end
|