lib/watir/capabilities.rb in watir-7.0.0.beta2 vs lib/watir/capabilities.rb in watir-7.0.0.beta3

- old
+ new

@@ -61,18 +61,49 @@ raise TypeError, ':http_client must be a Hash or a Selenium HTTP Client instance' end end def process_browser_options - browser_options = @options.delete(:options) || {} + browser_options = @options.delete(:options).dup || {} + vendor_caps = process_vendor_capabilities(browser_options) - options = browser_options if browser_options.is_a? Selenium::WebDriver::Options - options ||= Selenium::WebDriver::Options.send(@browser, **browser_options) + options = if browser_options.is_a? Selenium::WebDriver::Options + browser_options + else + convert_timeouts(browser_options) + Selenium::WebDriver::Options.send(@browser, **browser_options) + end + options.unhandled_prompt_behavior ||= :ignore browser_specific_options(options) raise ArgumentError, "#{@options} are unrecognized arguments for Browser constructor" unless @options.empty? - options + vendor_caps << options + end + + def process_vendor_capabilities(opts) + return [] unless opts.is_a? Hash + + vendor = opts.select { |key, _val| key.to_s.include?(':') && opts.delete(key) } + vendor.map { |k, v| Selenium::WebDriver::Remote::Capabilities.new(k => v) } + end + + def convert_timeouts(browser_options) + browser_options[:timeouts] ||= {} + browser_options[:timeouts].keys.each do |key| + raise(ArgumentError, 'do not set implicit wait, Watir handles waiting automatically') if key.to_s == 'implicit' + + Watir.logger.deprecate('using timeouts directly in options', + ":#{key}_timeout", + id: 'timeouts') + end + if browser_options.key?(:page_load_timeout) + browser_options[:timeouts][:page_load] = browser_options.delete(:page_load_timeout) * 1000 + end + + return unless browser_options.key?(:script_timeout) + + browser_options[:timeouts][:script] = browser_options.delete(:script_timeout) * 1000 end def browser_specific_options(options) case @browser when :chrome, :edge, :microsoftedge