selenium-webdriver 3.142.7 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +685 -5
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/NOTICE +2 -0
  6. data/README.md +4 -5
  7. data/bin/linux/selenium-manager +0 -0
  8. data/bin/macos/selenium-manager +0 -0
  9. data/bin/windows/selenium-manager.exe +0 -0
  10. data/lib/selenium/server.rb +93 -90
  11. data/lib/selenium/webdriver/atoms/findElements.js +122 -0
  12. data/lib/selenium/webdriver/atoms/getAttribute.js +100 -7
  13. data/lib/selenium/webdriver/atoms/isDisplayed.js +77 -78
  14. data/lib/selenium/webdriver/atoms/mutationListener.js +55 -0
  15. data/lib/selenium/webdriver/atoms.rb +5 -3
  16. data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
  17. data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
  18. data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
  19. data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
  20. data/lib/selenium/webdriver/bidi/log/filter_by.rb +40 -0
  21. data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
  22. data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
  23. data/lib/selenium/webdriver/bidi/log_inspector.rb +143 -0
  24. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  25. data/lib/selenium/webdriver/bidi/session.rb +51 -0
  26. data/lib/selenium/webdriver/{common/keyboard.rb → bidi.rb} +21 -35
  27. data/lib/selenium/webdriver/chrome/driver.rb +9 -86
  28. data/lib/selenium/webdriver/chrome/features.rb +48 -0
  29. data/lib/selenium/webdriver/chrome/options.rb +9 -158
  30. data/lib/selenium/webdriver/chrome/profile.rb +3 -80
  31. data/lib/selenium/webdriver/chrome/service.rb +7 -29
  32. data/lib/selenium/webdriver/chrome.rb +5 -20
  33. data/lib/selenium/webdriver/chromium/driver.rb +60 -0
  34. data/lib/selenium/webdriver/{chrome/bridge.rb → chromium/features.rb} +48 -17
  35. data/lib/selenium/webdriver/chromium/options.rb +243 -0
  36. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  37. data/lib/selenium/webdriver/chromium.rb +29 -0
  38. data/lib/selenium/webdriver/common/action_builder.rb +126 -238
  39. data/lib/selenium/webdriver/common/child_process.rb +124 -0
  40. data/lib/selenium/webdriver/common/driver.rb +82 -43
  41. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  42. data/lib/selenium/webdriver/common/driver_extensions/{has_location.rb → full_page_screenshot.rb} +13 -11
  43. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +49 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +87 -0
  46. data/lib/selenium/webdriver/common/driver_extensions/{has_touch_screen.rb → has_bidi.rb} +9 -9
  47. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +86 -0
  48. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +36 -0
  49. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +42 -0
  50. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  51. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +41 -0
  52. data/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb +65 -0
  53. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +36 -0
  54. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
  55. data/lib/selenium/webdriver/common/driver_extensions/{has_remote_status.rb → has_logs.rb} +4 -4
  56. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +16 -1
  57. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +69 -0
  58. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +11 -13
  59. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +75 -0
  60. data/lib/selenium/webdriver/common/driver_extensions/{rotatable.rb → prints_page.rb} +18 -20
  61. data/lib/selenium/webdriver/common/driver_finder.rb +45 -0
  62. data/lib/selenium/webdriver/common/element.rb +89 -29
  63. data/lib/selenium/webdriver/common/error.rb +53 -194
  64. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  65. data/lib/selenium/webdriver/common/interactions/input_device.rb +10 -4
  66. data/lib/selenium/webdriver/common/interactions/interaction.rb +12 -22
  67. data/lib/selenium/webdriver/common/interactions/interactions.rb +24 -4
  68. data/lib/selenium/webdriver/common/interactions/key_actions.rb +10 -6
  69. data/lib/selenium/webdriver/common/interactions/key_input.rb +11 -27
  70. data/lib/selenium/webdriver/common/interactions/none_input.rb +10 -8
  71. data/lib/selenium/webdriver/common/interactions/pause.rb +49 -0
  72. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +71 -82
  73. data/lib/selenium/webdriver/common/interactions/pointer_cancel.rb +45 -0
  74. data/lib/selenium/webdriver/common/interactions/pointer_event_properties.rb +63 -0
  75. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +15 -84
  76. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +60 -0
  77. data/lib/selenium/webdriver/common/interactions/pointer_press.rb +85 -0
  78. data/lib/selenium/webdriver/common/interactions/scroll.rb +59 -0
  79. data/lib/selenium/webdriver/common/interactions/scroll_origin.rb +48 -0
  80. data/lib/selenium/webdriver/common/interactions/typing_interaction.rb +54 -0
  81. data/lib/selenium/webdriver/common/interactions/wheel_actions.rb +113 -0
  82. data/lib/selenium/webdriver/common/{w3c_manager.rb → interactions/wheel_input.rb} +14 -17
  83. data/lib/selenium/webdriver/common/keys.rb +1 -0
  84. data/lib/selenium/webdriver/common/local_driver.rb +46 -0
  85. data/lib/selenium/webdriver/common/log_entry.rb +2 -2
  86. data/lib/selenium/webdriver/common/logger.rb +119 -19
  87. data/lib/selenium/webdriver/common/manager.rb +11 -38
  88. data/lib/selenium/webdriver/common/options.rb +154 -23
  89. data/lib/selenium/webdriver/common/platform.rb +15 -52
  90. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  91. data/lib/selenium/webdriver/common/profile_helper.rb +11 -9
  92. data/lib/selenium/webdriver/common/proxy.rb +8 -5
  93. data/lib/selenium/webdriver/common/search_context.rb +7 -9
  94. data/lib/selenium/webdriver/common/selenium_manager.rb +140 -0
  95. data/lib/selenium/webdriver/common/service.rb +26 -143
  96. data/lib/selenium/webdriver/common/service_manager.rb +144 -0
  97. data/lib/selenium/webdriver/common/shadow_root.rb +86 -0
  98. data/lib/selenium/webdriver/common/socket_lock.rb +4 -4
  99. data/lib/selenium/webdriver/common/socket_poller.rb +4 -4
  100. data/lib/selenium/webdriver/common/takes_screenshot.rb +65 -0
  101. data/lib/selenium/webdriver/common/target_locator.rb +31 -4
  102. data/lib/selenium/webdriver/common/timeouts.rb +31 -4
  103. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +85 -0
  104. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +72 -0
  105. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +62 -0
  106. data/lib/selenium/webdriver/common/wait.rb +1 -1
  107. data/lib/selenium/webdriver/common/websocket_connection.rb +164 -0
  108. data/lib/selenium/webdriver/common/window.rb +6 -10
  109. data/lib/selenium/webdriver/common/zipper.rb +4 -10
  110. data/lib/selenium/webdriver/common.rb +43 -20
  111. data/lib/selenium/webdriver/devtools/console_event.rb +36 -0
  112. data/lib/selenium/webdriver/devtools/exception_event.rb +34 -0
  113. data/lib/selenium/webdriver/devtools/mutation_event.rb +35 -0
  114. data/lib/selenium/webdriver/devtools/network_interceptor.rb +173 -0
  115. data/lib/selenium/webdriver/devtools/pinned_script.rb +57 -0
  116. data/lib/selenium/webdriver/devtools/request.rb +65 -0
  117. data/lib/selenium/webdriver/devtools/response.rb +64 -0
  118. data/lib/selenium/webdriver/devtools.rb +96 -0
  119. data/lib/selenium/webdriver/edge/driver.rb +11 -27
  120. data/lib/selenium/webdriver/edge/features.rb +48 -0
  121. data/lib/selenium/webdriver/edge/options.rb +18 -43
  122. data/lib/selenium/webdriver/edge/profile.rb +33 -0
  123. data/lib/selenium/webdriver/edge/service.rb +8 -23
  124. data/lib/selenium/webdriver/edge.rb +11 -16
  125. data/lib/selenium/webdriver/firefox/driver.rb +38 -19
  126. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  127. data/lib/selenium/webdriver/firefox/features.rb +70 -0
  128. data/lib/selenium/webdriver/firefox/options.rb +73 -61
  129. data/lib/selenium/webdriver/firefox/profile.rb +20 -72
  130. data/lib/selenium/webdriver/firefox/service.rb +3 -25
  131. data/lib/selenium/webdriver/firefox/util.rb +1 -1
  132. data/lib/selenium/webdriver/firefox.rb +17 -28
  133. data/lib/selenium/webdriver/ie/driver.rb +5 -45
  134. data/lib/selenium/webdriver/ie/features.rb +34 -0
  135. data/lib/selenium/webdriver/ie/options.rb +14 -44
  136. data/lib/selenium/webdriver/ie/service.rb +3 -27
  137. data/lib/selenium/webdriver/ie.rb +4 -16
  138. data/lib/selenium/webdriver/remote/bridge/commands.rb +164 -0
  139. data/lib/selenium/webdriver/remote/bridge.rb +574 -88
  140. data/lib/selenium/webdriver/remote/capabilities.rb +144 -158
  141. data/lib/selenium/webdriver/remote/driver.rb +45 -14
  142. data/lib/selenium/webdriver/remote/features.rb +75 -0
  143. data/lib/selenium/webdriver/remote/http/common.rb +3 -8
  144. data/lib/selenium/webdriver/remote/http/curb.rb +1 -3
  145. data/lib/selenium/webdriver/remote/http/default.rb +24 -33
  146. data/lib/selenium/webdriver/remote/response.rb +17 -49
  147. data/lib/selenium/webdriver/remote/server_error.rb +1 -1
  148. data/lib/selenium/webdriver/remote.rb +15 -12
  149. data/lib/selenium/webdriver/safari/driver.rb +7 -29
  150. data/lib/selenium/webdriver/safari/{bridge.rb → features.rb} +7 -5
  151. data/lib/selenium/webdriver/safari/options.rb +12 -27
  152. data/lib/selenium/webdriver/safari/service.rb +13 -11
  153. data/lib/selenium/webdriver/safari.rb +14 -20
  154. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -1
  155. data/lib/selenium/webdriver/support/color.rb +24 -24
  156. data/lib/selenium/webdriver/support/event_firing_bridge.rb +5 -5
  157. data/lib/selenium/webdriver/support/guards/guard.rb +90 -0
  158. data/lib/selenium/webdriver/{firefox/marionette/bridge.rb → support/guards/guard_condition.rb} +21 -20
  159. data/lib/selenium/webdriver/support/guards.rb +95 -0
  160. data/lib/selenium/webdriver/support/relative_locator.rb +50 -0
  161. data/lib/selenium/webdriver/support/select.rb +6 -4
  162. data/lib/selenium/webdriver/support.rb +1 -0
  163. data/lib/selenium/webdriver/version.rb +1 -1
  164. data/lib/selenium/webdriver.rb +19 -17
  165. data/selenium-webdriver.gemspec +36 -18
  166. metadata +161 -91
  167. data/lib/selenium/webdriver/common/bridge_helper.rb +0 -82
  168. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +0 -58
  169. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +0 -64
  170. data/lib/selenium/webdriver/common/mouse.rb +0 -89
  171. data/lib/selenium/webdriver/common/touch_action_builder.rb +0 -78
  172. data/lib/selenium/webdriver/common/touch_screen.rb +0 -123
  173. data/lib/selenium/webdriver/common/w3c_action_builder.rb +0 -212
  174. data/lib/selenium/webdriver/edge/bridge.rb +0 -76
  175. data/lib/selenium/webdriver/firefox/binary.rb +0 -187
  176. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
  177. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  178. data/lib/selenium/webdriver/firefox/launcher.rb +0 -111
  179. data/lib/selenium/webdriver/firefox/legacy/driver.rb +0 -83
  180. data/lib/selenium/webdriver/firefox/marionette/driver.rb +0 -90
  181. data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
  182. data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
  183. data/lib/selenium/webdriver/remote/http/persistent.rb +0 -60
  184. data/lib/selenium/webdriver/remote/oss/bridge.rb +0 -594
  185. data/lib/selenium/webdriver/remote/oss/commands.rb +0 -223
  186. data/lib/selenium/webdriver/remote/w3c/bridge.rb +0 -605
  187. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +0 -310
  188. 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
+ module DriverExtensions
23
+ module HasFileDownloads
24
+ def downloadable_files
25
+ verify_enabled
26
+
27
+ @bridge.downloadable_files['names']
28
+ end
29
+
30
+ def download_file(file_name, target_directory)
31
+ verify_enabled
32
+
33
+ response = @bridge.download_file(file_name)
34
+ contents = response['contents']
35
+
36
+ File.open("#{file_name}.zip", 'wb') { |f| f << Base64.decode64(contents) }
37
+ target_directory += '/' unless target_directory.end_with?('/')
38
+ FileUtils.mkdir_p(target_directory)
39
+
40
+ begin
41
+ Zip::File.open("#{file_name}.zip") do |zip|
42
+ zip.each { |entry| zip.extract(entry, "#{target_directory}#{file_name}") }
43
+ end
44
+ ensure
45
+ FileUtils.rm_f("#{file_name}.zip")
46
+ end
47
+ end
48
+
49
+ def delete_downloadable_files
50
+ verify_enabled
51
+
52
+ @bridge.delete_downloadable_files
53
+ end
54
+
55
+ private
56
+
57
+ def verify_enabled
58
+ return if capabilities['se:downloadsEnabled']
59
+
60
+ raise Error::WebDriverError, 'You must enable downloads in order to work with downloadable files.'
61
+ end
62
+ end # HasFileDownloads
63
+ end # DriverExtensions
64
+ end # WebDriver
65
+ end # Selenium
@@ -0,0 +1,36 @@
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 DriverExtensions
23
+ module HasLaunching
24
+ #
25
+ # Launches Chromium app specified by id.
26
+ #
27
+ # @param [String] id
28
+ #
29
+
30
+ def launch_app(id)
31
+ @bridge.launch_app(id)
32
+ end
33
+ end # HasLaunching
34
+ end # DriverExtensions
35
+ end # WebDriver
36
+ end # Selenium
@@ -0,0 +1,143 @@
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 DriverExtensions
23
+ module HasLogEvents
24
+ include Atoms
25
+
26
+ KINDS = %i[console exception mutation].freeze
27
+
28
+ #
29
+ # Registers listener to be called whenever browser receives
30
+ # a new Console API message such as console.log() or an unhandled
31
+ # exception.
32
+ #
33
+ # This currently relies on DevTools so is only supported in
34
+ # Chromium browsers.
35
+ #
36
+ # @example Collect console messages
37
+ # logs = []
38
+ # driver.on_log_event(:console) do |event|
39
+ # logs.push(event)
40
+ # end
41
+ #
42
+ # @example Collect JavaScript exceptions
43
+ # exceptions = []
44
+ # driver.on_log_event(:exception) do |event|
45
+ # exceptions.push(event)
46
+ # end
47
+ #
48
+ # @example Collect DOM mutations
49
+ # mutations = []
50
+ # driver.on_log_event(:mutation) do |event|
51
+ # mutations.push(event)
52
+ # end
53
+ #
54
+ # @param [Symbol] kind :console, :exception or :mutation
55
+ # @param [#call] block which is called when event happens
56
+ # @yieldparam [DevTools::ConsoleEvent, DevTools::ExceptionEvent, DevTools::MutationEvent]
57
+ #
58
+
59
+ def on_log_event(kind, &block)
60
+ raise Error::WebDriverError, "Don't know how to handle #{kind} events" unless KINDS.include?(kind)
61
+
62
+ enabled = log_listeners[kind].any?
63
+ log_listeners[kind] << block
64
+ return if enabled
65
+
66
+ devtools.runtime.enable
67
+ __send__("log_#{kind}_events")
68
+ end
69
+
70
+ private
71
+
72
+ def log_listeners
73
+ @log_listeners ||= Hash.new { |listeners, kind| listeners[kind] = [] }
74
+ end
75
+
76
+ def log_console_events
77
+ devtools.runtime.on(:console_api_called) do |params|
78
+ event = DevTools::ConsoleEvent.new(
79
+ type: params['type'],
80
+ timestamp: params['timestamp'],
81
+ args: params['args']
82
+ )
83
+
84
+ log_listeners[:console].each do |listener|
85
+ listener.call(event)
86
+ end
87
+ end
88
+ end
89
+
90
+ def log_exception_events
91
+ devtools.runtime.on(:exception_thrown) do |params|
92
+ description = if params.dig('exceptionDetails', 'exception')
93
+ params.dig('exceptionDetails', 'exception', 'description')
94
+ else
95
+ params.dig('exceptionDetails', 'text')
96
+ end
97
+
98
+ event = DevTools::ExceptionEvent.new(
99
+ description: description,
100
+ timestamp: params['timestamp'],
101
+ stacktrace: params.dig('exceptionDetails', 'stackTrace', 'callFrames')
102
+ )
103
+
104
+ log_listeners[:exception].each do |listener|
105
+ listener.call(event)
106
+ end
107
+ end
108
+ end
109
+
110
+ def log_mutation_events
111
+ devtools.page.enable
112
+
113
+ devtools.runtime.add_binding(name: '__webdriver_attribute')
114
+ execute_script(mutation_listener)
115
+ devtools.page.add_script_to_evaluate_on_new_document(source: mutation_listener)
116
+
117
+ devtools.runtime.on(:binding_called) { |event| log_mutation_event(event) }
118
+ end
119
+
120
+ def log_mutation_event(params)
121
+ payload = JSON.parse(params['payload'])
122
+ elements = find_elements(css: "*[data-__webdriver_id='#{payload['target']}']")
123
+ return if elements.empty?
124
+
125
+ event = DevTools::MutationEvent.new(
126
+ element: elements.first,
127
+ attribute_name: payload['name'],
128
+ current_value: payload['value'],
129
+ old_value: payload['oldValue']
130
+ )
131
+
132
+ log_listeners[:mutation].each do |log_listener|
133
+ log_listener.call(event)
134
+ end
135
+ end
136
+
137
+ def mutation_listener
138
+ @mutation_listener ||= read_atom(:mutationListener)
139
+ end
140
+ end # HasLogEvents
141
+ end # DriverExtensions
142
+ end # WebDriver
143
+ end # Selenium
@@ -20,11 +20,11 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
- module HasRemoteStatus
24
- def remote_status
25
- @bridge.status
23
+ module HasLogs
24
+ def logs
25
+ @logs ||= Logs.new(@bridge)
26
26
  end
27
- end # HasRemoteStatus
27
+ end # HasLogs
28
28
  end # DriverExtensions
29
29
  end # WebDriver
30
30
  end # Selenium
@@ -21,7 +21,6 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module HasNetworkConditions
24
-
25
24
  #
26
25
  # Returns network conditions.
27
26
  #
@@ -38,13 +37,29 @@ module Selenium
38
37
  # @param [Hash] conditions
39
38
  # @option conditions [Integer] :latency
40
39
  # @option conditions [Integer] :throughput
40
+ # @option conditions [Integer] :upload_throughput
41
+ # @option conditions [Integer] :download_throughput
41
42
  # @option conditions [Boolean] :offline
42
43
  #
43
44
 
44
45
  def network_conditions=(conditions)
46
+ conditions[:latency] ||= 0
47
+ unless conditions.key?(:throughput)
48
+ conditions[:download_throughput] ||= -1
49
+ conditions[:upload_throughput] ||= -1
50
+ end
51
+ conditions[:offline] = false unless conditions.key?(:offline)
52
+
45
53
  @bridge.network_conditions = conditions
46
54
  end
47
55
 
56
+ #
57
+ # Resets Chromium network emulation settings.
58
+ #
59
+
60
+ def delete_network_conditions
61
+ @bridge.delete_network_conditions
62
+ end
48
63
  end # HasNetworkConditions
49
64
  end # DriverExtensions
50
65
  end # WebDriver
@@ -0,0 +1,69 @@
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 DriverExtensions
23
+ module HasNetworkInterception
24
+ #
25
+ # Intercepts requests coming from browser allowing
26
+ # to either pass them through like proxy or provide
27
+ # a stubbed response instead.
28
+ #
29
+ # @example Log requests and pass through
30
+ # driver.intercept do |request, &continue|
31
+ # puts "#{request.method} #{request.url}"
32
+ # continue.call(request)
33
+ # end
34
+ #
35
+ # @example Stub requests for images
36
+ # driver.intercept do |request, &continue|
37
+ # if request.url.match?(/\.png$/)
38
+ # request.url = 'https://upload.wikimedia.org/wikipedia/commons/d/d5/Selenium_Logo.png'
39
+ # end
40
+ # continue.call(request)
41
+ # end
42
+ #
43
+ # @example Log responses and pass through
44
+ # driver.intercept do |request, &continue|
45
+ # continue.call(request) do |response|
46
+ # puts "#{response.code} #{response.body}"
47
+ # end
48
+ # end
49
+ #
50
+ # @example Mutate specific response
51
+ # driver.intercept do |request, &continue|
52
+ # continue.call(request) do |response|
53
+ # response.body << 'Added by Selenium!' if request.url.include?('/myurl')
54
+ # end
55
+ # end
56
+ #
57
+ # @param [Proc] block which is called when request is intercepted
58
+ # @yieldparam [DevTools::Request] request
59
+ # @yieldparam [Proc] continue block which proceeds with the request and optionally yields response
60
+ #
61
+
62
+ def intercept(&block)
63
+ @interceptor ||= DevTools::NetworkInterceptor.new(devtools)
64
+ @interceptor.intercept(&block)
65
+ end
66
+ end # HasNetworkInterception
67
+ end # DriverExtensions
68
+ end # WebDriver
69
+ end # Selenium
@@ -21,30 +21,28 @@ module Selenium
21
21
  module WebDriver
22
22
  module DriverExtensions
23
23
  module HasPermissions
24
-
25
24
  #
26
- # Returns permissions.
25
+ # Set one permission.
27
26
  #
28
- # @return [Hash]
27
+ # @param [String] name which permission to set
28
+ # @param [String] value what to set the permission to
29
29
  #
30
30
 
31
- def permissions
32
- @bridge.permissions
31
+ def add_permission(name, value)
32
+ @bridge.set_permission(name, value)
33
33
  end
34
34
 
35
35
  #
36
- # Sets permissions.
37
- #
38
- # @example
39
- # driver.permissions = {'getUserMedia' => true}
36
+ # Set multiple permissions.
40
37
  #
41
- # @param [Hash<Symbol, Boolean>] permissions
38
+ # @param [Hash] opt key/value pairs to set permissions
42
39
  #
43
40
 
44
- def permissions=(permissions)
45
- @bridge.permissions = permissions
41
+ def add_permissions(opt)
42
+ opt.each do |key, value|
43
+ @bridge.set_permission(key, value)
44
+ end
46
45
  end
47
-
48
46
  end # HasPermissions
49
47
  end # DriverExtensions
50
48
  end # WebDriver
@@ -0,0 +1,75 @@
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 DriverExtensions
23
+ module HasPinnedScripts
24
+ #
25
+ # Returns the list of all pinned scripts.
26
+ #
27
+ # @return [Array<DevTools::PinnedScript>]
28
+ #
29
+
30
+ def pinned_scripts
31
+ @pinned_scripts ||= []
32
+ end
33
+
34
+ #
35
+ # Pins JavaScript snippet that is available during the whole
36
+ # session on every page. This allows to store and call
37
+ # scripts without sending them over the wire every time.
38
+ #
39
+ # @example
40
+ # script = driver.pin_script('return window.location.href')
41
+ # driver.execute_script(script)
42
+ # # navigate to a new page
43
+ # driver.execute_script(script)
44
+ #
45
+ # @param [String] script
46
+ # @return [DevTools::PinnedScript]
47
+ #
48
+
49
+ def pin_script(script)
50
+ script = DevTools::PinnedScript.new(script)
51
+ pinned_scripts << script
52
+
53
+ devtools.page.enable
54
+ devtools.runtime.evaluate(expression: script.callable)
55
+ response = devtools.page.add_script_to_evaluate_on_new_document(source: script.callable)
56
+ script.devtools_identifier = response.dig('result', 'identifier')
57
+
58
+ script
59
+ end
60
+
61
+ #
62
+ # Unpins script making it undefined for the subsequent calls.
63
+ #
64
+ # @param [DevTools::PinnedScript] script
65
+ #
66
+
67
+ def unpin_script(script)
68
+ devtools.runtime.evaluate(expression: script.remove)
69
+ devtools.page.remove_script_to_evaluate_on_new_document(identifier: script.devtools_identifier)
70
+ pinned_scripts.delete(script)
71
+ end
72
+ end # HasPinnedScripts
73
+ end # DriverExtensions
74
+ end # WebDriver
75
+ end # Selenium
@@ -19,43 +19,41 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- #
23
- # @api private
24
- #
25
-
26
22
  module DriverExtensions
27
- module Rotatable
28
- ORIENTATIONS = %i[landscape portrait].freeze
29
-
23
+ module PrintsPage
24
+ #
25
+ # Save a page as a PDF to the given path
30
26
  #
31
- # Change the screen orientation
27
+ # @example Save Printed Page
28
+ # driver.save_print_page('../printed_page.pdf')
32
29
  #
33
- # @param [:landscape, :portrait] orientation
30
+ # @param [String] path to where the pdf should be saved
34
31
  #
35
32
  # @api public
36
33
  #
37
34
 
38
- def rotation=(orientation)
39
- unless ORIENTATIONS.include?(orientation)
40
- raise ArgumentError, "expected #{ORIENTATIONS.inspect}, got #{orientation.inspect}"
35
+ def save_print_page(path, **options)
36
+ File.open(path, 'wb') do |file|
37
+ content = Base64.decode64 print_page(**options)
38
+ file << content
41
39
  end
42
-
43
- bridge.screen_orientation = orientation.to_s.upcase
44
40
  end
45
- alias_method :rotate, :rotation=
46
41
 
47
42
  #
48
- # Get the current screen orientation
43
+ # Return a Base64 encoded Print Page as a string
49
44
  #
50
- # @return [:landscape, :portrait] orientation
45
+ # @see https://w3c.github.io/webdriver/#print-page
51
46
  #
52
47
  # @api public
53
48
  #
54
49
 
55
- def orientation
56
- bridge.screen_orientation.to_sym.downcase
50
+ def print_page(**options)
51
+ options[:pageRanges] = Array(options.delete(:page_ranges)) || []
52
+ options[:shrinkToFit] = options.delete(:shrink_to_fit) { true }
53
+
54
+ @bridge.print_page(options)
57
55
  end
58
- end # Rotatable
56
+ end # PrintsPage
59
57
  end # DriverExtensions
60
58
  end # WebDriver
61
59
  end # Selenium
@@ -0,0 +1,45 @@
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 DriverFinder
23
+ def self.path(options, klass)
24
+ path = klass.driver_path
25
+ path = path.call if path.is_a?(Proc)
26
+
27
+ path ||= begin
28
+ SeleniumManager.driver_path(options) unless options.is_a?(Remote::Capabilities)
29
+ rescue StandardError => e
30
+ raise Error::NoSuchDriverError, "Unable to obtain #{klass::EXECUTABLE} using Selenium Manager; #{e.message}"
31
+ end
32
+
33
+ begin
34
+ Platform.assert_executable(path)
35
+ rescue TypeError
36
+ raise Error::NoSuchDriverError, "Unable to locate or obtain #{klass::EXECUTABLE}"
37
+ rescue Error::WebDriverError => e
38
+ raise Error::NoSuchDriverError, "#{klass::EXECUTABLE} located, but: #{e.message}"
39
+ end
40
+
41
+ path
42
+ end
43
+ end
44
+ end
45
+ end