bbc-selenium-webdriver 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/CHANGES +473 -0
  2. data/README +31 -0
  3. data/lib/selenium-client.rb +2 -0
  4. data/lib/selenium-webdriver.rb +1 -0
  5. data/lib/selenium/client.rb +37 -0
  6. data/lib/selenium/client/base.rb +118 -0
  7. data/lib/selenium/client/driver.rb +10 -0
  8. data/lib/selenium/client/errors.rb +9 -0
  9. data/lib/selenium/client/extensions.rb +118 -0
  10. data/lib/selenium/client/idiomatic.rb +488 -0
  11. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  12. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  13. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  14. data/lib/selenium/client/legacy_driver.rb +1720 -0
  15. data/lib/selenium/client/protocol.rb +104 -0
  16. data/lib/selenium/client/selenium_helper.rb +34 -0
  17. data/lib/selenium/rake/server_task.rb +157 -0
  18. data/lib/selenium/server.rb +223 -0
  19. data/lib/selenium/webdriver.rb +64 -0
  20. data/lib/selenium/webdriver/android.rb +9 -0
  21. data/lib/selenium/webdriver/android/bridge.rb +51 -0
  22. data/lib/selenium/webdriver/chrome.rb +26 -0
  23. data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
  24. data/lib/selenium/webdriver/chrome/profile.rb +83 -0
  25. data/lib/selenium/webdriver/chrome/service.rb +74 -0
  26. data/lib/selenium/webdriver/common.rb +30 -0
  27. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  28. data/lib/selenium/webdriver/common/alert.rb +26 -0
  29. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  30. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  31. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  32. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  33. data/lib/selenium/webdriver/common/driver.rb +301 -0
  34. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  35. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  38. data/lib/selenium/webdriver/common/element.rb +262 -0
  39. data/lib/selenium/webdriver/common/error.rb +212 -0
  40. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  41. data/lib/selenium/webdriver/common/keyboard.rb +52 -0
  42. data/lib/selenium/webdriver/common/keys.rb +109 -0
  43. data/lib/selenium/webdriver/common/mouse.rb +65 -0
  44. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  45. data/lib/selenium/webdriver/common/options.rb +128 -0
  46. data/lib/selenium/webdriver/common/platform.rb +166 -0
  47. data/lib/selenium/webdriver/common/port_prober.rb +25 -0
  48. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  49. data/lib/selenium/webdriver/common/proxy.rb +120 -0
  50. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  51. data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
  52. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  53. data/lib/selenium/webdriver/common/timeouts.rb +29 -0
  54. data/lib/selenium/webdriver/common/wait.rb +60 -0
  55. data/lib/selenium/webdriver/common/window.rb +96 -0
  56. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  57. data/lib/selenium/webdriver/firefox.rb +37 -0
  58. data/lib/selenium/webdriver/firefox/binary.rb +161 -0
  59. data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
  60. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  61. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  62. data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
  63. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  64. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  65. data/lib/selenium/webdriver/firefox/profile.rb +315 -0
  66. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  67. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  68. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  69. data/lib/selenium/webdriver/ie.rb +19 -0
  70. data/lib/selenium/webdriver/ie/bridge.rb +60 -0
  71. data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
  72. data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
  73. data/lib/selenium/webdriver/ie/server.rb +64 -0
  74. data/lib/selenium/webdriver/iphone.rb +9 -0
  75. data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
  76. data/lib/selenium/webdriver/opera.rb +24 -0
  77. data/lib/selenium/webdriver/opera/bridge.rb +113 -0
  78. data/lib/selenium/webdriver/opera/service.rb +49 -0
  79. data/lib/selenium/webdriver/remote.rb +21 -0
  80. data/lib/selenium/webdriver/remote/bridge.rb +473 -0
  81. data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
  82. data/lib/selenium/webdriver/remote/commands.rb +181 -0
  83. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  84. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  85. data/lib/selenium/webdriver/remote/http/default.rb +102 -0
  86. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  87. data/lib/selenium/webdriver/remote/response.rb +99 -0
  88. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  89. data/lib/selenium/webdriver/support.rb +4 -0
  90. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  91. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  92. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  93. data/lib/selenium/webdriver/support/select.rb +293 -0
  94. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  95. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  96. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  97. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  98. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  99. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  100. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  101. data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
  102. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  103. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  104. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  105. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  106. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  107. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  108. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  109. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  110. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  111. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  112. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  113. data/spec/integration/selenium/client/spec_helper.rb +125 -0
  114. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  115. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
  116. data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
  117. data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
  118. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  119. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  120. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  121. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  122. data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
  123. data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
  124. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  125. data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
  126. data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
  127. data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
  128. data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
  129. data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
  130. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
  131. data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
  132. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  133. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
  134. data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
  135. data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
  136. data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
  137. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  138. data/spec/unit/selenium/client/base_spec.rb +239 -0
  139. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  140. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  141. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  142. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  143. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  144. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  145. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  146. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  147. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  148. data/spec/unit/selenium/server_spec.rb +131 -0
  149. data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
  150. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
  151. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
  152. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  153. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  154. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  155. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
  156. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
  157. data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
  158. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  159. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
  160. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  161. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
  162. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  163. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  164. data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
  165. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  166. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  167. data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
  168. metadata +215 -0
@@ -0,0 +1,241 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Remote
4
+ #
5
+ # Specification of the desired and/or actual capabilities of the browser that the
6
+ # server is being asked to create.
7
+ #
8
+ class Capabilities
9
+
10
+ DEFAULTS = {
11
+ :browser_name => "",
12
+ :version => "",
13
+ :platform => :any,
14
+ :javascript_enabled => false,
15
+ :css_selectors_enabled => false,
16
+ :takes_screenshot => false,
17
+ :native_events => false,
18
+ :rotatable => false,
19
+ :firefox_profile => nil,
20
+ :proxy => nil
21
+ }
22
+
23
+ DEFAULTS.each_key do |key|
24
+ define_method key do
25
+ @capabilities.fetch(key)
26
+ end
27
+
28
+ define_method "#{key}=" do |value|
29
+ @capabilities[key] = value
30
+ end
31
+ end
32
+
33
+ alias_method :css_selectors_enabled?, :css_selectors_enabled
34
+ alias_method :javascript_enabled? , :javascript_enabled
35
+ alias_method :native_events? , :native_events
36
+ alias_method :takes_screenshot? , :takes_screenshot
37
+ alias_method :rotatable? , :rotatable
38
+
39
+ #
40
+ # Convenience methods for the common choices.
41
+ #
42
+
43
+ class << self
44
+ def android(opts = {})
45
+ new({
46
+ :browser_name => "android",
47
+ :platform => :android,
48
+ :rotatable => true,
49
+ :takes_screenshot => true
50
+ }.merge(opts))
51
+ end
52
+
53
+ def chrome(opts = {})
54
+ new({
55
+ :browser_name => "chrome",
56
+ :javascript_enabled => true,
57
+ :css_selectors_enabled => true
58
+ }.merge(opts))
59
+ end
60
+
61
+ def firefox(opts = {})
62
+ new({
63
+ :browser_name => "firefox",
64
+ :javascript_enabled => true,
65
+ :takes_screenshot => true,
66
+ :css_selectors_enabled => true
67
+ }.merge(opts))
68
+ end
69
+
70
+ def htmlunit(opts = {})
71
+ new({
72
+ :browser_name => "htmlunit"
73
+ }.merge(opts))
74
+ end
75
+
76
+ def internet_explorer(opts = {})
77
+ new({
78
+ :browser_name => "internet explorer",
79
+ :platform => :windows,
80
+ :takes_screenshot => true,
81
+ :css_selectors_enabled => true
82
+ }.merge(opts))
83
+ end
84
+ alias_method :ie, :internet_explorer
85
+
86
+ def iphone(opts = {})
87
+ new({
88
+ :browser_name => "iPhone",
89
+ :platform => :mac,
90
+ :javascript_enabled => true
91
+ }.merge(opts))
92
+ end
93
+
94
+ def ipad(opts = {})
95
+ new({
96
+ :browser_name => "iPad",
97
+ :platform => :mac,
98
+ :javascript_enabled => true
99
+ }.merge(opts))
100
+ end
101
+
102
+ def opera(opts = {})
103
+ new({
104
+ :browser_name => "opera",
105
+ :javascript_enabled => true,
106
+ :takes_screenshot => true,
107
+ :css_selectors_enabled => true
108
+ }.merge(opts))
109
+ end
110
+
111
+ #
112
+ # @api private
113
+ #
114
+
115
+ def json_create(data)
116
+ data = data.dup
117
+
118
+ caps = new
119
+ caps.browser_name = data.delete("browserName")
120
+ caps.version = data.delete("version")
121
+ caps.platform = data.delete("platform").downcase.to_sym
122
+ caps.javascript_enabled = data.delete("javascriptEnabled")
123
+ caps.css_selectors_enabled = data.delete("cssSelectorsEnabled")
124
+ caps.takes_screenshot = data.delete("takesScreenshot")
125
+ caps.native_events = data.delete("nativeEvents")
126
+ caps.rotatable = data.delete("rotatable")
127
+ caps.proxy = Proxy.json_create(data['proxy']) if data.has_key?('proxy')
128
+
129
+ # any remaining pairs will be added as is, with no conversion
130
+ caps.merge!(data)
131
+
132
+ caps
133
+ end
134
+ end
135
+
136
+ # @option :browser_name [String] required browser name
137
+ # @option :version [String] required browser version number
138
+ # @option :platform [Symbol] one of :any, :win, :mac, or :x
139
+ # @option :javascript_enabled [Boolean] does the driver have javascript enabled?
140
+ # @option :css_selectors_enabled [Boolean] does the driver support CSS selectors?
141
+ # @option :takes_screenshot [Boolean] can this driver take screenshots?
142
+ # @option :native_events [Boolean] does this driver use native events?
143
+ # @option :proxy [Selenium::WebDriver::Proxy, Hash] proxy configuration
144
+ #
145
+ # Firefox-specific options:
146
+ #
147
+ # @option :firefox_profile [Selenium::WebDriver::Firefox::Profile] the firefox profile to use
148
+ #
149
+ # @api public
150
+ #
151
+
152
+ def initialize(opts = {})
153
+ @capabilities = DEFAULTS.merge(opts)
154
+ self.proxy = opts.delete(:proxy)
155
+ end
156
+
157
+ #
158
+ # Allows setting arbitrary capabilities.
159
+ #
160
+
161
+ def []=(key, value)
162
+ @capabilities[key] = value
163
+ end
164
+
165
+ def [](key)
166
+ @capabilities[key]
167
+ end
168
+
169
+ def merge!(other)
170
+ if other.respond_to?(:capabilities) && other.capabilities.kind_of?(Hash)
171
+ @capabilities.merge! other.capabilities
172
+ elsif other.kind_of? Hash
173
+ @capabilities.merge! other
174
+ else
175
+ raise ArgumentError, "argument should be a Hash or implement #capabilities"
176
+ end
177
+ end
178
+
179
+ def proxy=(proxy)
180
+ case proxy
181
+ when Hash
182
+ @capabilities[:proxy] = Proxy.new(proxy)
183
+ when Proxy, nil
184
+ @capabilities[:proxy] = proxy
185
+ else
186
+ raise TypeError, "expected Hash or #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}"
187
+ end
188
+ end
189
+
190
+ # @api private
191
+ #
192
+
193
+ def as_json(opts = nil)
194
+ hash = {}
195
+
196
+ @capabilities.each do |key, value|
197
+ case key
198
+ when :platform
199
+ hash['platform'] = value.to_s.upcase
200
+ when :firefox_profile
201
+ hash['firefox_profile'] = value.as_json['zip'] if value
202
+ when :proxy
203
+ hash['proxy'] = value.as_json if value
204
+ when String
205
+ hash[key] = value
206
+ when Symbol
207
+ hash[camel_case(key.to_s)] = value
208
+ else
209
+ raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class} / #{value.inspect}"
210
+ end
211
+ end
212
+
213
+ hash
214
+ end
215
+
216
+ def to_json(*args)
217
+ MultiJson.encode as_json
218
+ end
219
+
220
+ def ==(other)
221
+ return false unless other.kind_of? self.class
222
+ as_json == other.as_json
223
+ end
224
+ alias_method :eql?, :==
225
+
226
+ protected
227
+
228
+ def capabilities
229
+ @capabilities
230
+ end
231
+
232
+ private
233
+
234
+ def camel_case(str)
235
+ str.gsub(/_([a-z])/) { $1.upcase }
236
+ end
237
+
238
+ end # Capabilities
239
+ end # Remote
240
+ end # WebDriver
241
+ end # Selenium
@@ -0,0 +1,181 @@
1
+ # @api private
2
+ class Selenium::WebDriver::Remote::Bridge
3
+
4
+ #
5
+ # http://code.google.com/p/selenium/wiki/JsonWireProtocol#Command_Reference
6
+ #
7
+
8
+ command :newSession, :post, "session"
9
+ command :getCapabilities, :get, "session/:session_id"
10
+
11
+ #
12
+ # basic driver
13
+ #
14
+
15
+ command :getCurrentUrl, :get, "session/:session_id/url"
16
+ command :get, :post, "session/:session_id/url"
17
+ command :goForward, :post, "session/:session_id/forward"
18
+ command :goBack, :post, "session/:session_id/back"
19
+ command :refresh, :post, "session/:session_id/refresh"
20
+ command :quit, :delete, "session/:session_id"
21
+ command :close, :delete, "session/:session_id/window"
22
+ command :getVisible, :get, "session/:session_id/visible"
23
+ command :setVisible, :post, "session/:session_id/visible"
24
+ command :getPageSource, :get, "session/:session_id/source"
25
+ command :getTitle, :get, "session/:session_id/title"
26
+ command :findElement, :post, "session/:session_id/element"
27
+ command :findElements, :post, "session/:session_id/elements"
28
+ command :getActiveElement, :post, "session/:session_id/element/active"
29
+
30
+ #
31
+ # window handling
32
+ #
33
+
34
+ command :getCurrentWindowHandle, :get, "session/:session_id/window_handle"
35
+ command :getWindowHandles, :get, "session/:session_id/window_handles"
36
+ command :setWindowSize, :post, "session/:session_id/window/:window_handle/size"
37
+ command :setWindowPosition, :post, "session/:session_id/window/:window_handle/position"
38
+ command :getWindowSize, :get, "session/:session_id/window/:window_handle/size"
39
+ command :getWindowPosition, :get, "session/:session_id/window/:window_handle/position"
40
+
41
+ #
42
+ # script execution
43
+ #
44
+
45
+ command :executeScript, :post, "session/:session_id/execute"
46
+ command :executeAsyncScript, :post, "session/:session_id/execute_async"
47
+
48
+ #
49
+ # screenshot
50
+ #
51
+
52
+ command :screenshot, :get, "session/:session_id/screenshot"
53
+
54
+ #
55
+ # alerts
56
+ #
57
+
58
+ command :dismissAlert, :post, "session/:session_id/dismiss_alert"
59
+ command :acceptAlert, :post, "session/:session_id/accept_alert"
60
+ command :getAlertText, :get, "session/:session_id/alert_text"
61
+ command :setAlertValue, :post, "session/:session_id/alert_text"
62
+
63
+ #
64
+ # target locator
65
+ #
66
+
67
+ command :switchToFrame, :post, "session/:session_id/frame"
68
+ command :switchToWindow, :post, "session/:session_id/window"
69
+
70
+ #
71
+ # options
72
+ #
73
+
74
+ command :getAllCookies, :get, "session/:session_id/cookie"
75
+ command :addCookie, :post, "session/:session_id/cookie"
76
+ command :deleteAllCookies, :delete, "session/:session_id/cookie"
77
+ command :deleteCookieNamed, :delete, "session/:session_id/cookie/:name"
78
+
79
+ #
80
+ # timeouts
81
+ #
82
+
83
+ command :setImplicitWaitTimeout, :post, "session/:session_id/timeouts/implicit_wait"
84
+ command :setScriptTimeout, :post, "session/:session_id/timeouts/async_script"
85
+
86
+ #
87
+ # element
88
+ #
89
+
90
+ command :describeElement, :get, "session/:session_id/element/:id"
91
+ command :findChildElement, :post, "session/:session_id/element/:id/element"
92
+ command :findChildElements, :post, "session/:session_id/element/:id/elements"
93
+ command :clickElement, :post, "session/:session_id/element/:id/click"
94
+ command :submitElement, :post, "session/:session_id/element/:id/submit"
95
+ command :getElementValue, :get, "session/:session_id/element/:id/value"
96
+ command :sendKeysToElement, :post, "session/:session_id/element/:id/value"
97
+ command :uploadFile, :post, "session/:session_id/file"
98
+ command :getElementTagName, :get, "session/:session_id/element/:id/name"
99
+ command :clearElement, :post, "session/:session_id/element/:id/clear"
100
+ command :isElementSelected, :get, "session/:session_id/element/:id/selected"
101
+ command :setElementSelected, :post, "session/:session_id/element/:id/selected"
102
+ command :isElementEnabled, :get, "session/:session_id/element/:id/enabled"
103
+ command :getElementAttribute, :get, "session/:session_id/element/:id/attribute/:name"
104
+ command :elementEquals, :get, "session/:session_id/element/:id/equals/:other"
105
+ command :isElementDisplayed, :get, "session/:session_id/element/:id/displayed"
106
+ command :getElementLocation, :get, "session/:session_id/element/:id/location"
107
+ command :getElementLocationOnceScrolledIntoView, :get, "session/:session_id/element/:id/location_in_view"
108
+ command :getElementSize, :get, "session/:session_id/element/:id/size"
109
+ command :dragElement, :post, "session/:session_id/element/:id/drag"
110
+ command :getElementValueOfCssProperty, :get, "session/:session_id/element/:id/css/:property_name"
111
+ command :getElementText, :get, "session/:session_id/element/:id/text"
112
+
113
+ #
114
+ # rotatable
115
+ #
116
+
117
+ command :getScreenOrientation, :get, "session/:session_id/orientation"
118
+ command :setScreenOrientation, :post, "session/:session_id/orientation"
119
+
120
+ #
121
+ # interactions API
122
+ #
123
+
124
+ command :click, :post, "session/:session_id/click"
125
+ command :doubleClick, :post, "session/:session_id/doubleclick"
126
+ command :mouseDown, :post, "session/:session_id/buttondown"
127
+ command :mouseUp, :post, "session/:session_id/buttonup"
128
+ command :mouseMoveTo, :post, "session/:session_id/moveto"
129
+ command :sendModifierKeyToActiveElement, :post, "session/:session_id/modifier"
130
+ command :sendKeysToActiveElement, :post, "session/:session_id/keys"
131
+
132
+ #
133
+ # html 5
134
+ #
135
+
136
+ command :executeSql, :post, "session/:session_id/execute_sql"
137
+ command :getLocation, :get, "session/:session_id/location"
138
+ command :setLocation, :post, "session/:session_id/location"
139
+ command :getAppCache, :get, "session/:session_id/application_cache"
140
+ command :getAppCacheStatus, :get, "session/:session_id/application_cache/status"
141
+ command :clearAppCache, :delete, "session/:session_id/application_cache/clear"
142
+ command :isBrowserOnline, :get, "session/:session_id/browser_connection"
143
+ command :setBrowserOnline, :post, "session/:session_id/browser_connection"
144
+
145
+ command :getLocalStorageItem, :get, "session/:session_id/local_storage/key/:key"
146
+ command :removeLocalStorageItem, :delete, "session/:session_id/local_storage/key/:key"
147
+ command :getLocalStorageKeys, :get, "session/:session_id/local_storage"
148
+ command :setLocalStorageItem, :post, "session/:session_id/local_storage"
149
+ command :clearLocalStorage, :delete, "session/:session_id/local_storage"
150
+ command :getLocalStorageSize, :get, "session/:session_id/local_storage/size"
151
+
152
+ command :getSessionStorageItem, :get, "session/:session_id/session_storage/key/:key"
153
+ command :removeSessionStorageItem, :delete, "session/:session_id/session_storage/key/:key"
154
+ command :getSessionStorageKeys, :get, "session/:session_id/session_storage"
155
+ command :setSessionStorageItem, :post, "session/:session_id/session_storage"
156
+ command :clearSessionStorage, :delete, "session/:session_id/session_storage"
157
+ command :getSessionStorageSize, :get, "session/:session_id/session_storage/size"
158
+
159
+ #
160
+ # ime
161
+ #
162
+
163
+ command :imeGetAvailableEngines, :get, "session/:session_id/ime/available_engines"
164
+ command :imeGetActiveEngine, :get, "session/:session_id/ime/active_engine"
165
+ command :imeIsActivated, :get, "session/:session_id/ime/activated"
166
+ command :imeDeactivate, :post, "session/:session_id/ime/deactivate"
167
+ command :imeActivateEngine, :post, "session/:session_id/ime/activate"
168
+
169
+ #
170
+ # touch
171
+ #
172
+
173
+ command :touchSingleTap, :post, "session/:session_id/touch/click"
174
+ command :touchDoubleTap, :post, "session/:session_id/touch/doubleclick"
175
+ command :touchLongPress, :post, "session/:session_id/touch/longclick"
176
+ command :touchDown, :post, "session/:session_id/touch/down"
177
+ command :touchUp, :post, "session/:session_id/touch/up"
178
+ command :touchMove, :post, "session/:session_id/touch/move"
179
+ command :touchScroll, :post, "session/:session_id/touch/scroll"
180
+ command :touchFlick, :post, "session/:session_id/touch/flick"
181
+ end
@@ -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 = MultiJson.encode(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 " >>> #{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, MultiJson.decode(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