selenium-webdriver 3.142.7 → 4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +583 -5
- data/Gemfile +3 -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 -78
- 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 +76 -78
- data/lib/selenium/webdriver/atoms/mutationListener.js +55 -0
- data/lib/selenium/webdriver/atoms.rb +2 -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 +44 -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 +6 -33
- data/lib/selenium/webdriver/chrome.rb +5 -18
- data/lib/selenium/webdriver/chromium/driver.rb +61 -0
- data/lib/selenium/webdriver/{chrome/bridge.rb → chromium/features.rb} +51 -16
- data/lib/selenium/webdriver/chromium/options.rb +261 -0
- data/lib/selenium/webdriver/chromium/profile.rb +113 -0
- data/lib/selenium/webdriver/chromium/service.rb +42 -0
- data/lib/selenium/webdriver/chromium.rb +32 -0
- data/lib/selenium/webdriver/common/action_builder.rb +135 -237
- data/lib/selenium/webdriver/common/child_process.rb +124 -0
- data/lib/selenium/webdriver/common/driver.rb +94 -43
- data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
- data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +42 -0
- 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_launching.rb +36 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +5 -9
- 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_connection.rb +6 -27
- 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 +43 -0
- data/lib/selenium/webdriver/common/element.rb +89 -29
- data/lib/selenium/webdriver/common/error.rb +32 -198
- 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 +55 -0
- data/lib/selenium/webdriver/common/log_entry.rb +2 -2
- data/lib/selenium/webdriver/common/logger.rb +58 -15
- data/lib/selenium/webdriver/common/manager.rb +11 -38
- data/lib/selenium/webdriver/common/options.rb +169 -23
- data/lib/selenium/webdriver/common/platform.rb +14 -6
- 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 +7 -4
- data/lib/selenium/webdriver/common/search_context.rb +7 -9
- data/lib/selenium/webdriver/common/selenium_manager.rb +108 -0
- data/lib/selenium/webdriver/common/service.rb +17 -136
- data/lib/selenium/webdriver/common/service_manager.rb +142 -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 +3 -3
- 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 +42 -18
- 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 +44 -0
- data/lib/selenium/webdriver/edge/options.rb +10 -49
- data/lib/selenium/webdriver/edge/profile.rb +33 -0
- data/lib/selenium/webdriver/edge/service.rb +7 -27
- data/lib/selenium/webdriver/edge.rb +11 -14
- 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 +66 -0
- data/lib/selenium/webdriver/firefox/options.rb +77 -50
- data/lib/selenium/webdriver/firefox/profile.rb +16 -70
- data/lib/selenium/webdriver/firefox/service.rb +3 -13
- 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/options.rb +15 -46
- data/lib/selenium/webdriver/ie/service.rb +11 -19
- data/lib/selenium/webdriver/ie.rb +3 -16
- data/lib/selenium/webdriver/remote/bridge/commands.rb +170 -0
- data/lib/selenium/webdriver/remote/bridge.rb +590 -86
- data/lib/selenium/webdriver/remote/capabilities.rb +182 -124
- data/lib/selenium/webdriver/remote/driver.rb +30 -15
- data/lib/selenium/webdriver/remote/http/common.rb +0 -5
- data/lib/selenium/webdriver/remote/http/curb.rb +0 -2
- data/lib/selenium/webdriver/remote/http/default.rb +23 -31
- data/lib/selenium/webdriver/remote/response.rb +17 -49
- data/lib/selenium/webdriver/remote.rb +14 -12
- data/lib/selenium/webdriver/safari/driver.rb +7 -29
- data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +3 -5
- data/lib/selenium/webdriver/safari/options.rb +12 -27
- data/lib/selenium/webdriver/safari/service.rb +3 -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 +22 -22
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +4 -4
- data/lib/selenium/webdriver/support/guards/guard.rb +87 -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 +17 -17
- data/selenium-webdriver.gemspec +36 -18
- metadata +164 -94
- data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
- 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,261 @@
|
|
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 Chromium
|
23
|
+
class Options < WebDriver::Options
|
24
|
+
attr_accessor :profile, :logging_prefs
|
25
|
+
|
26
|
+
# see: http://chromedriver.chromium.org/capabilities
|
27
|
+
CAPABILITIES = {args: 'args',
|
28
|
+
binary: 'binary',
|
29
|
+
local_state: 'localState',
|
30
|
+
prefs: 'prefs',
|
31
|
+
detach: 'detach',
|
32
|
+
debugger_address: 'debuggerAddress',
|
33
|
+
exclude_switches: 'excludeSwitches',
|
34
|
+
minidump_path: 'minidumpPath',
|
35
|
+
emulation: 'mobileEmulation',
|
36
|
+
perf_logging_prefs: 'perfLoggingPrefs',
|
37
|
+
window_types: 'windowTypes',
|
38
|
+
android_package: 'androidPackage',
|
39
|
+
android_activity: 'androidActivity',
|
40
|
+
android_device_serial: 'androidDeviceSerial',
|
41
|
+
android_use_running_app: 'androidUseRunningApp'}.freeze
|
42
|
+
|
43
|
+
# NOTE: special handling of 'extensions' to validate when set instead of when used
|
44
|
+
attr_reader :extensions
|
45
|
+
|
46
|
+
# Create a new Options instance.
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# options = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized', 'user-data-dir=/tmp/temp_profile'])
|
50
|
+
# driver = Selenium::WebDriver.for(:chrome, capabilities: options)
|
51
|
+
#
|
52
|
+
# @param [Profile] profile An instance of a Chrome::Profile Class
|
53
|
+
# @param [Hash] opts the pre-defined options to create the Chrome::Options with
|
54
|
+
# @option opts [Array] encoded_extensions List of extensions that do not need to be Base64 encoded
|
55
|
+
# @option opts [Array<String>] args List of command-line arguments to use when starting Chrome
|
56
|
+
# @option opts [String] binary Path to the Chrome executable to use
|
57
|
+
# @option opts [Hash] prefs A hash with each entry consisting of the name of the preference and its value
|
58
|
+
# @option opts [Array<String>] extensions A list of paths to (.crx) Chrome extensions to install on startup
|
59
|
+
# @option opts [Hash] options A hash for raw options
|
60
|
+
# @option opts [Hash] emulation A hash for raw emulation options
|
61
|
+
# @option opts [Hash] local_state A hash for the Local State file in the user data folder
|
62
|
+
# @option opts [Boolean] detach whether browser is closed when the driver is sent the quit command
|
63
|
+
# @option opts [String] debugger_address address of a Chrome debugger server to connect to
|
64
|
+
# @option opts [Array<String>] exclude_switches command line switches to exclude
|
65
|
+
# @option opts [String] minidump_path Directory to store Chrome minidumps (linux only)
|
66
|
+
# @option opts [Hash] perf_logging_prefs A hash for performance logging preferences
|
67
|
+
# @option opts [Array<String>] window_types A list of window types to appear in the list of window handles
|
68
|
+
#
|
69
|
+
|
70
|
+
def initialize(profile: nil, **opts)
|
71
|
+
super(**opts)
|
72
|
+
|
73
|
+
@profile = profile
|
74
|
+
|
75
|
+
@options = {args: [],
|
76
|
+
prefs: {},
|
77
|
+
emulation: {},
|
78
|
+
extensions: [],
|
79
|
+
local_state: {},
|
80
|
+
exclude_switches: [],
|
81
|
+
perf_logging_prefs: {},
|
82
|
+
window_types: []}.merge(@options)
|
83
|
+
|
84
|
+
@logging_prefs = options.delete(:logging_prefs) || {}
|
85
|
+
@encoded_extensions = @options.delete(:encoded_extensions) || []
|
86
|
+
@extensions = []
|
87
|
+
@options.delete(:extensions).each { |ext| validate_extension(ext) }
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Add an extension by local path.
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
95
|
+
# options.add_extension('/path/to/extension.crx')
|
96
|
+
#
|
97
|
+
# @param [String] path The local path to the .crx file
|
98
|
+
#
|
99
|
+
|
100
|
+
def add_extension(path)
|
101
|
+
validate_extension(path)
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Add an extension by local path.
|
106
|
+
#
|
107
|
+
# @example
|
108
|
+
# extensions = ['/path/to/extension.crx', '/path/to/other.crx']
|
109
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
110
|
+
# options.extensions = extensions
|
111
|
+
#
|
112
|
+
# @param [Array<String>] extensions A list of paths to (.crx) Chrome extensions to install on startup
|
113
|
+
#
|
114
|
+
|
115
|
+
def extensions=(extensions)
|
116
|
+
extensions.each { |ext| validate_extension(ext) }
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Add an extension by Base64-encoded string.
|
121
|
+
#
|
122
|
+
# @example
|
123
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
124
|
+
# options.add_encoded_extension(encoded_string)
|
125
|
+
#
|
126
|
+
# @param [String] encoded The Base64-encoded string of the .crx file
|
127
|
+
#
|
128
|
+
|
129
|
+
def add_encoded_extension(encoded)
|
130
|
+
@encoded_extensions << encoded
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Add a command-line argument to use when starting Chrome.
|
135
|
+
#
|
136
|
+
# @example Start Chrome maximized
|
137
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
138
|
+
# options.add_argument('start-maximized')
|
139
|
+
#
|
140
|
+
# @param [String] arg The command-line argument to add
|
141
|
+
#
|
142
|
+
|
143
|
+
def add_argument(arg)
|
144
|
+
@options[:args] << arg
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Add a preference that is only applied to the user profile in use.
|
149
|
+
#
|
150
|
+
# @example Set the default homepage
|
151
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
152
|
+
# options.add_preference('homepage', 'http://www.seleniumhq.com/')
|
153
|
+
#
|
154
|
+
# @param [String] name Key of the preference
|
155
|
+
# @param [Boolean, String, Integer] value Value of the preference
|
156
|
+
#
|
157
|
+
|
158
|
+
def add_preference(name, value)
|
159
|
+
@options[:prefs][name] = value
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# Run Chrome in headless mode.
|
164
|
+
# Old headless uses a non-production browser and is set with `--headless`
|
165
|
+
# Native headless from v86 - v108 is set with `--headless=chrome`
|
166
|
+
# Native headless from v109+ is set with `--headless=new`
|
167
|
+
#
|
168
|
+
# @example Enable headless mode
|
169
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
170
|
+
# options.headless!
|
171
|
+
#
|
172
|
+
|
173
|
+
def headless!
|
174
|
+
WebDriver.logger.deprecate('`Options#headless!`',
|
175
|
+
"`Options#add_argument('--headless=new')`",
|
176
|
+
id: :headless)
|
177
|
+
add_argument '--headless'
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Add emulation device information
|
182
|
+
#
|
183
|
+
# see: http://chromedriver.chromium.org/mobile-emulation
|
184
|
+
#
|
185
|
+
# @example Start Chrome in mobile emulation mode by device name
|
186
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
187
|
+
# options.add_emulation(device_name: 'iPhone 6')
|
188
|
+
#
|
189
|
+
# @example Start Chrome in mobile emulation mode by device metrics
|
190
|
+
# options = Selenium::WebDriver::Chrome::Options.new
|
191
|
+
# options.add_emulation(device_metrics: {width: 400, height: 800, pixelRatio: 1, touch: true})
|
192
|
+
#
|
193
|
+
# @param [Hash] opts the pre-defined options for adding mobile emulation values
|
194
|
+
# @option opts [String] :device_name A valid device name from the Chrome DevTools Emulation panel
|
195
|
+
# @option opts [Hash] :device_metrics Hash containing width, height, pixelRatio, touch
|
196
|
+
# @option opts [String] :user_agent Full user agent
|
197
|
+
#
|
198
|
+
|
199
|
+
def add_emulation(**opts)
|
200
|
+
@options[:emulation] = opts
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# Enables mobile browser use on Android.
|
205
|
+
#
|
206
|
+
# @see https://chromedriver.chromium.org/getting-started/getting-started---android
|
207
|
+
#
|
208
|
+
# @param [String] package The package name of the Chrome or WebView app.
|
209
|
+
# @param [String] serial_number The device serial number on which to launch the Chrome or WebView app.
|
210
|
+
# @param [String] use_running_app When true uses an already-running Chrome or WebView app,
|
211
|
+
# instead of launching the app with a clear data directory.
|
212
|
+
# @param [String] activity Name of the Activity hosting the WebView (Not available on Chrome Apps).
|
213
|
+
#
|
214
|
+
|
215
|
+
def enable_android(package: 'com.android.chrome', serial_number: nil, use_running_app: nil, activity: nil)
|
216
|
+
@options[:android_package] = package
|
217
|
+
@options[:android_activity] = activity unless activity.nil?
|
218
|
+
@options[:android_device_serial] = serial_number unless serial_number.nil?
|
219
|
+
@options[:android_use_running_app] = use_running_app unless use_running_app.nil?
|
220
|
+
end
|
221
|
+
|
222
|
+
protected
|
223
|
+
|
224
|
+
def process_browser_options(browser_options)
|
225
|
+
enable_logging(browser_options) unless @logging_prefs.empty?
|
226
|
+
|
227
|
+
options = browser_options[self.class::KEY]
|
228
|
+
options['binary'] ||= binary_path if binary_path
|
229
|
+
|
230
|
+
if @profile
|
231
|
+
options['args'] ||= []
|
232
|
+
options['args'] << "--user-data-dir=#{@profile.directory}"
|
233
|
+
end
|
234
|
+
|
235
|
+
return if (@encoded_extensions + @extensions).empty?
|
236
|
+
|
237
|
+
options['extensions'] = @encoded_extensions + @extensions.map { |ext| encode_extension(ext) }
|
238
|
+
end
|
239
|
+
|
240
|
+
def binary_path
|
241
|
+
Chrome.path
|
242
|
+
end
|
243
|
+
|
244
|
+
def encode_extension(path)
|
245
|
+
File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
|
246
|
+
end
|
247
|
+
|
248
|
+
def validate_extension(path)
|
249
|
+
raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
|
250
|
+
raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx'
|
251
|
+
|
252
|
+
@extensions << path
|
253
|
+
end
|
254
|
+
|
255
|
+
def camelize?(key)
|
256
|
+
!%w[localState prefs].include?(key)
|
257
|
+
end
|
258
|
+
end # Options
|
259
|
+
end # Chromium
|
260
|
+
end # WebDriver
|
261
|
+
end # Selenium
|
@@ -0,0 +1,113 @@
|
|
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 Chromium
|
23
|
+
#
|
24
|
+
# @private
|
25
|
+
#
|
26
|
+
|
27
|
+
class Profile
|
28
|
+
include ProfileHelper
|
29
|
+
|
30
|
+
def initialize(model = nil)
|
31
|
+
@model = verify_model(model)
|
32
|
+
@extensions = []
|
33
|
+
@encoded_extensions = []
|
34
|
+
@directory = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_extension(path)
|
38
|
+
raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
|
39
|
+
|
40
|
+
@extensions << path
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_encoded_extension(encoded)
|
44
|
+
@encoded_extensions << encoded
|
45
|
+
end
|
46
|
+
|
47
|
+
def directory
|
48
|
+
@directory || layout_on_disk
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Set a preference in the profile.
|
53
|
+
#
|
54
|
+
# See https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc
|
55
|
+
#
|
56
|
+
|
57
|
+
def []=(key, value)
|
58
|
+
parts = key.split('.')
|
59
|
+
parts[0..-2].inject(prefs) { |a, e| a[e] ||= {} }[parts.last] = value
|
60
|
+
end
|
61
|
+
|
62
|
+
def [](key)
|
63
|
+
parts = key.split('.')
|
64
|
+
parts.inject(prefs) { |a, e| a.fetch(e) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def layout_on_disk
|
68
|
+
@directory = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-chrome-profile')
|
69
|
+
FileReaper << @directory
|
70
|
+
|
71
|
+
write_prefs_to @directory
|
72
|
+
|
73
|
+
@directory
|
74
|
+
end
|
75
|
+
|
76
|
+
def as_json(*)
|
77
|
+
extensions = @extensions.map do |crx_path|
|
78
|
+
File.open(crx_path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
|
79
|
+
end
|
80
|
+
|
81
|
+
extensions.concat(@encoded_extensions)
|
82
|
+
|
83
|
+
opts = {'directory' => directory || layout_on_disk}
|
84
|
+
opts['extensions'] = extensions if extensions.any?
|
85
|
+
opts
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def write_prefs_to(dir)
|
91
|
+
prefs_file = prefs_file_for(dir)
|
92
|
+
|
93
|
+
FileUtils.mkdir_p File.dirname(prefs_file)
|
94
|
+
File.open(prefs_file, 'w') { |file| file << JSON.generate(prefs) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def prefs
|
98
|
+
@prefs ||= read_model_prefs
|
99
|
+
end
|
100
|
+
|
101
|
+
def read_model_prefs
|
102
|
+
return {} unless @model
|
103
|
+
|
104
|
+
JSON.parse File.read(prefs_file_for(@model))
|
105
|
+
end
|
106
|
+
|
107
|
+
def prefs_file_for(dir)
|
108
|
+
File.join dir, 'Default', 'Preferences'
|
109
|
+
end
|
110
|
+
end # Profile
|
111
|
+
end # Chromium
|
112
|
+
end # WebDriver
|
113
|
+
end # Selenium
|
@@ -0,0 +1,42 @@
|
|
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 Chromium
|
23
|
+
class Service < WebDriver::Service
|
24
|
+
protected
|
25
|
+
|
26
|
+
def extract_service_args(driver_opts)
|
27
|
+
driver_args = super
|
28
|
+
driver_opts = driver_opts.dup
|
29
|
+
driver_args << "--log-path=#{driver_opts.delete(:log_path)}" if driver_opts.key?(:log_path)
|
30
|
+
driver_args << "--url-base=#{driver_opts.delete(:url_base)}" if driver_opts.key?(:url_base)
|
31
|
+
driver_args << "--port-server=#{driver_opts.delete(:port_server)}" if driver_opts.key?(:port_server)
|
32
|
+
if driver_opts.key?(:whitelisted_ips)
|
33
|
+
driver_args << "--whitelisted-ips=#{driver_opts.delete(:whitelisted_ips)}"
|
34
|
+
end
|
35
|
+
driver_args << '--verbose' if driver_opts.key?(:verbose)
|
36
|
+
driver_args << '--silent' if driver_opts.key?(:silent)
|
37
|
+
driver_args
|
38
|
+
end
|
39
|
+
end # Service
|
40
|
+
end # Chromium
|
41
|
+
end # WebDriver
|
42
|
+
end # Selenium
|
@@ -0,0 +1,32 @@
|
|
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 'net/http'
|
21
|
+
|
22
|
+
module Selenium
|
23
|
+
module WebDriver
|
24
|
+
module Chromium
|
25
|
+
autoload :Features, 'selenium/webdriver/chromium/features'
|
26
|
+
autoload :Driver, 'selenium/webdriver/chromium/driver'
|
27
|
+
autoload :Profile, 'selenium/webdriver/chromium/profile'
|
28
|
+
autoload :Options, 'selenium/webdriver/chromium/options'
|
29
|
+
autoload :Service, 'selenium/webdriver/chromium/service'
|
30
|
+
end # Chromium
|
31
|
+
end # WebDriver
|
32
|
+
end # Selenium
|