Class: Selenium::WebDriver::Chromium::Profile

Inherits:
Object
  • Object
show all
Includes:
ProfileHelper
Defined in:
lib/selenium/webdriver/chromium/profile.rb

Instance Method Summary collapse

Methods included from ProfileHelper

decoded, #encoded, included, #to_json

Constructor Details

#initialize(model = nil) ⇒ Profile

Returns a new instance of Profile.



30
31
32
33
34
35
# File 'lib/selenium/webdriver/chromium/profile.rb', line 30

def initialize(model = nil)
  @model = verify_model(model)
  @extensions = []
  @encoded_extensions = []
  @directory = nil
end

Instance Method Details

#[](key) ⇒ Object



62
63
64
65
# File 'lib/selenium/webdriver/chromium/profile.rb', line 62

def [](key)
  parts = key.split('.')
  parts.inject(prefs) { |a, e| a.fetch(e) }
end

#[]=(key, value) ⇒ Object



57
58
59
60
# File 'lib/selenium/webdriver/chromium/profile.rb', line 57

def []=(key, value)
  parts = key.split('.')
  parts[0..-2].inject(prefs) { |a, e| a[e] ||= {} }[parts.last] = value
end

#add_encoded_extension(encoded) ⇒ Object



43
44
45
# File 'lib/selenium/webdriver/chromium/profile.rb', line 43

def add_encoded_extension(encoded)
  @encoded_extensions << encoded
end

#add_extension(path) ⇒ Object



37
38
39
40
41
# File 'lib/selenium/webdriver/chromium/profile.rb', line 37

def add_extension(path)
  raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)

  @extensions << path
end

#as_jsonObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/selenium/webdriver/chromium/profile.rb', line 76

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

#directoryObject



47
48
49
# File 'lib/selenium/webdriver/chromium/profile.rb', line 47

def directory
  @directory || layout_on_disk
end

#layout_on_diskObject



67
68
69
70
71
72
73
74
# File 'lib/selenium/webdriver/chromium/profile.rb', line 67

def layout_on_disk
  @directory = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-chrome-profile')
  FileReaper << @directory

  write_prefs_to @directory

  @directory
end