Class: Selenium::WebDriver::Remote::Bridge
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Remote::Bridge
- Includes:
- Atoms, BridgeHelper
- Defined in:
- lib/selenium/webdriver/remote/bridge.rb
Direct Known Subclasses
Constant Summary collapse
- PORT =
4444
- COMMANDS =
{ new_session: [:post, 'session'.freeze] }.freeze
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#context ⇒ Object
Returns the value of attribute context.
-
#dialect ⇒ Object
readonly
Returns the value of attribute dialect.
-
#file_detector ⇒ Object
Returns the value of attribute file_detector.
-
#http ⇒ Object
Returns the value of attribute http.
Class Method Summary collapse
-
.handshake(**opts) ⇒ OSS:Bridge, W3C::Bridge
Implements protocol handshake which:.
Instance Method Summary collapse
- #browser ⇒ Object
-
#create_session(desired_capabilities, options = nil) ⇒ Object
Creates session handling both OSS and W3C dialects.
-
#initialize(opts = {}) ⇒ Bridge
constructor
private
Initializes the bridge with the given server URL.
-
#session_id ⇒ Object
Returns the current session ID.
Methods included from BridgeHelper
#element_id_from, #parse_cookie_string, #unwrap_script_result
Constructor Details
#initialize(opts = {}) ⇒ Bridge
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.
Initializes the bridge with the given server URL
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 74 def initialize(opts = {}) opts = opts.dup http_client = opts.delete(:http_client) { Http::Default.new } url = opts.delete(:url) { "http://#{Platform.localhost}:#{PORT}/wd/hub" } opts.delete(:options) unless opts.empty? raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}" end uri = url.is_a?(URI) ? url : URI.parse(url) uri.path += '/' unless uri.path =~ %r{\/$} http_client.server_url = uri @http = http_client @file_detector = nil end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
31 32 33 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 31 def capabilities @capabilities end |
#context ⇒ Object
Returns the value of attribute context.
30 31 32 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 30 def context @context end |
#dialect ⇒ Object (readonly)
Returns the value of attribute dialect.
31 32 33 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 31 def dialect @dialect end |
#file_detector ⇒ Object
Returns the value of attribute file_detector.
30 31 32 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 30 def file_detector @file_detector end |
#http ⇒ Object
Returns the value of attribute http.
30 31 32 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 30 def http @http end |
Class Method Details
.handshake(**opts) ⇒ OSS:Bridge, W3C::Bridge
Implements protocol handshake which:
1. Creates session with driver.
2. Sniffs response.
3. Based on the response, understands which dialect we should use.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 42 def self.handshake(**opts) desired_capabilities = opts.delete(:desired_capabilities) { Capabilities.new } if desired_capabilities.is_a?(Symbol) unless Capabilities.respond_to?(desired_capabilities) raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}" end desired_capabilities = Capabilities.__send__(desired_capabilities) end bridge = new(opts) capabilities = bridge.create_session(desired_capabilities, opts.delete(:options)) case bridge.dialect when :oss Remote::OSS::Bridge.new(capabilities, bridge.session_id, opts) when :w3c Remote::W3C::Bridge.new(capabilities, bridge.session_id, opts) else raise WebDriverError, 'cannot understand dialect' end end |
Instance Method Details
#browser ⇒ Object
138 139 140 141 142 143 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 138 def browser @browser ||= begin name = @capabilities.browser_name name ? name.tr(' ', '_').to_sym : 'unknown' end end |
#create_session(desired_capabilities, options = nil) ⇒ Object
Creates session handling both OSS and W3C dialects.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 98 def create_session(desired_capabilities, = nil) response = execute(:new_session, {}, merged_capabilities(desired_capabilities, )) @session_id = response['sessionId'] oss_status = response['status'] value = response['value'] if value.is_a?(Hash) @session_id = value['sessionId'] if value.key?('sessionId') if value.key?('capabilities') value = value['capabilities'] elsif value.key?('value') value = value['value'] end end unless @session_id raise Error::WebDriverError, 'no sessionId in returned payload' end if oss_status WebDriver.logger.info 'Detected OSS dialect.' @dialect = :oss Capabilities.json_create(value) else WebDriver.logger.info 'Detected W3C dialect.' @dialect = :w3c W3C::Capabilities.json_create(value) end end |
#session_id ⇒ Object
Returns the current session ID.
134 135 136 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 134 def session_id @session_id || raise(Error::WebDriverError, 'no current session exists') end |