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
- 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) ⇒ 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 76 def initialize(opts = {}) opts = opts.dup WebDriver.logger.deprecate ':port', 'full URL' if opts.key?(:port) port = opts.delete(:port) || 4444 http_client = opts.delete(:http_client) { Http::Default.new } url = opts.delete(:url) { "http://#{Platform.localhost}:#{port}/wd/hub" } 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.
32 33 34 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 32 def capabilities @capabilities end |
#context ⇒ Object
Returns the value of attribute context.
31 32 33 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 31 def context @context end |
#dialect ⇒ Object (readonly)
Returns the value of attribute dialect.
32 33 34 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 32 def dialect @dialect end |
#file_detector ⇒ Object
Returns the value of attribute file_detector.
31 32 33 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 31 def file_detector @file_detector end |
#http ⇒ Object
Returns the value of attribute http.
31 32 33 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 31 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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 43 def self.handshake(**opts) desired_capabilities = opts.delete(:desired_capabilities) if desired_capabilities.is_a?(Symbol) unless Remote::Capabilities.respond_to?(desired_capabilities) raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}" end desired_capabilities = Remote::Capabilities.__send__(desired_capabilities) end bridge = new(opts) capabilities = bridge.create_session(desired_capabilities) 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
142 143 144 145 146 147 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 142 def browser @browser ||= begin name = @capabilities.browser_name name ? name.tr(' ', '_').to_sym : 'unknown' end end |
#create_session(desired_capabilities) ⇒ Object
Creates session handling both OSS and W3C dialects.
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 129 130 131 132 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 102 def create_session(desired_capabilities) 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.
138 139 140 |
# File 'lib/selenium/webdriver/remote/bridge.rb', line 138 def session_id @session_id || raise(Error::WebDriverError, 'no current session exists') end |