selenium-webdriver 3.142.7 → 4.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +685 -5
- data/Gemfile +6 -1
- data/LICENSE +1 -1
- data/NOTICE +2 -0
- data/README.md +4 -5
- data/bin/linux/selenium-manager +0 -0
- data/bin/macos/selenium-manager +0 -0
- data/bin/windows/selenium-manager.exe +0 -0
- data/lib/selenium/server.rb +93 -90
- data/lib/selenium/webdriver/atoms/findElements.js +122 -0
- data/lib/selenium/webdriver/atoms/getAttribute.js +100 -7
- data/lib/selenium/webdriver/atoms/isDisplayed.js +77 -78
- data/lib/selenium/webdriver/atoms/mutationListener.js +55 -0
- data/lib/selenium/webdriver/atoms.rb +5 -3
- data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
- data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
- data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
- data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
- data/lib/selenium/webdriver/bidi/log/filter_by.rb +40 -0
- data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
- data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
- data/lib/selenium/webdriver/bidi/log_inspector.rb +143 -0
- data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
- data/lib/selenium/webdriver/bidi/session.rb +51 -0
- data/lib/selenium/webdriver/{common/keyboard.rb → bidi.rb} +21 -35
- data/lib/selenium/webdriver/chrome/driver.rb +9 -86
- data/lib/selenium/webdriver/chrome/features.rb +48 -0
- data/lib/selenium/webdriver/chrome/options.rb +9 -158
- data/lib/selenium/webdriver/chrome/profile.rb +3 -80
- data/lib/selenium/webdriver/chrome/service.rb +7 -29
- data/lib/selenium/webdriver/chrome.rb +5 -20
- data/lib/selenium/webdriver/chromium/driver.rb +60 -0
- data/lib/selenium/webdriver/{chrome/bridge.rb → chromium/features.rb} +48 -17
- data/lib/selenium/webdriver/chromium/options.rb +243 -0
- data/lib/selenium/webdriver/chromium/profile.rb +113 -0
- data/lib/selenium/webdriver/chromium.rb +29 -0
- data/lib/selenium/webdriver/common/action_builder.rb +126 -238
- data/lib/selenium/webdriver/common/child_process.rb +124 -0
- data/lib/selenium/webdriver/common/driver.rb +82 -43
- data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
- data/lib/selenium/webdriver/common/driver_extensions/{has_location.rb → full_page_screenshot.rb} +13 -11
- data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
- data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +49 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +87 -0
- data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_bidi.rb} +9 -9
- data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +86 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +36 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +42 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
- data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +41 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb +65 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +36 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
- data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_logs.rb} +4 -4
- data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +16 -1
- data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +69 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -13
- data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +75 -0
- data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
- data/lib/selenium/webdriver/common/driver_finder.rb +45 -0
- data/lib/selenium/webdriver/common/element.rb +89 -29
- data/lib/selenium/webdriver/common/error.rb +53 -194
- data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
- data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
- data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -22
- data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
- data/lib/selenium/webdriver/common/interactions/key_actions.rb +10 -6
- data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
- data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
- data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
- data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +71 -82
- data/lib/selenium/webdriver/common/interactions/pointer_cancel.rb +45 -0
- data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
- data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
- data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
- data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
- data/lib/selenium/webdriver/common/interactions/scroll.rb +59 -0
- data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
- data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
- data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +113 -0
- data/lib/selenium/webdriver/common/{w3c_manager.rb → interactions/wheel_input.rb} +14 -17
- data/lib/selenium/webdriver/common/keys.rb +1 -0
- data/lib/selenium/webdriver/common/local_driver.rb +46 -0
- data/lib/selenium/webdriver/common/log_entry.rb +2 -2
- data/lib/selenium/webdriver/common/logger.rb +119 -19
- data/lib/selenium/webdriver/common/manager.rb +11 -38
- data/lib/selenium/webdriver/common/options.rb +154 -23
- data/lib/selenium/webdriver/common/platform.rb +15 -52
- data/lib/selenium/webdriver/common/port_prober.rb +4 -6
- data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
- data/lib/selenium/webdriver/common/proxy.rb +8 -5
- data/lib/selenium/webdriver/common/search_context.rb +7 -9
- data/lib/selenium/webdriver/common/selenium_manager.rb +140 -0
- data/lib/selenium/webdriver/common/service.rb +26 -143
- data/lib/selenium/webdriver/common/service_manager.rb +144 -0
- data/lib/selenium/webdriver/common/shadow_root.rb +86 -0
- data/lib/selenium/webdriver/common/socket_lock.rb +4 -4
- data/lib/selenium/webdriver/common/socket_poller.rb +4 -4
- data/lib/selenium/webdriver/common/takes_screenshot.rb +65 -0
- data/lib/selenium/webdriver/common/target_locator.rb +31 -4
- data/lib/selenium/webdriver/common/timeouts.rb +31 -4
- data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +85 -0
- data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +72 -0
- data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +62 -0
- data/lib/selenium/webdriver/common/wait.rb +1 -1
- data/lib/selenium/webdriver/common/websocket_connection.rb +164 -0
- data/lib/selenium/webdriver/common/window.rb +6 -10
- data/lib/selenium/webdriver/common/zipper.rb +4 -10
- data/lib/selenium/webdriver/common.rb +43 -20
- data/lib/selenium/webdriver/devtools/console_event.rb +36 -0
- data/lib/selenium/webdriver/devtools/exception_event.rb +34 -0
- data/lib/selenium/webdriver/devtools/mutation_event.rb +35 -0
- data/lib/selenium/webdriver/devtools/network_interceptor.rb +173 -0
- data/lib/selenium/webdriver/devtools/pinned_script.rb +57 -0
- data/lib/selenium/webdriver/devtools/request.rb +65 -0
- data/lib/selenium/webdriver/devtools/response.rb +64 -0
- data/lib/selenium/webdriver/devtools.rb +96 -0
- data/lib/selenium/webdriver/edge/driver.rb +11 -27
- data/lib/selenium/webdriver/edge/features.rb +48 -0
- data/lib/selenium/webdriver/edge/options.rb +18 -43
- data/lib/selenium/webdriver/edge/profile.rb +33 -0
- data/lib/selenium/webdriver/edge/service.rb +8 -23
- data/lib/selenium/webdriver/edge.rb +11 -16
- data/lib/selenium/webdriver/firefox/driver.rb +38 -19
- data/lib/selenium/webdriver/firefox/extension.rb +8 -0
- data/lib/selenium/webdriver/firefox/features.rb +70 -0
- data/lib/selenium/webdriver/firefox/options.rb +73 -61
- data/lib/selenium/webdriver/firefox/profile.rb +20 -72
- data/lib/selenium/webdriver/firefox/service.rb +3 -25
- data/lib/selenium/webdriver/firefox/util.rb +1 -1
- data/lib/selenium/webdriver/firefox.rb +17 -28
- data/lib/selenium/webdriver/ie/driver.rb +5 -45
- data/lib/selenium/webdriver/ie/features.rb +34 -0
- data/lib/selenium/webdriver/ie/options.rb +14 -44
- data/lib/selenium/webdriver/ie/service.rb +3 -27
- data/lib/selenium/webdriver/ie.rb +4 -16
- data/lib/selenium/webdriver/remote/bridge/commands.rb +164 -0
- data/lib/selenium/webdriver/remote/bridge.rb +574 -88
- data/lib/selenium/webdriver/remote/capabilities.rb +144 -158
- data/lib/selenium/webdriver/remote/driver.rb +45 -14
- data/lib/selenium/webdriver/remote/features.rb +75 -0
- data/lib/selenium/webdriver/remote/http/common.rb +3 -8
- data/lib/selenium/webdriver/remote/http/curb.rb +1 -3
- data/lib/selenium/webdriver/remote/http/default.rb +24 -33
- data/lib/selenium/webdriver/remote/response.rb +17 -49
- data/lib/selenium/webdriver/remote/server_error.rb +1 -1
- data/lib/selenium/webdriver/remote.rb +15 -12
- data/lib/selenium/webdriver/safari/driver.rb +7 -29
- data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +7 -5
- data/lib/selenium/webdriver/safari/options.rb +12 -27
- data/lib/selenium/webdriver/safari/service.rb +13 -11
- data/lib/selenium/webdriver/safari.rb +14 -20
- data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
- data/lib/selenium/webdriver/support/color.rb +24 -24
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +5 -5
- data/lib/selenium/webdriver/support/guards/guard.rb +90 -0
- data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +21 -20
- data/lib/selenium/webdriver/support/guards.rb +95 -0
- data/lib/selenium/webdriver/support/relative_locator.rb +50 -0
- data/lib/selenium/webdriver/support/select.rb +6 -4
- data/lib/selenium/webdriver/support.rb +1 -0
- data/lib/selenium/webdriver/version.rb +1 -1
- data/lib/selenium/webdriver.rb +19 -17
- data/selenium-webdriver.gemspec +36 -18
- metadata +161 -91
- data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
- data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +0 -58
- data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
- data/lib/selenium/webdriver/common/mouse.rb +0 -89
- data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
- data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
- data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
- data/lib/selenium/webdriver/edge/bridge.rb +0 -76
- data/lib/selenium/webdriver/firefox/binary.rb +0 -187
- data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
- data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
- data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
- data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/remote/http/persistent.rb +0 -60
- data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
- data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
- data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
- data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
- data/lib/selenium/webdriver/remote/w3c/commands.rb +0 -157
@@ -0,0 +1,65 @@
|
|
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
|
+
#
|
23
|
+
# @api private
|
24
|
+
#
|
25
|
+
module TakesScreenshot
|
26
|
+
#
|
27
|
+
# Save a PNG screenshot of the viewport to the given path
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
#
|
31
|
+
|
32
|
+
def save_screenshot(png_path, full_page: false)
|
33
|
+
extension = File.extname(png_path).downcase
|
34
|
+
if extension != '.png'
|
35
|
+
WebDriver.logger.warn 'name used for saved screenshot does not match file type. ' \
|
36
|
+
'It should end with .png extension',
|
37
|
+
id: :screenshot
|
38
|
+
end
|
39
|
+
File.open(png_path, 'wb') { |f| f << screenshot_as(:png, full_page: full_page) }
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Return a PNG screenshot in the given format as a string
|
44
|
+
#
|
45
|
+
# @param [:base64, :png] format
|
46
|
+
# @param [Boolean] full_page allows taking full page screenshots if supported
|
47
|
+
# @return String screenshot
|
48
|
+
#
|
49
|
+
# @api public
|
50
|
+
|
51
|
+
def screenshot_as(format, full_page: false)
|
52
|
+
case format
|
53
|
+
when :base64
|
54
|
+
full_page ? full_screenshot : screenshot
|
55
|
+
when :png
|
56
|
+
screenshot_as(:base64, full_page: full_page).unpack1('m')
|
57
|
+
else
|
58
|
+
raise Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
|
59
|
+
end
|
60
|
+
rescue NameError
|
61
|
+
raise Error::UnsupportedOperationError, "Full Page Screenshots are not supported for #{inspect}"
|
62
|
+
end
|
63
|
+
end # TakesScreenshot
|
64
|
+
end # WebDriver
|
65
|
+
end # Selenium
|
@@ -44,6 +44,33 @@ module Selenium
|
|
44
44
|
@bridge.switch_to_parent_frame
|
45
45
|
end
|
46
46
|
|
47
|
+
#
|
48
|
+
# Switch to a new top-level browsing context
|
49
|
+
#
|
50
|
+
# @param type either :tab or :window
|
51
|
+
#
|
52
|
+
|
53
|
+
def new_window(type = :window)
|
54
|
+
raise ArgumentError, "Valid types are :tab and :window, received: #{type.inspect}" unless %i[window
|
55
|
+
tab].include?(type)
|
56
|
+
|
57
|
+
handle = @bridge.new_window(type)['handle']
|
58
|
+
|
59
|
+
if block_given?
|
60
|
+
execute_and_close = proc do
|
61
|
+
yield(self)
|
62
|
+
begin
|
63
|
+
@bridge.close
|
64
|
+
rescue Error::NoSuchWindowError
|
65
|
+
# window already closed
|
66
|
+
end
|
67
|
+
end
|
68
|
+
window(handle, &execute_and_close)
|
69
|
+
else
|
70
|
+
window(handle)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
47
74
|
#
|
48
75
|
# switch to the given window handle
|
49
76
|
#
|
@@ -57,10 +84,10 @@ module Selenium
|
|
57
84
|
def window(id)
|
58
85
|
if block_given?
|
59
86
|
original = begin
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
87
|
+
@bridge.window_handle
|
88
|
+
rescue Error::NoSuchWindowError
|
89
|
+
nil
|
90
|
+
end
|
64
91
|
|
65
92
|
unless @bridge.window_handles.include? id
|
66
93
|
raise Error::NoSuchWindowError, "The specified identifier '#{id}' is not found in the window handle list"
|
@@ -24,22 +24,49 @@ module Selenium
|
|
24
24
|
@bridge = bridge
|
25
25
|
end
|
26
26
|
|
27
|
+
#
|
28
|
+
# Gets the amount of time the driver should wait when searching for elements.
|
29
|
+
#
|
30
|
+
|
31
|
+
def implicit_wait
|
32
|
+
Float(@bridge.timeouts['implicit']) / 1000
|
33
|
+
end
|
34
|
+
|
27
35
|
#
|
28
36
|
# Set the amount of time the driver should wait when searching for elements.
|
29
37
|
#
|
30
38
|
|
31
39
|
def implicit_wait=(seconds)
|
32
|
-
@bridge.
|
40
|
+
@bridge.timeouts = {'implicit' => Integer(seconds * 1000)}
|
33
41
|
end
|
34
42
|
|
43
|
+
#
|
44
|
+
# Gets the amount of time to wait for an asynchronous script to finish
|
45
|
+
# execution before throwing an error.
|
46
|
+
#
|
47
|
+
|
48
|
+
def script
|
49
|
+
Float(@bridge.timeouts['script']) / 1000
|
50
|
+
end
|
51
|
+
alias script_timeout script
|
52
|
+
|
35
53
|
#
|
36
54
|
# Sets the amount of time to wait for an asynchronous script to finish
|
37
55
|
# execution before throwing an error. If the timeout is negative, then the
|
38
56
|
# script will be allowed to run indefinitely.
|
39
57
|
#
|
40
58
|
|
41
|
-
def
|
42
|
-
@bridge.
|
59
|
+
def script=(seconds)
|
60
|
+
@bridge.timeouts = {'script' => Integer(seconds * 1000)}
|
61
|
+
end
|
62
|
+
alias script_timeout= script=
|
63
|
+
|
64
|
+
#
|
65
|
+
# Gets the amount of time to wait for a page load to complete before throwing an error.
|
66
|
+
#
|
67
|
+
|
68
|
+
def page_load
|
69
|
+
Float(@bridge.timeouts['pageLoad']) / 1000
|
43
70
|
end
|
44
71
|
|
45
72
|
#
|
@@ -48,7 +75,7 @@ module Selenium
|
|
48
75
|
#
|
49
76
|
|
50
77
|
def page_load=(seconds)
|
51
|
-
@bridge.
|
78
|
+
@bridge.timeouts = {'pageLoad' => Integer(seconds * 1000)}
|
52
79
|
end
|
53
80
|
end # Timeouts
|
54
81
|
end # WebDriver
|
@@ -0,0 +1,85 @@
|
|
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
|
+
#
|
21
|
+
# A credential stored in a virtual authenticator.
|
22
|
+
# @see https://w3c.github.io/webauthn/#credential-parameters
|
23
|
+
#
|
24
|
+
|
25
|
+
module Selenium
|
26
|
+
module WebDriver
|
27
|
+
class Credential
|
28
|
+
class << self
|
29
|
+
def resident(**opts)
|
30
|
+
Credential.new(resident_credential: true, **opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
def non_resident(**opts)
|
34
|
+
Credential.new(resident_credential: false, **opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def encode(byte_array)
|
38
|
+
Base64.urlsafe_encode64(byte_array&.pack('C*'))
|
39
|
+
end
|
40
|
+
|
41
|
+
def decode(base64)
|
42
|
+
Base64.urlsafe_decode64(base64).unpack('C*')
|
43
|
+
end
|
44
|
+
|
45
|
+
def from_json(opts)
|
46
|
+
user_handle = opts['userHandle'] ? decode(opts['userHandle']) : nil
|
47
|
+
new(id: decode(opts['credentialId']),
|
48
|
+
resident_credential: opts['isResidentCredential'],
|
49
|
+
rp_id: opts['rpId'],
|
50
|
+
private_key: opts['privateKey'],
|
51
|
+
sign_count: opts['signCount'],
|
52
|
+
user_handle: user_handle)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
attr_reader :id, :resident_credential, :rp_id, :user_handle, :private_key, :sign_count
|
57
|
+
alias resident_credential? resident_credential
|
58
|
+
|
59
|
+
def initialize(id:, resident_credential:, rp_id:, private_key:, **opts)
|
60
|
+
@id = id
|
61
|
+
@resident_credential = resident_credential
|
62
|
+
@rp_id = rp_id
|
63
|
+
@user_handle = opts.delete(:user_handle) { nil }
|
64
|
+
@private_key = private_key
|
65
|
+
@sign_count = opts.delete(:sign_count) { 0 }
|
66
|
+
|
67
|
+
raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# @api private
|
72
|
+
#
|
73
|
+
|
74
|
+
def as_json(*)
|
75
|
+
credential_data = {'credentialId' => Credential.encode(id),
|
76
|
+
'isResidentCredential' => resident_credential?,
|
77
|
+
'rpId' => rp_id,
|
78
|
+
'privateKey' => Credential.encode(private_key),
|
79
|
+
'signCount' => sign_count}
|
80
|
+
credential_data['userHandle'] = Credential.encode(user_handle) if user_handle
|
81
|
+
credential_data
|
82
|
+
end
|
83
|
+
end # Credential
|
84
|
+
end # WebDriver
|
85
|
+
end # Selenium
|
@@ -0,0 +1,72 @@
|
|
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
|
+
class VirtualAuthenticator
|
23
|
+
attr_reader :options
|
24
|
+
|
25
|
+
#
|
26
|
+
# api private
|
27
|
+
# Use `Driver#add_virtual_authenticator`
|
28
|
+
#
|
29
|
+
|
30
|
+
def initialize(bridge, authenticator_id, options)
|
31
|
+
@id = authenticator_id
|
32
|
+
@bridge = bridge
|
33
|
+
@options = options
|
34
|
+
@valid = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_credential(credential)
|
38
|
+
credential = credential.as_json
|
39
|
+
@bridge.add_credential credential, @id
|
40
|
+
end
|
41
|
+
|
42
|
+
def credentials
|
43
|
+
credential_data = @bridge.credentials @id
|
44
|
+
credential_data.map do |cred|
|
45
|
+
Credential.from_json(cred)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def remove_credential(credential_id)
|
50
|
+
credential_id = Credential.encode(credential_id) if credential_id.instance_of?(Array)
|
51
|
+
@bridge.remove_credential credential_id, @id
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_all_credentials
|
55
|
+
@bridge.remove_all_credentials @id
|
56
|
+
end
|
57
|
+
|
58
|
+
def user_verified=(verified)
|
59
|
+
@bridge.user_verified verified, @id
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove!
|
63
|
+
@bridge.remove_virtual_authenticator(@id)
|
64
|
+
@valid = false
|
65
|
+
end
|
66
|
+
|
67
|
+
def valid?
|
68
|
+
@valid
|
69
|
+
end
|
70
|
+
end # VirtualAuthenticator
|
71
|
+
end # WebDriver
|
72
|
+
end # Selenium
|
@@ -0,0 +1,62 @@
|
|
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
|
+
#
|
21
|
+
# Options for the creation of virtual authenticators.
|
22
|
+
# @see http://w3c.github.io/webauthn/#sctn-automation
|
23
|
+
#
|
24
|
+
|
25
|
+
module Selenium
|
26
|
+
module WebDriver
|
27
|
+
class VirtualAuthenticatorOptions
|
28
|
+
PROTOCOL = {ctap2: 'ctap2', u2f: 'ctap1/u2f'}.freeze
|
29
|
+
TRANSPORT = {ble: 'ble', usb: 'usb', nfc: 'nfc', internal: 'internal'}.freeze
|
30
|
+
|
31
|
+
attr_accessor :protocol, :transport, :resident_key, :user_verification, :user_consenting, :user_verified
|
32
|
+
alias resident_key? resident_key
|
33
|
+
alias user_verification? user_verification
|
34
|
+
alias user_consenting? user_consenting
|
35
|
+
alias user_verified? user_verified
|
36
|
+
|
37
|
+
def initialize(**opts)
|
38
|
+
@protocol = opts.delete(:protocol) { :ctap2 }
|
39
|
+
@transport = opts.delete(:transport) { :usb }
|
40
|
+
@resident_key = opts.delete(:resident_key) { false }
|
41
|
+
@user_verification = opts.delete(:user_verification) { false }
|
42
|
+
@user_consenting = opts.delete(:user_consenting) { true }
|
43
|
+
@user_verified = opts.delete(:user_verified) { false }
|
44
|
+
|
45
|
+
raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
#
|
51
|
+
|
52
|
+
def as_json(*)
|
53
|
+
{'protocol' => PROTOCOL[protocol],
|
54
|
+
'transport' => TRANSPORT[transport],
|
55
|
+
'hasResidentKey' => resident_key?,
|
56
|
+
'hasUserVerification' => user_verification?,
|
57
|
+
'isUserConsenting' => user_consenting?,
|
58
|
+
'isUserVerified' => user_verified?}
|
59
|
+
end
|
60
|
+
end # VirtualAuthenticatorOptions
|
61
|
+
end # WebDriver
|
62
|
+
end # Selenium
|
@@ -0,0 +1,164 @@
|
|
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
|
+
require 'websocket'
|
21
|
+
|
22
|
+
module Selenium
|
23
|
+
module WebDriver
|
24
|
+
class WebSocketConnection
|
25
|
+
CONNECTION_ERRORS = [
|
26
|
+
Errno::ECONNRESET, # connection is aborted (browser process was killed)
|
27
|
+
Errno::EPIPE # broken pipe (browser process was killed)
|
28
|
+
].freeze
|
29
|
+
|
30
|
+
RESPONSE_WAIT_TIMEOUT = 30
|
31
|
+
RESPONSE_WAIT_INTERVAL = 0.1
|
32
|
+
|
33
|
+
MAX_LOG_MESSAGE_SIZE = 9999
|
34
|
+
|
35
|
+
def initialize(url:)
|
36
|
+
@callback_threads = ThreadGroup.new
|
37
|
+
|
38
|
+
@session_id = nil
|
39
|
+
@url = url
|
40
|
+
|
41
|
+
process_handshake
|
42
|
+
@socket_thread = attach_socket_listener
|
43
|
+
end
|
44
|
+
|
45
|
+
def close
|
46
|
+
@callback_threads.list.each(&:exit)
|
47
|
+
@socket_thread.exit
|
48
|
+
socket.close
|
49
|
+
end
|
50
|
+
|
51
|
+
def callbacks
|
52
|
+
@callbacks ||= Hash.new { |callbacks, event| callbacks[event] = [] }
|
53
|
+
end
|
54
|
+
|
55
|
+
def send_cmd(**payload)
|
56
|
+
id = next_id
|
57
|
+
data = payload.merge(id: id)
|
58
|
+
WebDriver.logger.debug "WebSocket -> #{data}"[...MAX_LOG_MESSAGE_SIZE], id: :bidi
|
59
|
+
data = JSON.generate(data)
|
60
|
+
out_frame = WebSocket::Frame::Outgoing::Client.new(version: ws.version, data: data, type: 'text')
|
61
|
+
socket.write(out_frame.to_s)
|
62
|
+
|
63
|
+
wait.until { messages.delete(id) }
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# We should be thread-safe to use the hash without synchronization
|
69
|
+
# because its keys are WebSocket message identifiers and they should be
|
70
|
+
# unique within a devtools session.
|
71
|
+
def messages
|
72
|
+
@messages ||= {}
|
73
|
+
end
|
74
|
+
|
75
|
+
def process_handshake
|
76
|
+
socket.print(ws.to_s)
|
77
|
+
ws << socket.readpartial(1024)
|
78
|
+
end
|
79
|
+
|
80
|
+
def attach_socket_listener
|
81
|
+
Thread.new do
|
82
|
+
Thread.current.abort_on_exception = true
|
83
|
+
Thread.current.report_on_exception = false
|
84
|
+
|
85
|
+
until socket.eof?
|
86
|
+
incoming_frame << socket.readpartial(1024)
|
87
|
+
|
88
|
+
while (frame = incoming_frame.next)
|
89
|
+
message = process_frame(frame)
|
90
|
+
next unless message['method']
|
91
|
+
|
92
|
+
params = message['params']
|
93
|
+
callbacks[message['method']].each do |callback|
|
94
|
+
@callback_threads.add(callback_thread(params, &callback))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
rescue *CONNECTION_ERRORS
|
99
|
+
Thread.stop
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def incoming_frame
|
104
|
+
@incoming_frame ||= WebSocket::Frame::Incoming::Client.new(version: ws.version)
|
105
|
+
end
|
106
|
+
|
107
|
+
def process_frame(frame)
|
108
|
+
message = frame.to_s
|
109
|
+
|
110
|
+
# Firefox will periodically fail on unparsable empty frame
|
111
|
+
return {} if message.empty?
|
112
|
+
|
113
|
+
message = JSON.parse(message)
|
114
|
+
messages[message['id']] = message
|
115
|
+
WebDriver.logger.debug "WebSocket <- #{message}"[...MAX_LOG_MESSAGE_SIZE], id: :bidi
|
116
|
+
|
117
|
+
message
|
118
|
+
end
|
119
|
+
|
120
|
+
def callback_thread(params)
|
121
|
+
Thread.new do
|
122
|
+
Thread.current.abort_on_exception = true
|
123
|
+
|
124
|
+
# We might end up blocked forever when we have an error in event.
|
125
|
+
# For example, if network interception event raises error,
|
126
|
+
# the browser will keep waiting for the request to be proceeded
|
127
|
+
# before returning back to the original thread. In this case,
|
128
|
+
# we should at least print the error.
|
129
|
+
Thread.current.report_on_exception = true
|
130
|
+
|
131
|
+
yield params
|
132
|
+
rescue Error::WebDriverError, *CONNECTION_ERRORS
|
133
|
+
Thread.stop
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def wait
|
138
|
+
@wait ||= Wait.new(timeout: RESPONSE_WAIT_TIMEOUT, interval: RESPONSE_WAIT_INTERVAL)
|
139
|
+
end
|
140
|
+
|
141
|
+
def socket
|
142
|
+
@socket ||= if URI(@url).scheme == 'wss'
|
143
|
+
socket = TCPSocket.new(ws.host, ws.port)
|
144
|
+
socket = OpenSSL::SSL::SSLSocket.new(socket, OpenSSL::SSL::SSLContext.new)
|
145
|
+
socket.sync_close = true
|
146
|
+
socket.connect
|
147
|
+
|
148
|
+
socket
|
149
|
+
else
|
150
|
+
TCPSocket.new(ws.host, ws.port)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def ws
|
155
|
+
@ws ||= WebSocket::Handshake::Client.new(url: @url)
|
156
|
+
end
|
157
|
+
|
158
|
+
def next_id
|
159
|
+
@id ||= 0
|
160
|
+
@id += 1
|
161
|
+
end
|
162
|
+
end # BiDi
|
163
|
+
end # WebDriver
|
164
|
+
end # Selenium
|
@@ -19,10 +19,6 @@
|
|
19
19
|
|
20
20
|
module Selenium
|
21
21
|
module WebDriver
|
22
|
-
#
|
23
|
-
# @api beta This API may be changed or removed in a future release.
|
24
|
-
#
|
25
|
-
|
26
22
|
class Window
|
27
23
|
#
|
28
24
|
# @api private
|
@@ -40,8 +36,8 @@ module Selenium
|
|
40
36
|
|
41
37
|
def size=(dimension)
|
42
38
|
unless dimension.respond_to?(:width) && dimension.respond_to?(:height)
|
43
|
-
raise ArgumentError, "expected #{dimension.inspect}:#{dimension.class}" \
|
44
|
-
'
|
39
|
+
raise ArgumentError, "expected #{dimension.inspect}:#{dimension.class} " \
|
40
|
+
'to respond to #width and #height'
|
45
41
|
end
|
46
42
|
|
47
43
|
@bridge.resize_window dimension.width, dimension.height
|
@@ -65,8 +61,8 @@ module Selenium
|
|
65
61
|
|
66
62
|
def position=(point)
|
67
63
|
unless point.respond_to?(:x) && point.respond_to?(:y)
|
68
|
-
raise ArgumentError, "expected #{point.inspect}:#{point.class}" \
|
69
|
-
'
|
64
|
+
raise ArgumentError, "expected #{point.inspect}:#{point.class} " \
|
65
|
+
'to respond to #x and #y'
|
70
66
|
end
|
71
67
|
|
72
68
|
@bridge.reposition_window point.x, point.y
|
@@ -90,8 +86,8 @@ module Selenium
|
|
90
86
|
|
91
87
|
def rect=(rectangle)
|
92
88
|
unless %w[x y width height].all? { |val| rectangle.respond_to? val }
|
93
|
-
raise ArgumentError, "expected #{rectangle.inspect}:#{rectangle.class}" \
|
94
|
-
'
|
89
|
+
raise ArgumentError, "expected #{rectangle.inspect}:#{rectangle.class} " \
|
90
|
+
'to respond to #x, #y, #width, and #height'
|
95
91
|
end
|
96
92
|
|
97
93
|
@bridge.set_window_rect(x: rectangle.x,
|
@@ -41,7 +41,7 @@ module Selenium
|
|
41
41
|
to = File.join(destination, entry.name)
|
42
42
|
dirname = File.dirname(to)
|
43
43
|
|
44
|
-
FileUtils.mkdir_p dirname
|
44
|
+
FileUtils.mkdir_p dirname
|
45
45
|
zip.extract(entry, to)
|
46
46
|
end
|
47
47
|
end
|
@@ -72,16 +72,10 @@ module Selenium
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def with_tmp_zip(&blk)
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
zip_path = File.join(tmp_dir, 'webdriver-zip')
|
79
|
-
|
80
|
-
begin
|
75
|
+
# Don't use Tempfile since it lacks rb_file_s_rename permission on Windows.
|
76
|
+
Dir.mktmpdir do |tmp_dir|
|
77
|
+
zip_path = File.join(tmp_dir, 'webdriver-zip')
|
81
78
|
Zip::File.open(zip_path, Zip::File::CREATE, &blk)
|
82
|
-
ensure
|
83
|
-
FileUtils.rm_rf tmp_dir
|
84
|
-
FileUtils.rm_rf zip_path
|
85
79
|
end
|
86
80
|
end
|
87
81
|
|