123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Remote::Driver Private

Overview

Driver implementation for remote server.

Constant Summary

::Selenium::WebDriver::SearchContext - Included

FINDERS

Class Method Summary

Instance Attribute Summary

::Selenium::WebDriver::DriverExtensions::UploadsFiles - Included

#file_detector=

Set the file detector to pass local files to a remote ::Selenium::WebDriver.

::Selenium::WebDriver::Driver - Inherited

Instance Method Summary

::Selenium::WebDriver::DriverExtensions::HasSessionEvents - Included

#fire_session_event

Fires a custom session event to the remote server event bus.

::Selenium::WebDriver::DriverExtensions::HasFileDownloads - Included

::Selenium::WebDriver::DriverExtensions::HasSessionId - Included

::Selenium::WebDriver::Driver - Inherited

#[]

Get the first element matching the given selector.

#action, #add_virtual_authenticator,
#all

driver.all(class: 'bar') #=> [#<WebDriver::Element:0x1011c3b88, ...].

#browser, #capabilities,
#close

Close the current window, or the browser if no windows are left.

#current_url

Get the URL of the current page.

#execute_async_script

Execute an asynchronous piece of JavaScript in the context of the currently selected frame or window.

#execute_script

Execute the given JavaScript.

#first

driver.first(id: 'foo').

#get

Opens the specified URL in the browser.

#inspect, #manage, #navigate, #network,
#page_source

Get the source of the current page.

#quit

Quit the browser.

#ref, #script,
#status

information about whether a remote end is in a state in which it can create new sessions, and may include additional meta information.

#switch_to,
#title

Get the title of the current page.

#window_handle

Get the current window handle.

#window_handles

Get the window handles of open browser windows.

#add_extensions, #create_bridge, #screenshot

::Selenium::WebDriver::TakesScreenshot - Included

#save_screenshot

Save a PNG screenshot of the viewport to the given path.

#screenshot_as

Return a PNG screenshot in the given format as a string.

::Selenium::WebDriver::SearchContext - Included

#find_element

Find the first element matching the given arguments.

#find_elements

Find all elements matching the given arguments.

#extract_args

Constructor Details

.new(capabilities: nil, options: nil, service: nil, url: nil, http_client: nil, client_config: nil) ⇒ Driver

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/driver.rb', line 34

def initialize(capabilities: nil, options: nil, service: nil, url: nil, http_client: nil, client_config: nil,
               **)
  assert_arguments(service, url, http_client, client_config)

  caps = process_options(options, capabilities)
  http_client ||= Remote::Http::Default.new(client_config: client_config)
  http_client.server_url = url || client_config&.server_url || "http://#{Platform.localhost}:4444/wd/hub"
  super(caps: caps, http_client: http_client, **)
  @bridge.file_detector = ->((filename, *)) { File.exist?(filename) && filename.to_s }
  command_list = @bridge.command_list
  @bridge.extend(WebDriver::Remote::Features)
  @bridge.add_commands(command_list)
end

Instance Method Details

#assert_arguments(service, url, http_client, client_config) (private)

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/driver.rb', line 50

def assert_arguments(service, url, http_client, client_config)
  raise ArgumentError, "Can not set :service object on #{self.class}" if service
  raise ArgumentError, 'Cannot use both :http_client and :client_config' if http_client && client_config
  raise ArgumentError, 'Cannot use both :url and a ClientConfig#server_url' if url && client_config&.server_url
end

#devtools_url (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/driver.rb', line 56

def devtools_url
  capabilities['se:cdp']
end

#devtools_version (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/driver.rb', line 60

def devtools_version
  cdp_version = capabilities['se:cdpVersion']&.split('.')&.first
  raise Error::WebDriverError, 'DevTools is not supported by the Remote Server' unless cdp_version

  Integer(cdp_version)
end

#generate_capabilities(capabilities) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/driver.rb', line 77

def generate_capabilities(capabilities)
  Array(capabilities).map { |cap|
    if cap.is_a? Symbol
      cap = WebDriver::Options.send(cap)
    elsif !cap.respond_to? :as_json
      msg = ":capabilities parameter only accepts objects responding to #as_json which #{cap.class} does not"
      raise ArgumentError, msg
    end
    cap.as_json
  }.inject(:merge)
end

#process_options(options, capabilities) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/remote/driver.rb', line 67

def process_options(options, capabilities)
  if options && capabilities
    msg = "Don't use both :options and :capabilities when initializing #{self.class}, prefer :options"
    raise ArgumentError, msg
  elsif options.nil? && capabilities.nil?
    raise ArgumentError, "#{self.class} needs :options to be set"
  end
  options ? options.as_json : generate_capabilities(capabilities)
end