selenium-webdriver 3.0.0.beta4.0 → 4.0.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +679 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/lib/selenium-webdriver.rb +2 -2
  7. data/lib/selenium/server.rb +23 -16
  8. data/lib/selenium/webdriver.rb +43 -25
  9. data/lib/selenium/webdriver/atoms.rb +20 -1
  10. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  11. data/lib/selenium/webdriver/atoms/getAttribute.js +84 -11
  12. data/lib/selenium/webdriver/atoms/isDisplayed.js +100 -0
  13. data/lib/selenium/webdriver/chrome.rb +15 -20
  14. data/lib/selenium/webdriver/chrome/bridge.rb +29 -66
  15. data/lib/selenium/webdriver/{edge/service.rb → chrome/driver.rb} +19 -22
  16. data/lib/selenium/webdriver/chrome/options.rb +221 -0
  17. data/lib/selenium/webdriver/chrome/profile.rb +6 -7
  18. data/lib/selenium/webdriver/chrome/service.rb +20 -20
  19. data/lib/selenium/webdriver/common.rb +19 -11
  20. data/lib/selenium/webdriver/common/action_builder.rb +98 -246
  21. data/lib/selenium/webdriver/common/alert.rb +2 -7
  22. data/lib/selenium/webdriver/common/driver.rb +89 -51
  23. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +45 -0
  24. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +50 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/{has_input_devices.rb → has_debugger.rb} +12 -25
  26. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +38 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +3 -5
  28. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +51 -0
  29. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +3 -3
  30. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +51 -0
  31. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +2 -2
  32. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +2 -2
  33. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +2 -2
  34. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +4 -4
  35. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +9 -3
  36. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +3 -5
  37. data/lib/selenium/webdriver/common/element.rb +32 -10
  38. data/lib/selenium/webdriver/common/error.rb +103 -121
  39. data/lib/selenium/webdriver/common/file_reaper.rb +3 -5
  40. data/lib/selenium/webdriver/common/html5/local_storage.rb +2 -2
  41. data/lib/selenium/webdriver/common/html5/session_storage.rb +2 -2
  42. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +3 -2
  43. data/lib/selenium/webdriver/common/interactions/input_device.rb +54 -0
  44. data/lib/selenium/webdriver/common/interactions/interaction.rb +53 -0
  45. data/lib/selenium/webdriver/{phantomjs.rb → common/interactions/interactions.rb} +17 -20
  46. data/lib/selenium/webdriver/common/interactions/key_actions.rb +145 -0
  47. data/lib/selenium/webdriver/common/interactions/key_input.rb +66 -0
  48. data/lib/selenium/webdriver/common/interactions/none_input.rb +36 -0
  49. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +363 -0
  50. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +139 -0
  51. data/lib/selenium/webdriver/common/keys.rb +37 -15
  52. data/lib/selenium/webdriver/common/log_entry.rb +4 -4
  53. data/lib/selenium/webdriver/common/logger.rb +147 -0
  54. data/lib/selenium/webdriver/common/logs.rb +2 -2
  55. data/lib/selenium/webdriver/common/manager.rb +177 -0
  56. data/lib/selenium/webdriver/common/navigation.rb +2 -2
  57. data/lib/selenium/webdriver/common/options.rb +47 -105
  58. data/lib/selenium/webdriver/common/platform.rb +44 -38
  59. data/lib/selenium/webdriver/common/port_prober.rb +8 -19
  60. data/lib/selenium/webdriver/common/profile_helper.rb +13 -5
  61. data/lib/selenium/webdriver/common/proxy.rb +14 -8
  62. data/lib/selenium/webdriver/common/search_context.rb +16 -20
  63. data/lib/selenium/webdriver/common/service.rb +115 -30
  64. data/lib/selenium/webdriver/common/socket_lock.rb +12 -7
  65. data/lib/selenium/webdriver/common/socket_poller.rb +29 -22
  66. data/lib/selenium/webdriver/common/target_locator.rb +6 -6
  67. data/lib/selenium/webdriver/common/timeouts.rb +2 -2
  68. data/lib/selenium/webdriver/common/wait.rb +14 -8
  69. data/lib/selenium/webdriver/common/window.rb +38 -2
  70. data/lib/selenium/webdriver/common/zipper.rb +3 -5
  71. data/lib/selenium/webdriver/edge.rb +33 -20
  72. data/lib/selenium/webdriver/edge_chrome/bridge.rb +30 -0
  73. data/lib/selenium/webdriver/edge_chrome/driver.rb +38 -0
  74. data/lib/selenium/webdriver/{common/driver_extensions/has_touch_screen.rb → edge_chrome/options.rb} +10 -12
  75. data/lib/selenium/webdriver/edge_chrome/profile.rb +33 -0
  76. data/lib/selenium/webdriver/edge_chrome/service.rb +36 -0
  77. data/lib/selenium/webdriver/edge_html/driver.rb +39 -0
  78. data/lib/selenium/webdriver/edge_html/options.rb +91 -0
  79. data/lib/selenium/webdriver/edge_html/service.rb +47 -0
  80. data/lib/selenium/webdriver/firefox.rb +24 -29
  81. data/lib/selenium/webdriver/firefox/bridge.rb +15 -39
  82. data/lib/selenium/webdriver/firefox/{util.rb → driver.rb} +13 -19
  83. data/lib/selenium/webdriver/firefox/extension.rb +28 -8
  84. data/lib/selenium/webdriver/firefox/options.rb +162 -0
  85. data/lib/selenium/webdriver/firefox/profile.rb +23 -82
  86. data/lib/selenium/webdriver/firefox/profiles_ini.rb +5 -5
  87. data/lib/selenium/webdriver/firefox/service.rb +18 -37
  88. data/lib/selenium/webdriver/ie.rb +13 -19
  89. data/lib/selenium/webdriver/ie/driver.rb +40 -0
  90. data/lib/selenium/webdriver/ie/options.rb +118 -0
  91. data/lib/selenium/webdriver/ie/service.rb +20 -20
  92. data/lib/selenium/webdriver/remote.rb +15 -17
  93. data/lib/selenium/webdriver/remote/bridge.rb +281 -300
  94. data/lib/selenium/webdriver/remote/capabilities.rb +102 -83
  95. data/lib/selenium/webdriver/remote/commands.rb +132 -192
  96. data/lib/selenium/webdriver/remote/driver.rb +52 -0
  97. data/lib/selenium/webdriver/remote/http/common.rb +23 -13
  98. data/lib/selenium/webdriver/remote/http/curb.rb +10 -7
  99. data/lib/selenium/webdriver/remote/http/default.rb +52 -32
  100. data/lib/selenium/webdriver/remote/http/persistent.rb +8 -4
  101. data/lib/selenium/webdriver/remote/response.rb +32 -35
  102. data/lib/selenium/webdriver/remote/server_error.rb +2 -2
  103. data/lib/selenium/webdriver/safari.rb +24 -22
  104. data/lib/selenium/webdriver/safari/bridge.rb +21 -21
  105. data/lib/selenium/webdriver/safari/driver.rb +41 -0
  106. data/lib/selenium/webdriver/safari/options.rb +66 -0
  107. data/lib/selenium/webdriver/safari/service.rb +8 -24
  108. data/lib/selenium/webdriver/support.rb +3 -2
  109. data/lib/selenium/webdriver/support/abstract_event_listener.rb +2 -2
  110. data/lib/selenium/webdriver/support/block_event_listener.rb +3 -3
  111. data/lib/selenium/webdriver/support/color.rb +13 -13
  112. data/lib/selenium/webdriver/support/escaper.rb +2 -2
  113. data/lib/selenium/webdriver/support/event_firing_bridge.rb +4 -4
  114. data/lib/selenium/webdriver/support/relative_locator.rb +51 -0
  115. data/lib/selenium/webdriver/support/select.rb +20 -21
  116. data/lib/selenium/webdriver/version.rb +24 -0
  117. data/selenium-webdriver.gemspec +31 -17
  118. metadata +331 -248
  119. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  120. data/lib/selenium/webdriver/common/keyboard.rb +0 -69
  121. data/lib/selenium/webdriver/common/mouse.rb +0 -88
  122. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -81
  123. data/lib/selenium/webdriver/common/touch_screen.rb +0 -121
  124. data/lib/selenium/webdriver/common/w3c_error.rb +0 -191
  125. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  126. data/lib/selenium/webdriver/edge/legacy_support.rb +0 -117
  127. data/lib/selenium/webdriver/firefox/binary.rb +0 -186
  128. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  129. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  130. data/lib/selenium/webdriver/firefox/launcher.rb +0 -114
  131. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  132. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  133. data/lib/selenium/webdriver/firefox/w3c_bridge.rb +0 -79
  134. data/lib/selenium/webdriver/ie/bridge.rb +0 -76
  135. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -65
  136. data/lib/selenium/webdriver/phantomjs/service.rb +0 -66
  137. data/lib/selenium/webdriver/remote/w3c_bridge.rb +0 -682
  138. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +0 -228
  139. data/lib/selenium/webdriver/remote/w3c_commands.rb +0 -135
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Licensed to the Software Freedom Conservancy (SFC) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The SFC licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ module Selenium
21
+ module WebDriver
22
+ module Remote
23
+
24
+ #
25
+ # Driver implementation for remote server.
26
+ # @api private
27
+ #
28
+
29
+ class Driver < WebDriver::Driver
30
+ include DriverExtensions::UploadsFiles
31
+ include DriverExtensions::TakesScreenshot
32
+ include DriverExtensions::HasSessionId
33
+ include DriverExtensions::Rotatable
34
+ include DriverExtensions::HasRemoteStatus
35
+ include DriverExtensions::HasWebStorage
36
+
37
+ def initialize(bridge: nil, listener: nil, **opts)
38
+ desired_capabilities = opts[:desired_capabilities]
39
+ if desired_capabilities.is_a?(Symbol)
40
+ unless Remote::Capabilities.respond_to?(desired_capabilities)
41
+ raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
42
+ end
43
+
44
+ opts[:desired_capabilities] = Remote::Capabilities.__send__(desired_capabilities)
45
+ end
46
+ opts[:url] ||= "http://#{Platform.localhost}:4444/wd/hub"
47
+ super
48
+ end
49
+ end # Driver
50
+ end # Remote
51
+ end # WebDriver
52
+ end # Selenium
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -23,8 +23,12 @@ module Selenium
23
23
  module Http
24
24
  class Common
25
25
  MAX_REDIRECTS = 20 # same as chromium/gecko
26
- CONTENT_TYPE = 'application/json'.freeze
27
- DEFAULT_HEADERS = {'Accept' => CONTENT_TYPE}.freeze
26
+ CONTENT_TYPE = 'application/json'
27
+ DEFAULT_HEADERS = {
28
+ 'Accept' => CONTENT_TYPE,
29
+ 'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8",
30
+ 'User-Agent' => "selenium/#{WebDriver::VERSION} (ruby #{Platform.os})"
31
+ }.freeze
28
32
 
29
33
  attr_accessor :timeout
30
34
  attr_writer :server_url
@@ -33,6 +37,10 @@ module Selenium
33
37
  @timeout = nil
34
38
  end
35
39
 
40
+ def quit_errors
41
+ [IOError]
42
+ end
43
+
36
44
  def close
37
45
  # hook for subclasses - will be called on Driver#quit
38
46
  end
@@ -44,13 +52,10 @@ module Selenium
44
52
 
45
53
  if command_hash
46
54
  payload = JSON.generate(command_hash)
47
- headers['Content-Type'] = "#{CONTENT_TYPE}; charset=utf-8"
48
- headers['Content-Length'] = payload.bytesize.to_s if [:post, :put].include?(verb)
55
+ headers['Content-Length'] = payload.bytesize.to_s if %i[post put].include?(verb)
49
56
 
50
- if $DEBUG
51
- puts " >>> #{url} | #{payload}"
52
- puts " > #{headers.inspect}"
53
- end
57
+ WebDriver.logger.info(" >>> #{url} | #{payload}")
58
+ WebDriver.logger.debug(" > #{headers.inspect}")
54
59
  elsif verb == :post
55
60
  payload = '{}'
56
61
  headers['Content-Length'] = '2'
@@ -63,6 +68,7 @@ module Selenium
63
68
 
64
69
  def server_url
65
70
  return @server_url if @server_url
71
+
66
72
  raise Error::WebDriverError, 'server_url not set'
67
73
  end
68
74
 
@@ -74,16 +80,20 @@ module Selenium
74
80
  code = code.to_i
75
81
  body = body.to_s.strip
76
82
  content_type = content_type.to_s
77
- puts "<- #{body}\n" if $DEBUG
83
+ WebDriver.logger.info("<- #{body}")
78
84
 
79
85
  if content_type.include? CONTENT_TYPE
80
86
  raise Error::WebDriverError, "empty body: #{content_type.inspect} (#{code})\n#{body}" if body.empty?
87
+
81
88
  Response.new(code, JSON.parse(body))
82
89
  elsif code == 204
83
90
  Response.new(code)
84
91
  else
85
- msg = "unexpected response, code=#{code}, content-type=#{content_type.inspect}"
86
- msg << "\n#{body}" unless body.empty?
92
+ msg = if body.empty?
93
+ "unexpected response, code=#{code}, content-type=#{content_type.inspect}"
94
+ else
95
+ "unexpected response, code=#{code}, content-type=#{content_type.inspect}\n#{body}"
96
+ end
87
97
 
88
98
  raise Error::WebDriverError, msg
89
99
  end
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -22,8 +22,6 @@ require 'curb'
22
22
  module Selenium
23
23
  module WebDriver
24
24
  module Remote
25
- # added for rescue
26
- Bridge::QUIT_ERRORS << Curl::Err::RecvError
27
25
 
28
26
  module Http
29
27
  #
@@ -40,6 +38,11 @@ module Selenium
40
38
  #
41
39
 
42
40
  class Curb < Common
41
+
42
+ def quit_errors
43
+ [Curl::Err::RecvError] + super
44
+ end
45
+
43
46
  private
44
47
 
45
48
  def request(verb, url, headers, payload)
@@ -76,16 +79,16 @@ module Selenium
76
79
  end
77
80
 
78
81
  def client
79
- @client ||= (
82
+ @client ||= begin
80
83
  c = Curl::Easy.new
81
84
 
82
85
  c.max_redirects = MAX_REDIRECTS
83
86
  c.follow_location = true
84
87
  c.timeout = @timeout if @timeout
85
- c.verbose = $DEBUG
88
+ c.verbose = WebDriver.logger.info?
86
89
 
87
90
  c
88
- )
91
+ end
89
92
  end
90
93
  end # Curb
91
94
  end # Http
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -26,25 +26,46 @@ module Selenium
26
26
  module Http
27
27
  # @api private
28
28
  class Default < Common
29
- attr_accessor :proxy
29
+ attr_writer :proxy
30
+
31
+ attr_accessor :open_timeout
32
+ attr_accessor :read_timeout
33
+
34
+ # Initializes object.
35
+ # Warning: Setting {#open_timeout} to non-nil values will cause a separate thread to spawn.
36
+ # Debuggers that freeze the process will not be able to evaluate any operations if that happens.
37
+ # @param [Numeric] open_timeout - Open timeout to apply to HTTP client.
38
+ # @param [Numeric] read_timeout - Read timeout (seconds) to apply to HTTP client.
39
+ def initialize(open_timeout: nil, read_timeout: nil)
40
+ @open_timeout = open_timeout
41
+ @read_timeout = read_timeout
42
+ end
43
+
44
+ def close
45
+ @http&.finish
46
+ end
30
47
 
31
48
  private
32
49
 
33
50
  def http
34
- @http ||= (
35
- http = new_http_client
36
- if server_url.scheme == 'https'
37
- http.use_ssl = true
38
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
39
- end
51
+ @http ||= begin
52
+ http = new_http_client
53
+ if server_url.scheme == 'https'
54
+ http.use_ssl = true
55
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
+ end
40
57
 
41
- if @timeout
42
- http.open_timeout = @timeout
43
- http.read_timeout = @timeout
58
+ # Defaulting open_timeout to nil to be consistent with Ruby 2.2 and earlier.
59
+ http.open_timeout = open_timeout
60
+ http.read_timeout = read_timeout if read_timeout
61
+
62
+ start(http)
63
+ http
44
64
  end
65
+ end
45
66
 
46
- http
47
- )
67
+ def start(http)
68
+ http.start
48
69
  end
49
70
 
50
71
  MAX_RETRIES = 3
@@ -64,23 +85,26 @@ module Selenium
64
85
  #
65
86
  # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
66
87
  raise if retries >= MAX_RETRIES
67
- retries += 1
68
88
 
89
+ retries += 1
90
+ sleep 2
69
91
  retry
70
- rescue Errno::EADDRNOTAVAIL => ex
92
+ rescue Errno::EADDRNOTAVAIL => e
71
93
  # a retry is sometimes needed when the port becomes temporarily unavailable
72
94
  raise if retries >= MAX_RETRIES
95
+
73
96
  retries += 1
74
97
  sleep 2
75
98
  retry
99
+ rescue Errno::ECONNREFUSED => e
100
+ raise e.class, "using proxy: #{proxy.http}" if use_proxy?
76
101
 
77
- rescue Errno::ECONNREFUSED => ex
78
- raise ex.class, "using proxy: #{proxy.http}" if use_proxy?
79
102
  raise
80
103
  end
81
104
 
82
105
  if response.is_a? Net::HTTPRedirection
83
106
  raise Error::WebDriverError, 'too many redirects' if redirects >= MAX_REDIRECTS
107
+
84
108
  request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
85
109
  else
86
110
  create_response response.code, response.body, response.content_type
@@ -90,9 +114,7 @@ module Selenium
90
114
  def new_request_for(verb, url, headers, payload)
91
115
  req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
92
116
 
93
- if server_url.userinfo
94
- req.basic_auth server_url.user, server_url.password
95
- end
117
+ req.basic_auth server_url.user, server_url.password if server_url.userinfo
96
118
 
97
119
  req.body = payload if payload
98
120
 
@@ -106,9 +128,7 @@ module Selenium
106
128
  def new_http_client
107
129
  if use_proxy?
108
130
  url = @proxy.http
109
- unless proxy.respond_to?(:http) && url
110
- raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"
111
- end
131
+ raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}" unless proxy.respond_to?(:http) && url
112
132
 
113
133
  proxy = URI.parse(url)
114
134
 
@@ -120,15 +140,15 @@ module Selenium
120
140
  end
121
141
 
122
142
  def proxy
123
- @proxy ||= (
124
- proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
125
- no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
143
+ @proxy ||= begin
144
+ proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
145
+ no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
126
146
 
127
- if proxy
128
- proxy = "http://#{proxy}" unless proxy.start_with?('http://')
129
- Proxy.new(http: proxy, no_proxy: no_proxy)
147
+ if proxy
148
+ proxy = "http://#{proxy}" unless proxy.start_with?('http://')
149
+ Proxy.new(http: proxy, no_proxy: no_proxy)
150
+ end
130
151
  end
131
- )
132
152
  end
133
153
 
134
154
  def use_proxy?
@@ -143,7 +163,7 @@ module Selenium
143
163
  rescue ArgumentError
144
164
  false
145
165
  end
146
- )
166
+ )
147
167
  end
148
168
 
149
169
  !ignored
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -26,11 +26,15 @@ module Selenium
26
26
  # @api private
27
27
  class Persistent < Default
28
28
  def close
29
- @http.shutdown if @http
29
+ @http&.shutdown
30
30
  end
31
31
 
32
32
  private
33
33
 
34
+ def start(*)
35
+ # no need to explicitly start connection
36
+ end
37
+
34
38
  def new_http_client
35
39
  proxy = nil
36
40
 
@@ -42,7 +46,7 @@ module Selenium
42
46
  proxy = URI.parse(url)
43
47
  end
44
48
 
45
- Net::HTTP::Persistent.new 'webdriver', proxy
49
+ Net::HTTP::Persistent.new name: 'webdriver', proxy: proxy
46
50
  end
47
51
 
48
52
  def response_for(request)
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -20,10 +20,13 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Remote
23
+
24
+ #
23
25
  # @api private
26
+ #
27
+
24
28
  class Response
25
29
  attr_reader :code, :payload
26
- attr_writer :payload
27
30
 
28
31
  def initialize(code, payload = nil)
29
32
  @code = code
@@ -33,32 +36,16 @@ module Selenium
33
36
  end
34
37
 
35
38
  def error
36
- klass = Error.for_code(status) || return
39
+ error, message, backtrace = process_error
40
+ klass = Error.for_error(error) || return
37
41
 
38
- ex = klass.new(error_message)
42
+ ex = klass.new(message)
39
43
  ex.set_backtrace(caller)
40
- add_backtrace ex
44
+ add_backtrace ex, backtrace
41
45
 
42
46
  ex
43
47
  end
44
48
 
45
- def error_message
46
- val = value
47
-
48
- case val
49
- when Hash
50
- msg = val['message']
51
- return 'unknown error' unless msg
52
- msg << ": #{val['alert']['text'].inspect}" if val['alert'].is_a?(Hash) && val['alert']['text']
53
- msg << " (#{val['class']})" if val['class']
54
- msg
55
- when String
56
- val
57
- else
58
- "unknown error, status=#{status}: #{val.inspect}"
59
- end
60
- end
61
-
62
49
  def [](key)
63
50
  @payload[key]
64
51
  end
@@ -69,15 +56,25 @@ module Selenium
69
56
  e = error
70
57
  raise e if e
71
58
  return unless @code.nil? || @code >= 400
59
+
72
60
  raise Error::ServerError, self
73
61
  end
74
62
 
75
- def add_backtrace(ex)
76
- return unless value.is_a?(Hash) && value['stackTrace']
63
+ def add_backtrace(ex, server_trace)
64
+ return unless server_trace
77
65
 
78
- server_trace = value['stackTrace']
66
+ backtrace = case server_trace
67
+ when Array
68
+ backtrace_from_remote(server_trace)
69
+ when String
70
+ server_trace.split("\n")
71
+ end
79
72
 
80
- backtrace = server_trace.map do |frame|
73
+ ex.set_backtrace(backtrace + ex.backtrace)
74
+ end
75
+
76
+ def backtrace_from_remote(server_trace)
77
+ server_trace.map { |frame|
81
78
  next unless frame.is_a?(Hash)
82
79
 
83
80
  file = frame['fileName']
@@ -90,17 +87,17 @@ module Selenium
90
87
  meth = 'unknown' if meth.nil? || meth.empty?
91
88
 
92
89
  "[remote server] #{file}:#{line}:in `#{meth}'"
93
- end.compact
94
-
95
- ex.set_backtrace(backtrace + ex.backtrace)
90
+ }.compact
96
91
  end
97
92
 
98
- def status
99
- @payload['status'] || @payload['error']
100
- end
93
+ def process_error
94
+ return unless self['value'].is_a?(Hash)
101
95
 
102
- def value
103
- @payload['value'] || @payload['message']
96
+ [
97
+ self['value']['error'],
98
+ self['value']['message'],
99
+ self['value']['stacktrace']
100
+ ]
104
101
  end
105
102
  end # Response
106
103
  end # Remote