browserstack-webdriver 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +791 -0
  3. data/README.md +31 -0
  4. data/build.desc +334 -0
  5. data/lib/selenium-client.rb +2 -0
  6. data/lib/selenium-webdriver.rb +1 -0
  7. data/lib/selenium/client.rb +37 -0
  8. data/lib/selenium/client/base.rb +132 -0
  9. data/lib/selenium/client/driver.rb +10 -0
  10. data/lib/selenium/client/errors.rb +9 -0
  11. data/lib/selenium/client/extensions.rb +118 -0
  12. data/lib/selenium/client/idiomatic.rb +488 -0
  13. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  14. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  15. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  16. data/lib/selenium/client/legacy_driver.rb +1720 -0
  17. data/lib/selenium/client/protocol.rb +104 -0
  18. data/lib/selenium/client/selenium_helper.rb +34 -0
  19. data/lib/selenium/rake/server_task.rb +157 -0
  20. data/lib/selenium/server.rb +248 -0
  21. data/lib/selenium/webdriver.rb +71 -0
  22. data/lib/selenium/webdriver/android.rb +9 -0
  23. data/lib/selenium/webdriver/android/bridge.rb +47 -0
  24. data/lib/selenium/webdriver/chrome.rb +26 -0
  25. data/lib/selenium/webdriver/chrome/bridge.rb +120 -0
  26. data/lib/selenium/webdriver/chrome/profile.rb +90 -0
  27. data/lib/selenium/webdriver/chrome/service.rb +75 -0
  28. data/lib/selenium/webdriver/common.rb +44 -0
  29. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  30. data/lib/selenium/webdriver/common/alert.rb +30 -0
  31. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  32. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  33. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  34. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  35. data/lib/selenium/webdriver/common/driver.rb +301 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/has_browser_connection.rb +17 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  38. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +25 -0
  39. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +13 -0
  40. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +22 -0
  41. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +19 -0
  42. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +22 -0
  43. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +45 -0
  44. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  46. data/lib/selenium/webdriver/common/element.rb +293 -0
  47. data/lib/selenium/webdriver/common/error.rb +207 -0
  48. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  49. data/lib/selenium/webdriver/common/html5/local_storage.rb +42 -0
  50. data/lib/selenium/webdriver/common/html5/location.rb +0 -0
  51. data/lib/selenium/webdriver/common/html5/session_storage.rb +44 -0
  52. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +42 -0
  53. data/lib/selenium/webdriver/common/json_helper.rb +34 -0
  54. data/lib/selenium/webdriver/common/keyboard.rb +55 -0
  55. data/lib/selenium/webdriver/common/keys.rb +109 -0
  56. data/lib/selenium/webdriver/common/log_entry.rb +29 -0
  57. data/lib/selenium/webdriver/common/logs.rb +23 -0
  58. data/lib/selenium/webdriver/common/mouse.rb +72 -0
  59. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  60. data/lib/selenium/webdriver/common/options.rb +136 -0
  61. data/lib/selenium/webdriver/common/platform.rb +218 -0
  62. data/lib/selenium/webdriver/common/port_prober.rb +42 -0
  63. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  64. data/lib/selenium/webdriver/common/proxy.rb +149 -0
  65. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  66. data/lib/selenium/webdriver/common/socket_poller.rb +105 -0
  67. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  68. data/lib/selenium/webdriver/common/timeouts.rb +38 -0
  69. data/lib/selenium/webdriver/common/touch_action_builder.rb +64 -0
  70. data/lib/selenium/webdriver/common/touch_screen.rb +105 -0
  71. data/lib/selenium/webdriver/common/wait.rb +63 -0
  72. data/lib/selenium/webdriver/common/window.rb +104 -0
  73. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  74. data/lib/selenium/webdriver/firefox.rb +37 -0
  75. data/lib/selenium/webdriver/firefox/binary.rb +158 -0
  76. data/lib/selenium/webdriver/firefox/bridge.rb +70 -0
  77. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  78. data/lib/selenium/webdriver/firefox/launcher.rb +106 -0
  79. data/lib/selenium/webdriver/firefox/profile.rb +263 -0
  80. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  81. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  82. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  83. data/lib/selenium/webdriver/ie.rb +19 -0
  84. data/lib/selenium/webdriver/ie/bridge.rb +68 -0
  85. data/lib/selenium/webdriver/ie/server.rb +86 -0
  86. data/lib/selenium/webdriver/iphone.rb +9 -0
  87. data/lib/selenium/webdriver/iphone/bridge.rb +45 -0
  88. data/lib/selenium/webdriver/opera.rb +24 -0
  89. data/lib/selenium/webdriver/opera/bridge.rb +112 -0
  90. data/lib/selenium/webdriver/opera/service.rb +49 -0
  91. data/lib/selenium/webdriver/phantomjs.rb +22 -0
  92. data/lib/selenium/webdriver/phantomjs/bridge.rb +59 -0
  93. data/lib/selenium/webdriver/phantomjs/service.rb +90 -0
  94. data/lib/selenium/webdriver/remote.rb +22 -0
  95. data/lib/selenium/webdriver/remote/bridge.rb +644 -0
  96. data/lib/selenium/webdriver/remote/capabilities.rb +267 -0
  97. data/lib/selenium/webdriver/remote/commands.rb +193 -0
  98. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  99. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  100. data/lib/selenium/webdriver/remote/http/default.rb +139 -0
  101. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  102. data/lib/selenium/webdriver/remote/response.rb +97 -0
  103. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  104. data/lib/selenium/webdriver/safari.rb +46 -0
  105. data/lib/selenium/webdriver/safari/bridge.rb +110 -0
  106. data/lib/selenium/webdriver/safari/browser.rb +20 -0
  107. data/lib/selenium/webdriver/safari/extension.rb +120 -0
  108. data/lib/selenium/webdriver/safari/server.rb +145 -0
  109. data/lib/selenium/webdriver/support.rb +5 -0
  110. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  111. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  112. data/lib/selenium/webdriver/support/color.rb +110 -0
  113. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  114. data/lib/selenium/webdriver/support/select.rb +293 -0
  115. data/ruby.iml +13 -0
  116. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  117. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  118. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  119. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  120. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  121. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  122. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  123. data/spec/integration/selenium/client/api/screenshot_spec.rb +31 -0
  124. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  125. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  126. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  127. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  128. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  129. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  130. data/spec/integration/selenium/client/api/webdriver_backed_spec.rb +21 -0
  131. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  132. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  133. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  134. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  135. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  136. data/spec/integration/selenium/client/spec_helper.rb +139 -0
  137. data/spec/integration/selenium/webdriver/app_cache_spec.rb +47 -0
  138. data/spec/integration/selenium/webdriver/browser_connection_spec.rb +20 -0
  139. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  140. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +63 -0
  141. data/spec/integration/selenium/webdriver/driver_spec.rb +266 -0
  142. data/spec/integration/selenium/webdriver/element_spec.rb +191 -0
  143. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  144. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  145. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  146. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  147. data/spec/integration/selenium/webdriver/location_spec.rb +29 -0
  148. data/spec/integration/selenium/webdriver/mouse_spec.rb +57 -0
  149. data/spec/integration/selenium/webdriver/navigation_spec.rb +46 -0
  150. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  151. data/spec/integration/selenium/webdriver/options_spec.rb +77 -0
  152. data/spec/integration/selenium/webdriver/remote/driver_spec.rb +19 -0
  153. data/spec/integration/selenium/webdriver/remote/element_spec.rb +26 -0
  154. data/spec/integration/selenium/webdriver/spec_helper.rb +36 -0
  155. data/spec/integration/selenium/webdriver/spec_support.rb +12 -0
  156. data/spec/integration/selenium/webdriver/spec_support/guards.rb +110 -0
  157. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +51 -0
  158. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  159. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +239 -0
  160. data/spec/integration/selenium/webdriver/sql_database_spec.rb +59 -0
  161. data/spec/integration/selenium/webdriver/storage_spec.rb +96 -0
  162. data/spec/integration/selenium/webdriver/target_locator_spec.rb +186 -0
  163. data/spec/integration/selenium/webdriver/timeout_spec.rb +69 -0
  164. data/spec/integration/selenium/webdriver/touch_spec.rb +176 -0
  165. data/spec/integration/selenium/webdriver/window_spec.rb +70 -0
  166. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  167. data/spec/unit/selenium/client/base_spec.rb +239 -0
  168. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  169. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  170. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  171. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  172. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  173. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  174. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  175. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  176. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  177. data/spec/unit/selenium/server_spec.rb +150 -0
  178. data/spec/unit/selenium/webdriver/action_builder_spec.rb +97 -0
  179. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +43 -0
  180. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +137 -0
  181. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  182. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  183. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  184. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +47 -0
  185. data/spec/unit/selenium/webdriver/ie/bridge_spec.rb +91 -0
  186. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +42 -0
  187. data/spec/unit/selenium/webdriver/log_entry_spec.rb +11 -0
  188. data/spec/unit/selenium/webdriver/opera/bridge_spec.rb +44 -0
  189. data/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb +55 -0
  190. data/spec/unit/selenium/webdriver/proxy_spec.rb +106 -0
  191. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  192. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +115 -0
  193. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  194. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +124 -0
  195. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  196. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  197. data/spec/unit/selenium/webdriver/spec_helper.rb +27 -0
  198. data/spec/unit/selenium/webdriver/support/color_spec.rb +119 -0
  199. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  200. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  201. data/spec/unit/selenium/webdriver/wait_spec.rb +49 -0
  202. metadata +370 -0
@@ -0,0 +1,74 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Remote
4
+ module Http
5
+ class Common
6
+ MAX_REDIRECTS = 20 # same as chromium/gecko
7
+ CONTENT_TYPE = "application/json"
8
+ DEFAULT_HEADERS = { "Accept" => CONTENT_TYPE }
9
+
10
+ attr_accessor :timeout
11
+ attr_writer :server_url
12
+
13
+ def initialize
14
+ @timeout = nil
15
+ end
16
+
17
+ def close
18
+ # hook for subclasses - will be called on Driver#quit
19
+ end
20
+
21
+ def call(verb, url, command_hash)
22
+ url = server_url.merge(url) unless url.kind_of?(URI)
23
+ headers = DEFAULT_HEADERS.dup
24
+ headers['Cache-Control'] = "no-cache" if verb == :get
25
+
26
+ if command_hash
27
+ payload = WebDriver.json_dump(command_hash)
28
+ headers["Content-Type"] = "#{CONTENT_TYPE}; charset=utf-8"
29
+ headers["Content-Length"] = payload.bytesize.to_s if [:post, :put].include?(verb)
30
+
31
+ if $DEBUG
32
+ puts " >>> #{url} | #{payload}"
33
+ puts " > #{headers.inspect}"
34
+ end
35
+ elsif verb == :post
36
+ payload = "{}" # work around http://code.google.com/p/selenium/issues/detail?id=1396
37
+ headers["Content-Length"] = "2"
38
+ end
39
+
40
+ request verb, url, headers, payload
41
+ end
42
+
43
+ private
44
+
45
+ def server_url
46
+ @server_url or raise Error::WebDriverError, "server_url not set"
47
+ end
48
+
49
+ def request(verb, url, headers, payload)
50
+ raise NotImplementedError, "subclass responsibility"
51
+ end
52
+
53
+ def create_response(code, body, content_type)
54
+ code, body, content_type = code.to_i, body.to_s.strip, content_type.to_s
55
+ puts "<- #{body}\n" if $DEBUG
56
+
57
+ if content_type.include? CONTENT_TYPE
58
+ raise Error::WebDriverError, "empty body: #{content_type.inspect} (#{code})\n#{body}" if body.empty?
59
+ Response.new(code, WebDriver.json_load(body))
60
+ elsif code == 204
61
+ Response.new(code)
62
+ else
63
+ msg = "unexpected response, code=#{code}, content-type=#{content_type.inspect}"
64
+ msg << "\n#{body}" unless body.empty?
65
+
66
+ raise Error::WebDriverError, msg
67
+ end
68
+ end
69
+
70
+ end # Common
71
+ end # Http
72
+ end # Remote
73
+ end # WebDriver
74
+ end # Selenium
@@ -0,0 +1,79 @@
1
+ require 'curb'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+
7
+ # added for rescue
8
+ Bridge::QUIT_ERRORS << Curl::Err::RecvError
9
+
10
+ module Http
11
+
12
+ #
13
+ # An alternative to the default Net::HTTP client.
14
+ #
15
+ # This can be used for the Firefox and Remote drivers if you have Curb
16
+ # installed.
17
+ #
18
+ # @example Using Curb
19
+ # require 'selenium/webdriver/remote/http/curb'
20
+ # include Selenium
21
+ #
22
+ # driver = WebDriver.for :firefox, :http_client => WebDriver::Remote::Http::Curb.new
23
+ #
24
+
25
+ class Curb < Common
26
+
27
+ private
28
+
29
+ def request(verb, url, headers, payload)
30
+ client.url = url.to_s
31
+
32
+ # workaround for http://github.com/taf2/curb/issues/issue/40
33
+ # curb will handle this for us anyway
34
+ headers.delete "Content-Length"
35
+
36
+ client.headers = headers
37
+
38
+ # http://github.com/taf2/curb/issues/issue/33
39
+ client.head = false
40
+ client.delete = false
41
+
42
+ case verb
43
+ when :get
44
+ client.http_get
45
+ when :post
46
+ client.post_body = payload || ""
47
+ client.http_post
48
+ when :put
49
+ client.put_data = payload || ""
50
+ client.http_put
51
+ when :delete
52
+ client.http_delete
53
+ when :head
54
+ client.http_head
55
+ else
56
+ raise Error::WebDriverError, "unknown HTTP verb: #{verb.inspect}"
57
+ end
58
+
59
+ create_response client.response_code, client.body_str, client.content_type
60
+ end
61
+
62
+ def client
63
+ @client ||= (
64
+ c = Curl::Easy.new
65
+
66
+ c.max_redirects = MAX_REDIRECTS
67
+ c.follow_location = true
68
+ c.timeout = @timeout if @timeout
69
+ c.verbose = !!$DEBUG
70
+
71
+ c
72
+ )
73
+ end
74
+
75
+ end # Curb
76
+ end # Http
77
+ end # Remote
78
+ end # WebDriver
79
+ end # Selenium
@@ -0,0 +1,139 @@
1
+ require 'net/https'
2
+ require 'ipaddr'
3
+
4
+ module Selenium
5
+ module WebDriver
6
+ module Remote
7
+ module Http
8
+
9
+ # @api private
10
+ class Default < Common
11
+ attr_accessor :proxy
12
+
13
+ private
14
+
15
+ def http
16
+ @http ||= (
17
+ http = new_http_client
18
+ if server_url.scheme == "https"
19
+ http.use_ssl = true
20
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
21
+ end
22
+
23
+ if @timeout
24
+ http.open_timeout = @timeout
25
+ http.read_timeout = @timeout
26
+ end
27
+
28
+ http
29
+ )
30
+ end
31
+
32
+ MAX_RETRIES = 3
33
+
34
+ def request(verb, url, headers, payload, redirects = 0)
35
+ request = new_request_for(verb, url, headers, payload)
36
+
37
+ retries = 0
38
+ begin
39
+ response = response_for(request)
40
+ rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE
41
+ # a retry is sometimes needed on Windows XP where we may quickly
42
+ # run out of ephemeral ports
43
+ #
44
+ # A more robust solution is bumping the MaxUserPort setting
45
+ # as described here:
46
+ #
47
+ # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
48
+ raise if retries >= MAX_RETRIES
49
+
50
+ request = new_request_for(verb, url, headers, payload)
51
+ retries += 1
52
+
53
+ retry
54
+ rescue Errno::ECONNREFUSED => ex
55
+ if use_proxy?
56
+ raise ex.class, "using proxy: #{proxy.http}"
57
+ else
58
+ raise
59
+ end
60
+ end
61
+
62
+ if response.kind_of? Net::HTTPRedirection
63
+ raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS
64
+ request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
65
+ else
66
+ create_response response.code, response.body, response.content_type
67
+ end
68
+ end
69
+
70
+ def new_request_for(verb, url, headers, payload)
71
+ req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
72
+
73
+ if server_url.userinfo
74
+ req.basic_auth server_url.user, server_url.password
75
+ end
76
+
77
+ req.body = payload if payload
78
+
79
+ req
80
+ end
81
+
82
+ def response_for(request)
83
+ http.request request
84
+ end
85
+
86
+ def new_http_client
87
+ if use_proxy?
88
+ unless proxy.respond_to?(:http) && url = @proxy.http
89
+ raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"
90
+ end
91
+
92
+ proxy = URI.parse(url)
93
+
94
+ clazz = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password)
95
+ clazz.new(server_url.host, server_url.port)
96
+ else
97
+ Net::HTTP.new server_url.host, server_url.port
98
+ end
99
+ end
100
+
101
+ def proxy
102
+ @proxy ||= (
103
+ proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
104
+ no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
105
+
106
+ if proxy
107
+ proxy = "http://#{proxy}" unless proxy.start_with?("http://")
108
+ Proxy.new(:http => proxy, :no_proxy => no_proxy)
109
+ end
110
+ )
111
+ end
112
+
113
+ def use_proxy?
114
+ return false if proxy.nil?
115
+
116
+ if proxy.no_proxy
117
+ ignored = proxy.no_proxy.split(",").any? do |host|
118
+ host == "*" ||
119
+ host == server_url.host || (
120
+ begin
121
+ IPAddr.new(host).include?(server_url.host)
122
+ rescue ArgumentError => ex
123
+ false
124
+ end
125
+ )
126
+
127
+ end
128
+
129
+ not ignored
130
+ else
131
+ true
132
+ end
133
+ end
134
+
135
+ end # Default
136
+ end # Http
137
+ end # Remote
138
+ end # WebDriver
139
+ end # Selenium
@@ -0,0 +1,38 @@
1
+ require 'net/http/persistent'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Remote
6
+ module Http
7
+
8
+ # @api private
9
+ class Persistent < Default
10
+
11
+ def close
12
+ @http.shutdown if @http
13
+ end
14
+
15
+ private
16
+
17
+ def new_http_client
18
+ proxy = nil
19
+
20
+ if @proxy
21
+ unless @proxy.respond_to?(:http) && url = @proxy.http
22
+ raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"
23
+ end
24
+ proxy = URI.parse(url)
25
+ end
26
+
27
+ Net::HTTP::Persistent.new "webdriver", proxy
28
+ end
29
+
30
+ def response_for(request)
31
+ http.request server_url, request
32
+ end
33
+
34
+ end # Persistent
35
+ end # Http
36
+ end # Remote
37
+ end # WebDriver
38
+ end # Selenium
@@ -0,0 +1,97 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Remote
4
+
5
+ # @api private
6
+ class Response
7
+
8
+ attr_reader :code, :payload
9
+ attr_writer :payload
10
+
11
+ def initialize(code, payload = nil)
12
+ @code = code
13
+ @payload = payload || {}
14
+
15
+ assert_ok
16
+ end
17
+
18
+ def error
19
+ klass = Error.for_code(status) || return
20
+
21
+ ex = klass.new(error_message)
22
+ ex.set_backtrace(caller)
23
+ add_backtrace ex
24
+
25
+ ex
26
+ end
27
+
28
+ def error_message
29
+ val = value
30
+
31
+ case val
32
+ when Hash
33
+ msg = val['message'] or return "unknown error"
34
+ msg << " (#{ val['class'] })" if val['class']
35
+ when String
36
+ msg = val
37
+ else
38
+ msg = "unknown error, status=#{status}: #{val.inspect}"
39
+ end
40
+
41
+ msg
42
+ end
43
+
44
+ def [](key)
45
+ @payload[key]
46
+ end
47
+
48
+ private
49
+
50
+ def assert_ok
51
+ if e = error()
52
+ raise e
53
+ elsif @code.nil? || @code >= 400
54
+ raise Error::ServerError, self
55
+ end
56
+ end
57
+
58
+ def add_backtrace(ex)
59
+ unless value.kind_of?(Hash) && value['stackTrace']
60
+ return
61
+ end
62
+
63
+ server_trace = value['stackTrace']
64
+
65
+ backtrace = server_trace.map do |frame|
66
+ next unless frame.kind_of?(Hash)
67
+
68
+ file = frame['fileName']
69
+ line = frame['lineNumber']
70
+ meth = frame['methodName']
71
+
72
+ if class_name = frame['className']
73
+ file = "#{class_name}(#{file})"
74
+ end
75
+
76
+ if meth.nil? || meth.empty?
77
+ meth = 'unknown'
78
+ end
79
+
80
+ "[remote server] #{file}:#{line}:in `#{meth}'"
81
+ end.compact
82
+
83
+ ex.set_backtrace(backtrace + ex.backtrace)
84
+ end
85
+
86
+ def status
87
+ @payload['status']
88
+ end
89
+
90
+ def value
91
+ @payload['value']
92
+ end
93
+
94
+ end # Response
95
+ end # Remote
96
+ end # WebDriver
97
+ end # Selenium
@@ -0,0 +1,17 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Error
4
+ class ServerError < StandardError
5
+
6
+ def initialize(response)
7
+ if response.kind_of? String
8
+ super(response)
9
+ else
10
+ super("status code #{response.code}")
11
+ end
12
+ end
13
+ end
14
+
15
+ end # Error
16
+ end # WebDriver
17
+ end # Selenium