Class: Selenium::WebDriver::Chrome::Options
- Inherits:
-
Selenium::WebDriver::Common::Options
- Object
- Selenium::WebDriver::Common::Options
- Selenium::WebDriver::Chrome::Options
- Defined in:
- lib/selenium/webdriver/chrome/options.rb
Constant Summary collapse
- KEY =
'goog:chromeOptions'
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#binary ⇒ Object
Returns the value of attribute binary.
-
#detach ⇒ Object
Returns the value of attribute detach.
-
#emulation ⇒ Object
readonly
Returns the value of attribute emulation.
-
#encoded_extensions ⇒ Object
readonly
Returns the value of attribute encoded_extensions.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prefs ⇒ Object
readonly
Returns the value of attribute prefs.
-
#profile ⇒ Object
Returns the value of attribute profile.
Instance Method Summary collapse
-
#add_argument(arg) ⇒ Object
Add a command-line argument to use when starting Chrome.
-
#add_emulation(device_name: nil, device_metrics: nil, user_agent: nil) ⇒ Object
Add an emulation device name.
-
#add_encoded_extension(encoded) ⇒ Object
Add an extension by Base64-encoded string.
-
#add_extension(path) ⇒ Object
Add an extension by local path.
-
#add_option(name, value) ⇒ Object
Add a new option not yet handled by bindings.
-
#add_preference(name, value) ⇒ Object
Add a preference that is only applied to the user profile in use.
- #as_json ⇒ Object private
-
#headless! ⇒ Object
Run Chrome in headless mode.
-
#initialize(**opts) ⇒ Options
constructor
Create a new Options instance.
Constructor Details
#initialize(**opts) ⇒ Options
Create a new Options instance.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 45 def initialize(**opts) @args = Set.new(opts.delete(:args) || []) @binary = opts.delete(:binary) || Chrome.path @prefs = opts.delete(:prefs) || {} @extensions = opts.delete(:extensions) || [] @options = opts.delete(:options) || {} @emulation = opts.delete(:emulation) || {} @detach = opts.delete(:detach) @profile = opts.delete(:profile) @encoded_extensions = [] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args
24 25 26 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 24 def args @args end |
#binary ⇒ Object
Returns the value of attribute binary
25 26 27 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 25 def binary @binary end |
#detach ⇒ Object
Returns the value of attribute detach
25 26 27 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 25 def detach @detach end |
#emulation ⇒ Object (readonly)
Returns the value of attribute emulation
24 25 26 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 24 def emulation @emulation end |
#encoded_extensions ⇒ Object (readonly)
Returns the value of attribute encoded_extensions
24 25 26 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 24 def encoded_extensions @encoded_extensions end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions
24 25 26 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 24 def extensions @extensions end |
#options ⇒ Object (readonly)
Returns the value of attribute options
24 25 26 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 24 def @options end |
#prefs ⇒ Object (readonly)
Returns the value of attribute prefs
24 25 26 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 24 def prefs @prefs end |
#profile ⇒ Object
Returns the value of attribute profile
25 26 27 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 25 def profile @profile end |
Instance Method Details
#add_argument(arg) ⇒ Object
Add a command-line argument to use when starting Chrome.
98 99 100 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 98 def add_argument(arg) @args << arg end |
#add_emulation(device_name: nil, device_metrics: nil, user_agent: nil) ⇒ Object
Add an emulation device name
160 161 162 163 164 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 160 def add_emulation(device_name: nil, device_metrics: nil, user_agent: nil) @emulation[:deviceName] = device_name if device_name @emulation[:deviceMetrics] = device_metrics if device_metrics @emulation[:userAgent] = user_agent if user_agent end |
#add_encoded_extension(encoded) ⇒ Object
Add an extension by Base64-encoded string.
84 85 86 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 84 def add_encoded_extension(encoded) @encoded_extensions << encoded end |
#add_extension(path) ⇒ Object
Add an extension by local path.
67 68 69 70 71 72 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 67 def add_extension(path) raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path) raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx' @extensions << path end |
#add_option(name, value) ⇒ Object
Add a new option not yet handled by bindings.
113 114 115 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 113 def add_option(name, value) @options[name] = value end |
#add_preference(name, value) ⇒ Object
Add a preference that is only applied to the user profile in use.
128 129 130 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 128 def add_preference(name, value) prefs[name] = value end |
#as_json ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 170 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) add_argument("--user-data-dir=#{@profile[:directory]}") if @profile opts = @options opts[:binary] = @binary if @binary opts[:args] = @args.to_a if @args.any? opts[:extensions] = extensions if extensions.any? opts[:mobileEmulation] = @emulation unless @emulation.empty? opts[:prefs] = @prefs unless @prefs.empty? opts[:detach] = @detach if !@detach.nil? && @detach != false {KEY => generate_as_json(opts)} end |
#headless! ⇒ Object
Run Chrome in headless mode.
140 141 142 |
# File 'lib/selenium/webdriver/chrome/options.rb', line 140 def headless! add_argument '--headless' end |