Class: Selenium::WebDriver::Firefox::Profile

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

Constant Summary collapse

VALID_PREFERENCE_TYPES =
[TrueClass, FalseClass, Integer, Float, String].freeze
WEBDRIVER_PREFS =
{
  log_file: 'webdriver.log.file'
}.freeze
DEFAULT_PREFERENCES =
{
  'browser.newtabpage.enabled' => false,
  'browser.startup.homepage' => 'about:blank',
  'browser.usedOnWindows10.introURL' => 'about:blank',
  'network.captive-portal-service.enabled' => false,
  'security.csp.enable' => false
}.freeze
LOCK_FILES =
%w[.parentlock parent.lock lock].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ProfileHelper

#encoded, included, #to_json

Constructor Details

#initialize(model = nil) ⇒ Profile

Create a new Profile instance

Examples:

User configured profile


profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.http'] = 'localhost'
profile['network.proxy.http_port'] = 9090

driver = Selenium::WebDriver.for :firefox, :profile => profile


72
73
74
75
76
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 72

def initialize(model = nil)
  @model = verify_model(model)

  @additional_prefs = read_model_prefs
end

Instance Attribute Details

#log_file ⇒ Object

Returns the value of attribute log_file.



41
42
43
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 41

def log_file
  @log_file
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



41
42
43
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 41

def name
  @name
end

Class Method Details

.decoded(json) ⇒ Object



55
56
57
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 55

def decoded(json)
  JSON.parse(json)
end

.from_name(name) ⇒ Object



48
49
50
51
52
53
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 48

def from_name(name)
  profile = ini[name]
  return profile if profile

  raise Error::WebDriverError, "unable to find profile named: #{name.inspect}"
end

.ini ⇒ Object



44
45
46
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 44

def ini
  @ini ||= ProfilesIni.new
end

Instance Method Details

#[]=(key, value) ⇒ Object

Set a preference for this particular profile.



96
97
98
99
100
101
102
103
104
105
106
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 96

def []=(key, value)
  unless VALID_PREFERENCE_TYPES.any? { |e| value.is_a? e }
    raise TypeError, "expected one of #{VALID_PREFERENCE_TYPES.inspect}, got #{value.inspect}:#{value.class}"
  end

  if value.is_a?(String) && Util.stringified?(value)
    raise ArgumentError, "preference values must be plain strings: #{key.inspect} => #{value.inspect}"
  end

  @additional_prefs[key.to_s] = value
end

#layout_on_disk ⇒ Object



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

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

  delete_lock_files(profile_dir)
  delete_extensions_cache(profile_dir)
  update_user_prefs_in(profile_dir)

  profile_dir
end

#proxy=(proxy) ⇒ Object

Raises:

  • (TypeError)


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'rb/lib/selenium/webdriver/firefox/profile.rb', line 113

def proxy=(proxy)
  raise TypeError, "expected #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}" unless proxy.is_a? Proxy

  case proxy.type
  when :manual
    self['network.proxy.type'] = 1

    set_manual_proxy_preference 'http', proxy.http
    set_manual_proxy_preference 'ssl', proxy.ssl
    set_manual_proxy_preference 'socks', proxy.socks

    self['network.proxy.no_proxies_on'] = proxy.no_proxy || ''
  when :pac
    self['network.proxy.type'] = 2
    self['network.proxy.autoconfig_url'] = proxy.pac
  when :auto_detect
    self['network.proxy.type'] = 4
  else
    raise ArgumentError, "unsupported proxy type #{proxy.type}"
  end
end