selenium-webdriver 4.0.0.alpha1 → 4.0.0.alpha6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +139 -1
  3. data/LICENSE +1 -1
  4. data/lib/selenium/server.rb +3 -3
  5. data/lib/selenium/webdriver.rb +11 -7
  6. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +84 -7
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +75 -77
  9. data/lib/selenium/webdriver/chrome.rb +10 -9
  10. data/lib/selenium/webdriver/chrome/bridge.rb +20 -4
  11. data/lib/selenium/webdriver/chrome/driver.rb +3 -52
  12. data/lib/selenium/webdriver/chrome/options.rb +97 -57
  13. data/lib/selenium/webdriver/chrome/profile.rb +2 -2
  14. data/lib/selenium/webdriver/chrome/service.rb +0 -4
  15. data/lib/selenium/webdriver/common.rb +3 -0
  16. data/lib/selenium/webdriver/common/driver.rb +76 -17
  17. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_devtools.rb} +10 -8
  18. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -1
  19. data/lib/selenium/webdriver/common/logger.rb +48 -16
  20. data/lib/selenium/webdriver/common/manager.rb +5 -0
  21. data/lib/selenium/webdriver/common/options.rb +60 -121
  22. data/lib/selenium/webdriver/common/platform.rb +3 -0
  23. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  24. data/lib/selenium/webdriver/common/profile_helper.rb +10 -2
  25. data/lib/selenium/webdriver/common/proxy.rb +0 -0
  26. data/lib/selenium/webdriver/common/search_context.rb +3 -2
  27. data/lib/selenium/webdriver/common/service.rb +30 -113
  28. data/lib/selenium/webdriver/common/service_manager.rb +151 -0
  29. data/lib/selenium/webdriver/common/socket_lock.rb +2 -2
  30. data/lib/selenium/webdriver/common/wait.rb +1 -1
  31. data/lib/selenium/webdriver/devtools.rb +118 -0
  32. data/lib/selenium/webdriver/devtools/accessibility.rb +62 -0
  33. data/lib/selenium/webdriver/devtools/animation.rb +98 -0
  34. data/lib/selenium/webdriver/devtools/application_cache.rb +64 -0
  35. data/lib/selenium/webdriver/devtools/audits.rb +61 -0
  36. data/lib/selenium/webdriver/devtools/background_service.rb +67 -0
  37. data/lib/selenium/webdriver/devtools/browser.rb +123 -0
  38. data/lib/selenium/webdriver/devtools/cache_storage.rb +73 -0
  39. data/lib/selenium/webdriver/devtools/cast.rb +70 -0
  40. data/lib/selenium/webdriver/devtools/console.rb +57 -0
  41. data/lib/selenium/webdriver/devtools/css.rb +165 -0
  42. data/lib/selenium/webdriver/devtools/database.rb +64 -0
  43. data/lib/selenium/webdriver/devtools/debugger.rb +229 -0
  44. data/lib/selenium/webdriver/devtools/device_orientation.rb +53 -0
  45. data/lib/selenium/webdriver/devtools/dom.rb +320 -0
  46. data/lib/selenium/webdriver/devtools/domdebugger.rb +93 -0
  47. data/lib/selenium/webdriver/devtools/domsnapshot.rb +65 -0
  48. data/lib/selenium/webdriver/devtools/domstorage.rb +79 -0
  49. data/lib/selenium/webdriver/devtools/emulation.rb +180 -0
  50. data/lib/selenium/webdriver/devtools/fetch.rb +97 -0
  51. data/lib/selenium/webdriver/devtools/headless_experimental.rb +61 -0
  52. data/lib/selenium/webdriver/devtools/heap_profiler.rb +107 -0
  53. data/lib/selenium/webdriver/devtools/indexed_db.rb +100 -0
  54. data/lib/selenium/webdriver/devtools/input.rb +140 -0
  55. data/lib/selenium/webdriver/devtools/inspector.rb +55 -0
  56. data/lib/selenium/webdriver/devtools/io.rb +59 -0
  57. data/lib/selenium/webdriver/devtools/layer_tree.rb +95 -0
  58. data/lib/selenium/webdriver/devtools/log.rb +66 -0
  59. data/lib/selenium/webdriver/devtools/media.rb +57 -0
  60. data/lib/selenium/webdriver/devtools/memory.rb +86 -0
  61. data/lib/selenium/webdriver/devtools/network.rb +228 -0
  62. data/lib/selenium/webdriver/devtools/overlay.rb +157 -0
  63. data/lib/selenium/webdriver/devtools/page.rb +374 -0
  64. data/lib/selenium/webdriver/devtools/performance.rb +63 -0
  65. data/lib/selenium/webdriver/devtools/profiler.rb +111 -0
  66. data/lib/selenium/webdriver/devtools/runtime.rb +193 -0
  67. data/lib/selenium/webdriver/devtools/schema.rb +46 -0
  68. data/lib/selenium/webdriver/devtools/security.rb +71 -0
  69. data/lib/selenium/webdriver/devtools/service_worker.rb +116 -0
  70. data/lib/selenium/webdriver/devtools/storage.rb +95 -0
  71. data/lib/selenium/webdriver/devtools/system_info.rb +50 -0
  72. data/lib/selenium/webdriver/devtools/target.rb +141 -0
  73. data/lib/selenium/webdriver/devtools/tethering.rb +55 -0
  74. data/lib/selenium/webdriver/devtools/tracing.rb +76 -0
  75. data/lib/selenium/webdriver/devtools/web_audio.rb +70 -0
  76. data/lib/selenium/webdriver/devtools/web_authn.rb +94 -0
  77. data/lib/selenium/webdriver/edge.rb +29 -9
  78. data/lib/selenium/webdriver/{firefox/util.rb → edge_chrome/bridge.rb} +11 -20
  79. data/lib/selenium/webdriver/{common/w3c_options.rb → edge_chrome/driver.rb} +14 -17
  80. data/lib/selenium/webdriver/edge_chrome/options.rb +36 -0
  81. data/lib/selenium/webdriver/edge_chrome/profile.rb +33 -0
  82. data/lib/selenium/webdriver/edge_chrome/service.rb +36 -0
  83. data/lib/selenium/webdriver/{common/w3c_manager.rb → edge_html/driver.rb} +11 -17
  84. data/lib/selenium/webdriver/{edge → edge_html}/options.rb +26 -22
  85. data/lib/selenium/webdriver/{edge → edge_html}/service.rb +2 -6
  86. data/lib/selenium/webdriver/firefox.rb +18 -15
  87. data/lib/selenium/webdriver/firefox/bridge.rb +1 -1
  88. data/lib/selenium/webdriver/firefox/driver.rb +2 -30
  89. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  90. data/lib/selenium/webdriver/firefox/options.rb +47 -52
  91. data/lib/selenium/webdriver/firefox/profile.rb +7 -78
  92. data/lib/selenium/webdriver/firefox/service.rb +0 -4
  93. data/lib/selenium/webdriver/ie.rb +8 -7
  94. data/lib/selenium/webdriver/ie/driver.rb +0 -32
  95. data/lib/selenium/webdriver/ie/options.rb +10 -33
  96. data/lib/selenium/webdriver/ie/service.rb +5 -9
  97. data/lib/selenium/webdriver/remote.rb +16 -10
  98. data/lib/selenium/webdriver/remote/bridge.rb +34 -42
  99. data/lib/selenium/webdriver/remote/capabilities.rb +22 -6
  100. data/lib/selenium/webdriver/remote/driver.rb +6 -12
  101. data/lib/selenium/webdriver/remote/http/default.rb +9 -4
  102. data/lib/selenium/webdriver/remote/http/persistent.rb +5 -6
  103. data/lib/selenium/webdriver/safari.rb +9 -8
  104. data/lib/selenium/webdriver/safari/bridge.rb +4 -4
  105. data/lib/selenium/webdriver/safari/driver.rb +3 -29
  106. data/lib/selenium/webdriver/safari/options.rb +18 -19
  107. data/lib/selenium/webdriver/safari/service.rb +0 -4
  108. data/lib/selenium/webdriver/support.rb +1 -0
  109. data/lib/selenium/webdriver/support/cdp_client_generator.rb +77 -0
  110. data/lib/selenium/webdriver/support/color.rb +2 -2
  111. data/lib/selenium/webdriver/support/event_firing_bridge.rb +1 -1
  112. data/lib/selenium/webdriver/support/relative_locator.rb +51 -0
  113. data/lib/selenium/webdriver/version.rb +1 -1
  114. data/selenium-webdriver.gemspec +5 -4
  115. metadata +81 -42
  116. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  117. data/lib/selenium/webdriver/common/keyboard.rb +0 -70
  118. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  119. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  120. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  121. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  122. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  123. data/lib/selenium/webdriver/edge/driver.rb +0 -70
  124. data/lib/selenium/webdriver/firefox/binary.rb +0 -110
  125. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  126. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  127. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  128. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  129. data/lib/selenium/webdriver/firefox/marionette/bridge.rb +0 -49
  130. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  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/remote/oss/bridge.rb +0 -594
  134. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  135. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  136. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  137. data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -1,49 +0,0 @@
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 Firefox
23
- module Marionette
24
- module Bridge
25
-
26
- COMMANDS = {
27
- install_addon: [:post, 'session/:session_id/moz/addon/install'],
28
- uninstall_addon: [:post, 'session/:session_id/moz/addon/uninstall']
29
- }.freeze
30
-
31
- def commands(command)
32
- COMMANDS[command] || super
33
- end
34
-
35
- def install_addon(path, temporary)
36
- payload = {path: path}
37
- payload[:temporary] = temporary unless temporary.nil?
38
- execute :install_addon, {}, payload
39
- end
40
-
41
- def uninstall_addon(id)
42
- execute :uninstall_addon, {}, {id: id}
43
- end
44
-
45
- end # Bridge
46
- end # Marionette
47
- end # Firefox
48
- end # WebDriver
49
- end # Selenium
@@ -1,90 +0,0 @@
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 Firefox
23
- module Marionette
24
-
25
- #
26
- # Driver implementation for Firefox using GeckoDriver.
27
- # @api private
28
- #
29
-
30
- class Driver < WebDriver::Driver
31
- include DriverExtensions::HasAddons
32
- include DriverExtensions::HasWebStorage
33
- include DriverExtensions::TakesScreenshot
34
-
35
- def initialize(opts = {})
36
- opts[:desired_capabilities] = create_capabilities(opts)
37
-
38
- opts[:url] ||= service_url(opts)
39
-
40
- listener = opts.delete(:listener)
41
- WebDriver.logger.info 'Skipping handshake as we know it is W3C.'
42
- desired_capabilities = opts.delete(:desired_capabilities)
43
- bridge = Remote::Bridge.new(opts)
44
- capabilities = bridge.create_session(desired_capabilities)
45
- @bridge = Remote::W3C::Bridge.new(capabilities, bridge.session_id, opts)
46
- @bridge.extend Marionette::Bridge
47
-
48
- super(@bridge, listener: listener)
49
- end
50
-
51
- def browser
52
- :firefox
53
- end
54
-
55
- def quit
56
- super
57
- ensure
58
- @service&.stop
59
- end
60
-
61
- private
62
-
63
- def create_capabilities(opts)
64
- caps = opts.delete(:desired_capabilities) { Remote::Capabilities.firefox }
65
- options = opts.delete(:options) { Options.new }
66
-
67
- firefox_options = opts.delete(:firefox_options)
68
- if firefox_options
69
- WebDriver.logger.deprecate ':firefox_options', 'Selenium::WebDriver::Firefox::Options'
70
- firefox_options.each do |key, value|
71
- options.add_option(key, value)
72
- end
73
- end
74
-
75
- profile = opts.delete(:profile)
76
- if profile
77
- WebDriver.logger.deprecate ':profile', 'Selenium::WebDriver::Firefox::Options#profile='
78
- options.profile = profile
79
- end
80
-
81
- options = options.as_json
82
- caps.merge!(options) unless options.empty?
83
-
84
- caps
85
- end
86
- end # Driver
87
- end # Marionette
88
- end # Firefox
89
- end # WebDriver
90
- end # Selenium
@@ -1,594 +0,0 @@
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
- module OSS
24
-
25
- #
26
- # Low level bridge to the remote server implementing JSON wire
27
- # protocol (OSS dialect), through which the rest of the API works.
28
- # @api private
29
- #
30
-
31
- class Bridge < Remote::Bridge
32
-
33
- def initialize(capabilities, session_id, **opts)
34
- @capabilities = capabilities
35
- @session_id = session_id
36
- super(opts)
37
- end
38
-
39
- def dialect
40
- :oss
41
- end
42
-
43
- def commands(command)
44
- COMMANDS[command]
45
- end
46
-
47
- def status
48
- execute :status
49
- end
50
-
51
- def get(url)
52
- execute :get, {}, {url: url}
53
- end
54
-
55
- def session_capabilities
56
- Capabilities.json_create execute(:get_capabilities)
57
- end
58
-
59
- def implicit_wait_timeout=(milliseconds)
60
- execute :implicitly_wait, {}, {ms: milliseconds}
61
- end
62
-
63
- def script_timeout=(milliseconds)
64
- execute :set_script_timeout, {}, {ms: milliseconds}
65
- end
66
-
67
- def timeout(type, milliseconds)
68
- execute :set_timeout, {}, {type: type, ms: milliseconds}
69
- end
70
-
71
- #
72
- # alerts
73
- #
74
-
75
- def accept_alert
76
- execute :accept_alert
77
- end
78
-
79
- def dismiss_alert
80
- execute :dismiss_alert
81
- end
82
-
83
- def alert=(keys)
84
- execute :set_alert_value, {}, {text: keys.to_s}
85
- end
86
-
87
- def alert_text
88
- execute :get_alert_text
89
- end
90
-
91
- def authentication(credentials)
92
- execute :set_authentication, {}, credentials
93
- end
94
-
95
- #
96
- # navigation
97
- #
98
-
99
- def go_back
100
- execute :go_back
101
- end
102
-
103
- def go_forward
104
- execute :go_forward
105
- end
106
-
107
- def url
108
- execute :get_current_url
109
- end
110
-
111
- def title
112
- execute :get_title
113
- end
114
-
115
- def page_source
116
- execute :get_page_source
117
- end
118
-
119
- def switch_to_window(name)
120
- execute :switch_to_window, {}, {name: name}
121
- end
122
-
123
- def switch_to_frame(id)
124
- execute :switch_to_frame, {}, {id: id}
125
- end
126
-
127
- def switch_to_parent_frame
128
- execute :switch_to_parent_frame
129
- end
130
-
131
- def switch_to_default_content
132
- switch_to_frame(nil)
133
- end
134
-
135
- def quit
136
- execute :quit
137
- http.close
138
- rescue *http.quit_errors
139
- end
140
-
141
- def close
142
- execute :close
143
- end
144
-
145
- def refresh
146
- execute :refresh
147
- end
148
-
149
- #
150
- # window handling
151
- #
152
-
153
- def window_handles
154
- execute :get_window_handles
155
- end
156
-
157
- def window_handle
158
- execute :get_current_window_handle
159
- end
160
-
161
- def resize_window(width, height, handle = :current)
162
- execute :set_window_size, {window_handle: handle},
163
- {width: width,
164
- height: height}
165
- end
166
-
167
- def maximize_window(handle = :current)
168
- execute :maximize_window, window_handle: handle
169
- end
170
-
171
- def window_size(handle = :current)
172
- data = execute :get_window_size, window_handle: handle
173
-
174
- Dimension.new data['width'], data['height']
175
- end
176
-
177
- def reposition_window(x, y, handle = :current)
178
- execute :set_window_position, {window_handle: handle},
179
- {x: x, y: y}
180
- end
181
-
182
- def window_position(handle = :current)
183
- data = execute :get_window_position, window_handle: handle
184
-
185
- Point.new data['x'], data['y']
186
- end
187
-
188
- def screenshot
189
- execute :screenshot
190
- end
191
-
192
- #
193
- # HTML 5
194
- #
195
-
196
- def local_storage_item(key, value = nil)
197
- if value
198
- execute :set_local_storage_item, {}, {key: key, value: value}
199
- else
200
- execute :get_local_storage_item, key: key
201
- end
202
- end
203
-
204
- def remove_local_storage_item(key)
205
- execute :remove_local_storage_item, key: key
206
- end
207
-
208
- def local_storage_keys
209
- execute :get_local_storage_keys
210
- end
211
-
212
- def clear_local_storage
213
- execute :clear_local_storage
214
- end
215
-
216
- def local_storage_size
217
- execute :get_local_storage_size
218
- end
219
-
220
- def session_storage_item(key, value = nil)
221
- if value
222
- execute :set_session_storage_item, {}, {key: key, value: value}
223
- else
224
- execute :get_session_storage_item, key: key
225
- end
226
- end
227
-
228
- def remove_session_storage_item(key)
229
- execute :remove_session_storage_item, key: key
230
- end
231
-
232
- def session_storage_keys
233
- execute :get_session_storage_keys
234
- end
235
-
236
- def clear_session_storage
237
- execute :clear_session_storage
238
- end
239
-
240
- def session_storage_size
241
- execute :get_session_storage_size
242
- end
243
-
244
- def location
245
- obj = execute(:get_location) || {}
246
- Location.new obj['latitude'], obj['longitude'], obj['altitude']
247
- end
248
-
249
- def set_location(lat, lon, alt)
250
- loc = {latitude: lat, longitude: lon, altitude: alt}
251
- execute :set_location, {}, {location: loc}
252
- end
253
-
254
- def network_connection
255
- execute :get_network_connection
256
- end
257
-
258
- def network_connection=(type)
259
- execute :set_network_connection, {}, {parameters: {type: type}}
260
- end
261
-
262
- #
263
- # javascript execution
264
- #
265
-
266
- def execute_script(script, *args)
267
- assert_javascript_enabled
268
-
269
- result = execute :execute_script, {}, {script: script, args: args}
270
- unwrap_script_result result
271
- end
272
-
273
- def execute_async_script(script, *args)
274
- assert_javascript_enabled
275
-
276
- result = execute :execute_async_script, {}, {script: script, args: args}
277
- unwrap_script_result result
278
- end
279
-
280
- #
281
- # cookies
282
- #
283
-
284
- def manage
285
- @manage ||= WebDriver::Manager.new(self)
286
- end
287
-
288
- def add_cookie(cookie)
289
- execute :add_cookie, {}, {cookie: cookie}
290
- end
291
-
292
- def delete_cookie(name)
293
- execute :delete_cookie, name: name
294
- end
295
-
296
- def cookies
297
- execute :get_cookies
298
- end
299
-
300
- def delete_all_cookies
301
- execute :delete_all_cookies
302
- end
303
-
304
- #
305
- # actions
306
- #
307
-
308
- #
309
- # @return [ActionBuilder]
310
- # @api public
311
- #
312
-
313
- def action
314
- ActionBuilder.new Mouse.new(self), Keyboard.new(self)
315
- end
316
-
317
- def mouse
318
- WebDriver.logger.deprecate 'Driver#mouse', 'driver.action.<command>.perform'
319
- Mouse.new self
320
- end
321
-
322
- def keyboard
323
- WebDriver.logger.deprecate 'Driver#keyboard', 'driver.action.<command>.perform'
324
- Keyboard.new self
325
- end
326
-
327
- def click_element(element)
328
- execute :click_element, id: element
329
- end
330
-
331
- def click
332
- execute :click, {}, {button: 0}
333
- end
334
-
335
- def double_click
336
- execute :double_click
337
- end
338
-
339
- def context_click
340
- execute :click, {}, {button: 2}
341
- end
342
-
343
- def mouse_down
344
- execute :mouse_down
345
- end
346
-
347
- def mouse_up
348
- execute :mouse_up
349
- end
350
-
351
- def mouse_move_to(element, x = nil, y = nil)
352
- params = {element: element}
353
-
354
- if x && y
355
- params[:xoffset] = x
356
- params[:yoffset] = y
357
- end
358
-
359
- execute :mouse_move_to, {}, params
360
- end
361
-
362
- def send_keys_to_active_element(key)
363
- execute :send_keys_to_active_element, {}, {value: key}
364
- end
365
-
366
- def send_keys_to_element(element, keys)
367
- # TODO: rework file detectors before Selenium 4.0
368
- if @file_detector
369
- local_files = keys.first.split("\n").map { |key| @file_detector.call(Array(key)) }.compact
370
- if local_files.any?
371
- keys = local_files.map { |local_file| upload(local_file) }
372
- keys = keys.join("\n")
373
- end
374
- end
375
-
376
- execute :send_keys_to_element, {id: element}, {value: Array(keys)}
377
- end
378
-
379
- def upload(local_file)
380
- unless File.file?(local_file)
381
- WebDriver.logger.debug("File detector only works with files. #{local_file.inspect} isn`t a file!")
382
- raise Error::WebDriverError, "You are trying to work with something that isn't a file."
383
- end
384
-
385
- execute :upload_file, {}, {file: Zipper.zip_file(local_file)}
386
- end
387
-
388
- def clear_element(element)
389
- execute :clear_element, id: element
390
- end
391
-
392
- def submit_element(element)
393
- execute :submit_element, id: element
394
- end
395
-
396
- def drag_element(element, right_by, down_by)
397
- execute :drag_element, {id: element}, {x: right_by, y: down_by}
398
- end
399
-
400
- def touch_single_tap(element)
401
- execute :touch_single_tap, {}, {element: element}
402
- end
403
-
404
- def touch_double_tap(element)
405
- execute :touch_double_tap, {}, {element: element}
406
- end
407
-
408
- def touch_long_press(element)
409
- execute :touch_long_press, {}, {element: element}
410
- end
411
-
412
- def touch_down(x, y)
413
- execute :touch_down, {}, {x: x, y: y}
414
- end
415
-
416
- def touch_up(x, y)
417
- execute :touch_up, {}, {x: x, y: y}
418
- end
419
-
420
- def touch_move(x, y)
421
- execute :touch_move, {}, {x: x, y: y}
422
- end
423
-
424
- def touch_scroll(element, x, y)
425
- if element
426
- execute :touch_scroll, {}, {element: element,
427
- xoffset: x,
428
- yoffset: y}
429
- else
430
- execute :touch_scroll, {}, {xoffset: x, yoffset: y}
431
- end
432
- end
433
-
434
- def touch_flick(xspeed, yspeed)
435
- execute :touch_flick, {}, {xspeed: xspeed, yspeed: yspeed}
436
- end
437
-
438
- def touch_element_flick(element, right_by, down_by, speed)
439
- execute :touch_flick, {}, {element: element,
440
- xoffset: right_by,
441
- yoffset: down_by,
442
- speed: speed}
443
- end
444
-
445
- def screen_orientation=(orientation)
446
- execute :set_screen_orientation, {}, {orientation: orientation}
447
- end
448
-
449
- def screen_orientation
450
- execute :get_screen_orientation
451
- end
452
-
453
- #
454
- # logs
455
- #
456
-
457
- def available_log_types
458
- types = execute :get_available_log_types
459
- Array(types).map(&:to_sym)
460
- end
461
-
462
- def log(type)
463
- data = execute :get_log, {}, {type: type.to_s}
464
-
465
- Array(data).map do |l|
466
- begin
467
- LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
468
- rescue KeyError
469
- next
470
- end
471
- end
472
- end
473
-
474
- #
475
- # element properties
476
- #
477
-
478
- def element_tag_name(element)
479
- execute :get_element_tag_name, id: element
480
- end
481
-
482
- def element_attribute(element, name)
483
- execute :get_element_attribute, id: element.ref, name: name
484
- end
485
-
486
- # Backwards compatibility for w3c
487
- def element_property(element, name)
488
- execute_script 'return arguments[0][arguments[1]]', element, name
489
- end
490
-
491
- def element_value(element)
492
- execute :get_element_value, id: element
493
- end
494
-
495
- def element_text(element)
496
- execute :get_element_text, id: element
497
- end
498
-
499
- def element_location(element)
500
- data = execute :get_element_location, id: element
501
-
502
- Point.new data['x'], data['y']
503
- end
504
-
505
- def element_rect(element)
506
- loc = execute :get_element_location, id: element
507
- size = execute :get_element_size, id: element
508
-
509
- Rectangle.new loc['x'], loc['y'], size['width'], size['height']
510
- end
511
-
512
- def element_location_once_scrolled_into_view(element)
513
- data = execute :get_element_location_once_scrolled_into_view, id: element
514
-
515
- Point.new data['x'], data['y']
516
- end
517
-
518
- def element_size(element)
519
- data = execute :get_element_size, id: element
520
-
521
- Dimension.new data['width'], data['height']
522
- end
523
-
524
- def element_enabled?(element)
525
- execute :is_element_enabled, id: element
526
- end
527
-
528
- def element_selected?(element)
529
- execute :is_element_selected, id: element
530
- end
531
-
532
- def element_displayed?(element)
533
- execute :is_element_displayed, id: element.ref
534
- end
535
-
536
- def element_value_of_css_property(element, prop)
537
- execute :get_element_value_of_css_property, id: element, property_name: prop
538
- end
539
-
540
- #
541
- # finding elements
542
- #
543
-
544
- def active_element
545
- Element.new self, element_id_from(execute(:get_active_element))
546
- end
547
-
548
- alias_method :switch_to_active_element, :active_element
549
-
550
- def find_element_by(how, what, parent = nil)
551
- id = if parent
552
- execute :find_child_element, {id: parent}, {using: how, value: what}
553
- else
554
- execute :find_element, {}, {using: how, value: what}
555
- end
556
-
557
- Element.new self, element_id_from(id)
558
- end
559
-
560
- def find_elements_by(how, what, parent = nil)
561
- ids = if parent
562
- execute :find_child_elements, {id: parent}, {using: how, value: what}
563
- else
564
- execute :find_elements, {}, {using: how, value: what}
565
- end
566
- # see https://github.com/SeleniumHQ/selenium/issues/4555
567
- ids ||= []
568
-
569
- ids.map { |id| Element.new self, element_id_from(id) }
570
- end
571
-
572
- private
573
-
574
- def assert_javascript_enabled
575
- return if capabilities.javascript_enabled?
576
-
577
- raise Error::UnsupportedOperationError, 'underlying webdriver instance does not support javascript'
578
- end
579
-
580
- #
581
- # executes a command on the remote server.
582
- #
583
- # Returns the 'value' of the returned payload
584
- #
585
-
586
- def execute(*args)
587
- super['value']
588
- end
589
-
590
- end # Bridge
591
- end # OSS
592
- end # Remote
593
- end # WebDriver
594
- end # Selenium