Class: Watir::Capabilities

Inherits:
Object
  • Object
show all
Defined in:
lib/watir/capabilities.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser = nil, options = {}) ⇒ Capabilities

Returns a new instance of Capabilities.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/watir/capabilities.rb', line 7

def initialize(browser = nil, options = {})
  @options, @browser = case browser
                       when Selenium::WebDriver::Driver
                         return
                       when ::Symbol, String
                         [options.dup, browser&.to_sym]
                       when Hash
                         [browser.dup, infer_browser(browser)]
                       when nil
                         [{}, infer_browser]
                       else
                         raise ArgumentError,
                               "expected Driver, String, Symbol or Hash, but received: #{browser.class}"
                       end
  validate_options

  @selenium_browser = @options.key?(:url) ? :remote : @browser
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/watir/capabilities.rb', line 5

def options
  @options
end

#selenium_argsObject (readonly)

Returns the value of attribute selenium_args.



5
6
7
# File 'lib/watir/capabilities.rb', line 5

def selenium_args
  @selenium_args
end

#selenium_browserObject (readonly)

Returns the value of attribute selenium_browser.



5
6
7
# File 'lib/watir/capabilities.rb', line 5

def selenium_browser
  @selenium_browser
end

Instance Method Details

#to_argsObject

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/watir/capabilities.rb', line 26

def to_args
  Watir.logger.info "Creating Browser instance of #{@browser} with user provided options: #{@options.inspect}"
  @selenium_args = process_arguments
  raise ArgumentError, "#{@options} are unrecognized arguments for Browser constructor" unless @options.empty?

  Watir.logger.info "Selenium options generated by Watir: #{@selenium_args.inspect}"
  [@selenium_browser, @selenium_args]
end