selenium-webdriver 4.0.0.alpha2 → 4.0.0.alpha7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +172 -4
  3. data/LICENSE +1 -1
  4. data/lib/selenium/server.rb +25 -9
  5. data/lib/selenium/webdriver.rb +12 -8
  6. data/lib/selenium/webdriver/atoms/findElements.js +121 -0
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +104 -7
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +76 -78
  9. data/lib/selenium/webdriver/atoms/mutationListener.js +38 -0
  10. data/lib/selenium/webdriver/chrome.rb +10 -9
  11. data/lib/selenium/webdriver/chrome/bridge.rb +20 -4
  12. data/lib/selenium/webdriver/chrome/driver.rb +7 -49
  13. data/lib/selenium/webdriver/chrome/options.rb +97 -57
  14. data/lib/selenium/webdriver/chrome/profile.rb +3 -3
  15. data/lib/selenium/webdriver/chrome/service.rb +0 -4
  16. data/lib/selenium/webdriver/common.rb +6 -1
  17. data/lib/selenium/webdriver/common/driver.rb +81 -17
  18. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +89 -0
  19. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +39 -0
  20. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +143 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -1
  22. data/lib/selenium/webdriver/common/element.rb +5 -0
  23. data/lib/selenium/webdriver/common/logger.rb +48 -16
  24. data/lib/selenium/webdriver/common/manager.rb +5 -0
  25. data/lib/selenium/webdriver/common/options.rb +116 -0
  26. data/lib/selenium/webdriver/common/platform.rb +4 -1
  27. data/lib/selenium/webdriver/common/port_prober.rb +4 -6
  28. data/lib/selenium/webdriver/common/profile_helper.rb +10 -2
  29. data/lib/selenium/webdriver/common/proxy.rb +0 -0
  30. data/lib/selenium/webdriver/common/search_context.rb +3 -2
  31. data/lib/selenium/webdriver/common/service.rb +30 -113
  32. data/lib/selenium/webdriver/common/service_manager.rb +151 -0
  33. data/lib/selenium/webdriver/common/socket_lock.rb +2 -2
  34. data/lib/selenium/webdriver/common/takes_screenshot.rb +63 -0
  35. data/lib/selenium/webdriver/common/wait.rb +1 -1
  36. data/lib/selenium/webdriver/devtools.rb +132 -0
  37. data/lib/selenium/webdriver/devtools/console_event.rb +38 -0
  38. data/lib/selenium/webdriver/devtools/exception_event.rb +36 -0
  39. data/lib/selenium/webdriver/devtools/mutation_event.rb +37 -0
  40. data/lib/selenium/webdriver/devtools/v84/accessibility.rb +64 -0
  41. data/lib/selenium/webdriver/devtools/v84/animation.rb +100 -0
  42. data/lib/selenium/webdriver/devtools/v84/application_cache.rb +66 -0
  43. data/lib/selenium/webdriver/devtools/v84/audits.rb +63 -0
  44. data/lib/selenium/webdriver/devtools/v84/background_service.rb +69 -0
  45. data/lib/selenium/webdriver/devtools/v84/browser.rb +125 -0
  46. data/lib/selenium/webdriver/devtools/v84/cache_storage.rb +75 -0
  47. data/lib/selenium/webdriver/devtools/v84/cast.rb +72 -0
  48. data/lib/selenium/webdriver/devtools/v84/console.rb +59 -0
  49. data/lib/selenium/webdriver/devtools/v84/css.rb +167 -0
  50. data/lib/selenium/webdriver/devtools/v84/database.rb +66 -0
  51. data/lib/selenium/webdriver/devtools/v84/debugger.rb +231 -0
  52. data/lib/selenium/webdriver/devtools/v84/device_orientation.rb +55 -0
  53. data/lib/selenium/webdriver/devtools/v84/dom.rb +322 -0
  54. data/lib/selenium/webdriver/devtools/v84/dom_debugger.rb +95 -0
  55. data/lib/selenium/webdriver/devtools/v84/dom_snapshot.rb +67 -0
  56. data/lib/selenium/webdriver/devtools/v84/dom_storage.rb +81 -0
  57. data/lib/selenium/webdriver/devtools/v84/emulation.rb +182 -0
  58. data/lib/selenium/webdriver/devtools/v84/fetch.rb +99 -0
  59. data/lib/selenium/webdriver/devtools/v84/headless_experimental.rb +63 -0
  60. data/lib/selenium/webdriver/devtools/v84/heap_profiler.rb +109 -0
  61. data/lib/selenium/webdriver/devtools/v84/indexed_db.rb +102 -0
  62. data/lib/selenium/webdriver/devtools/v84/input.rb +142 -0
  63. data/lib/selenium/webdriver/devtools/v84/inspector.rb +57 -0
  64. data/lib/selenium/webdriver/devtools/v84/io.rb +61 -0
  65. data/lib/selenium/webdriver/devtools/v84/layer_tree.rb +97 -0
  66. data/lib/selenium/webdriver/devtools/v84/log.rb +68 -0
  67. data/lib/selenium/webdriver/devtools/v84/media.rb +59 -0
  68. data/lib/selenium/webdriver/devtools/v84/memory.rb +88 -0
  69. data/lib/selenium/webdriver/devtools/v84/network.rb +230 -0
  70. data/lib/selenium/webdriver/devtools/v84/overlay.rb +159 -0
  71. data/lib/selenium/webdriver/devtools/v84/page.rb +376 -0
  72. data/lib/selenium/webdriver/devtools/v84/performance.rb +65 -0
  73. data/lib/selenium/webdriver/devtools/v84/profiler.rb +113 -0
  74. data/lib/selenium/webdriver/devtools/v84/runtime.rb +195 -0
  75. data/lib/selenium/webdriver/devtools/v84/schema.rb +48 -0
  76. data/lib/selenium/webdriver/devtools/v84/security.rb +73 -0
  77. data/lib/selenium/webdriver/devtools/v84/service_worker.rb +118 -0
  78. data/lib/selenium/webdriver/devtools/v84/storage.rb +97 -0
  79. data/lib/selenium/webdriver/devtools/v84/system_info.rb +52 -0
  80. data/lib/selenium/webdriver/devtools/v84/target.rb +143 -0
  81. data/lib/selenium/webdriver/devtools/v84/tethering.rb +57 -0
  82. data/lib/selenium/webdriver/devtools/v84/tracing.rb +78 -0
  83. data/lib/selenium/webdriver/devtools/v84/web_audio.rb +72 -0
  84. data/lib/selenium/webdriver/devtools/v84/web_authn.rb +96 -0
  85. data/lib/selenium/webdriver/devtools/v85/accessibility.rb +64 -0
  86. data/lib/selenium/webdriver/devtools/v85/animation.rb +100 -0
  87. data/lib/selenium/webdriver/devtools/v85/application_cache.rb +66 -0
  88. data/lib/selenium/webdriver/devtools/v85/audits.rb +63 -0
  89. data/lib/selenium/webdriver/devtools/v85/background_service.rb +69 -0
  90. data/lib/selenium/webdriver/devtools/v85/browser.rb +125 -0
  91. data/lib/selenium/webdriver/devtools/v85/cache_storage.rb +75 -0
  92. data/lib/selenium/webdriver/devtools/v85/cast.rb +72 -0
  93. data/lib/selenium/webdriver/devtools/v85/console.rb +59 -0
  94. data/lib/selenium/webdriver/devtools/v85/css.rb +167 -0
  95. data/lib/selenium/webdriver/devtools/v85/database.rb +66 -0
  96. data/lib/selenium/webdriver/devtools/v85/debugger.rb +231 -0
  97. data/lib/selenium/webdriver/devtools/v85/device_orientation.rb +55 -0
  98. data/lib/selenium/webdriver/devtools/v85/dom.rb +322 -0
  99. data/lib/selenium/webdriver/devtools/v85/dom_debugger.rb +95 -0
  100. data/lib/selenium/webdriver/devtools/v85/dom_snapshot.rb +67 -0
  101. data/lib/selenium/webdriver/devtools/v85/dom_storage.rb +81 -0
  102. data/lib/selenium/webdriver/devtools/v85/emulation.rb +182 -0
  103. data/lib/selenium/webdriver/devtools/v85/fetch.rb +99 -0
  104. data/lib/selenium/webdriver/devtools/v85/headless_experimental.rb +63 -0
  105. data/lib/selenium/webdriver/devtools/v85/heap_profiler.rb +109 -0
  106. data/lib/selenium/webdriver/devtools/v85/indexed_db.rb +102 -0
  107. data/lib/selenium/webdriver/devtools/v85/input.rb +143 -0
  108. data/lib/selenium/webdriver/devtools/v85/inspector.rb +57 -0
  109. data/lib/selenium/webdriver/devtools/v85/io.rb +61 -0
  110. data/lib/selenium/webdriver/devtools/v85/layer_tree.rb +97 -0
  111. data/lib/selenium/webdriver/devtools/v85/log.rb +68 -0
  112. data/lib/selenium/webdriver/devtools/v85/media.rb +59 -0
  113. data/lib/selenium/webdriver/devtools/v85/memory.rb +88 -0
  114. data/lib/selenium/webdriver/devtools/v85/network.rb +230 -0
  115. data/lib/selenium/webdriver/devtools/v85/overlay.rb +160 -0
  116. data/lib/selenium/webdriver/devtools/v85/page.rb +376 -0
  117. data/lib/selenium/webdriver/devtools/v85/performance.rb +65 -0
  118. data/lib/selenium/webdriver/devtools/v85/profiler.rb +113 -0
  119. data/lib/selenium/webdriver/devtools/v85/runtime.rb +196 -0
  120. data/lib/selenium/webdriver/devtools/v85/schema.rb +48 -0
  121. data/lib/selenium/webdriver/devtools/v85/security.rb +73 -0
  122. data/lib/selenium/webdriver/devtools/v85/service_worker.rb +118 -0
  123. data/lib/selenium/webdriver/devtools/v85/storage.rb +97 -0
  124. data/lib/selenium/webdriver/devtools/v85/system_info.rb +52 -0
  125. data/lib/selenium/webdriver/devtools/v85/target.rb +145 -0
  126. data/lib/selenium/webdriver/devtools/v85/tethering.rb +57 -0
  127. data/lib/selenium/webdriver/devtools/v85/tracing.rb +78 -0
  128. data/lib/selenium/webdriver/devtools/v85/web_audio.rb +72 -0
  129. data/lib/selenium/webdriver/devtools/v85/web_authn.rb +96 -0
  130. data/lib/selenium/webdriver/devtools/v86/accessibility.rb +64 -0
  131. data/lib/selenium/webdriver/devtools/v86/animation.rb +100 -0
  132. data/lib/selenium/webdriver/devtools/v86/application_cache.rb +66 -0
  133. data/lib/selenium/webdriver/devtools/v86/audits.rb +63 -0
  134. data/lib/selenium/webdriver/devtools/v86/background_service.rb +69 -0
  135. data/lib/selenium/webdriver/devtools/v86/browser.rb +125 -0
  136. data/lib/selenium/webdriver/devtools/v86/cache_storage.rb +75 -0
  137. data/lib/selenium/webdriver/devtools/v86/cast.rb +72 -0
  138. data/lib/selenium/webdriver/devtools/v86/console.rb +59 -0
  139. data/lib/selenium/webdriver/devtools/v86/css.rb +181 -0
  140. data/lib/selenium/webdriver/devtools/v86/database.rb +66 -0
  141. data/lib/selenium/webdriver/devtools/v86/debugger.rb +233 -0
  142. data/lib/selenium/webdriver/devtools/v86/device_orientation.rb +55 -0
  143. data/lib/selenium/webdriver/devtools/v86/dom.rb +329 -0
  144. data/lib/selenium/webdriver/devtools/v86/dom_debugger.rb +95 -0
  145. data/lib/selenium/webdriver/devtools/v86/dom_snapshot.rb +67 -0
  146. data/lib/selenium/webdriver/devtools/v86/dom_storage.rb +81 -0
  147. data/lib/selenium/webdriver/devtools/v86/emulation.rb +193 -0
  148. data/lib/selenium/webdriver/devtools/v86/fetch.rb +99 -0
  149. data/lib/selenium/webdriver/devtools/v86/headless_experimental.rb +63 -0
  150. data/lib/selenium/webdriver/devtools/v86/heap_profiler.rb +109 -0
  151. data/lib/selenium/webdriver/devtools/v86/indexed_db.rb +102 -0
  152. data/lib/selenium/webdriver/devtools/v86/input.rb +143 -0
  153. data/lib/selenium/webdriver/devtools/v86/inspector.rb +57 -0
  154. data/lib/selenium/webdriver/devtools/v86/io.rb +61 -0
  155. data/lib/selenium/webdriver/devtools/v86/layer_tree.rb +97 -0
  156. data/lib/selenium/webdriver/devtools/v86/log.rb +68 -0
  157. data/lib/selenium/webdriver/devtools/v86/media.rb +59 -0
  158. data/lib/selenium/webdriver/devtools/v86/memory.rb +88 -0
  159. data/lib/selenium/webdriver/devtools/v86/network.rb +235 -0
  160. data/lib/selenium/webdriver/devtools/v86/overlay.rb +183 -0
  161. data/lib/selenium/webdriver/devtools/v86/page.rb +376 -0
  162. data/lib/selenium/webdriver/devtools/v86/performance.rb +65 -0
  163. data/lib/selenium/webdriver/devtools/v86/profiler.rb +113 -0
  164. data/lib/selenium/webdriver/devtools/v86/runtime.rb +196 -0
  165. data/lib/selenium/webdriver/devtools/v86/schema.rb +48 -0
  166. data/lib/selenium/webdriver/devtools/v86/security.rb +73 -0
  167. data/lib/selenium/webdriver/devtools/v86/service_worker.rb +118 -0
  168. data/lib/selenium/webdriver/devtools/v86/storage.rb +97 -0
  169. data/lib/selenium/webdriver/devtools/v86/system_info.rb +52 -0
  170. data/lib/selenium/webdriver/devtools/v86/target.rb +145 -0
  171. data/lib/selenium/webdriver/devtools/v86/tethering.rb +57 -0
  172. data/lib/selenium/webdriver/devtools/v86/tracing.rb +78 -0
  173. data/lib/selenium/webdriver/devtools/v86/web_audio.rb +72 -0
  174. data/lib/selenium/webdriver/devtools/v86/web_authn.rb +102 -0
  175. data/lib/selenium/webdriver/devtools/v87/accessibility.rb +73 -0
  176. data/lib/selenium/webdriver/devtools/v87/animation.rb +100 -0
  177. data/lib/selenium/webdriver/devtools/v87/application_cache.rb +66 -0
  178. data/lib/selenium/webdriver/devtools/v87/audits.rb +63 -0
  179. data/lib/selenium/webdriver/devtools/v87/background_service.rb +69 -0
  180. data/lib/selenium/webdriver/devtools/v87/browser.rb +125 -0
  181. data/lib/selenium/webdriver/devtools/v87/cache_storage.rb +75 -0
  182. data/lib/selenium/webdriver/devtools/v87/cast.rb +72 -0
  183. data/lib/selenium/webdriver/devtools/v87/console.rb +59 -0
  184. data/lib/selenium/webdriver/devtools/v87/css.rb +181 -0
  185. data/lib/selenium/webdriver/devtools/v87/database.rb +66 -0
  186. data/lib/selenium/webdriver/devtools/v87/debugger.rb +233 -0
  187. data/lib/selenium/webdriver/devtools/v87/device_orientation.rb +55 -0
  188. data/lib/selenium/webdriver/devtools/v87/dom.rb +329 -0
  189. data/lib/selenium/webdriver/devtools/v87/dom_debugger.rb +95 -0
  190. data/lib/selenium/webdriver/devtools/v87/dom_snapshot.rb +67 -0
  191. data/lib/selenium/webdriver/devtools/v87/dom_storage.rb +81 -0
  192. data/lib/selenium/webdriver/devtools/v87/emulation.rb +193 -0
  193. data/lib/selenium/webdriver/devtools/v87/fetch.rb +99 -0
  194. data/lib/selenium/webdriver/devtools/v87/headless_experimental.rb +63 -0
  195. data/lib/selenium/webdriver/devtools/v87/heap_profiler.rb +109 -0
  196. data/lib/selenium/webdriver/devtools/v87/indexed_db.rb +102 -0
  197. data/lib/selenium/webdriver/devtools/v87/input.rb +143 -0
  198. data/lib/selenium/webdriver/devtools/v87/inspector.rb +57 -0
  199. data/lib/selenium/webdriver/devtools/v87/io.rb +61 -0
  200. data/lib/selenium/webdriver/devtools/v87/layer_tree.rb +97 -0
  201. data/lib/selenium/webdriver/devtools/v87/log.rb +68 -0
  202. data/lib/selenium/webdriver/devtools/v87/media.rb +59 -0
  203. data/lib/selenium/webdriver/devtools/v87/memory.rb +88 -0
  204. data/lib/selenium/webdriver/devtools/v87/network.rb +247 -0
  205. data/lib/selenium/webdriver/devtools/v87/overlay.rb +183 -0
  206. data/lib/selenium/webdriver/devtools/v87/page.rb +376 -0
  207. data/lib/selenium/webdriver/devtools/v87/performance.rb +65 -0
  208. data/lib/selenium/webdriver/devtools/v87/profiler.rb +125 -0
  209. data/lib/selenium/webdriver/devtools/v87/runtime.rb +196 -0
  210. data/lib/selenium/webdriver/devtools/v87/schema.rb +48 -0
  211. data/lib/selenium/webdriver/devtools/v87/security.rb +73 -0
  212. data/lib/selenium/webdriver/devtools/v87/service_worker.rb +118 -0
  213. data/lib/selenium/webdriver/devtools/v87/storage.rb +97 -0
  214. data/lib/selenium/webdriver/devtools/v87/system_info.rb +52 -0
  215. data/lib/selenium/webdriver/devtools/v87/target.rb +145 -0
  216. data/lib/selenium/webdriver/devtools/v87/tethering.rb +57 -0
  217. data/lib/selenium/webdriver/devtools/v87/tracing.rb +78 -0
  218. data/lib/selenium/webdriver/devtools/v87/web_audio.rb +72 -0
  219. data/lib/selenium/webdriver/devtools/v87/web_authn.rb +102 -0
  220. data/lib/selenium/webdriver/edge.rb +29 -9
  221. data/lib/selenium/webdriver/edge_chrome/bridge.rb +37 -0
  222. data/lib/selenium/webdriver/edge_chrome/driver.rb +48 -0
  223. data/lib/selenium/webdriver/edge_chrome/options.rb +37 -0
  224. data/lib/selenium/webdriver/edge_chrome/profile.rb +33 -0
  225. data/lib/selenium/webdriver/edge_chrome/service.rb +36 -0
  226. data/lib/selenium/webdriver/{edge → edge_html}/driver.rb +3 -35
  227. data/lib/selenium/webdriver/{edge → edge_html}/options.rb +26 -22
  228. data/lib/selenium/webdriver/{edge → edge_html}/service.rb +2 -6
  229. data/lib/selenium/webdriver/firefox.rb +18 -15
  230. data/lib/selenium/webdriver/firefox/bridge.rb +1 -1
  231. data/lib/selenium/webdriver/firefox/driver.rb +2 -31
  232. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  233. data/lib/selenium/webdriver/firefox/options.rb +47 -52
  234. data/lib/selenium/webdriver/firefox/profile.rb +7 -78
  235. data/lib/selenium/webdriver/firefox/service.rb +0 -4
  236. data/lib/selenium/webdriver/ie.rb +8 -7
  237. data/lib/selenium/webdriver/ie/driver.rb +0 -33
  238. data/lib/selenium/webdriver/ie/options.rb +10 -33
  239. data/lib/selenium/webdriver/ie/service.rb +5 -9
  240. data/lib/selenium/webdriver/remote.rb +16 -10
  241. data/lib/selenium/webdriver/remote/bridge.rb +38 -42
  242. data/lib/selenium/webdriver/remote/capabilities.rb +25 -7
  243. data/lib/selenium/webdriver/remote/driver.rb +6 -13
  244. data/lib/selenium/webdriver/remote/http/default.rb +10 -6
  245. data/lib/selenium/webdriver/remote/http/persistent.rb +5 -6
  246. data/lib/selenium/webdriver/safari.rb +16 -8
  247. data/lib/selenium/webdriver/safari/bridge.rb +4 -4
  248. data/lib/selenium/webdriver/safari/driver.rb +3 -30
  249. data/lib/selenium/webdriver/safari/options.rb +18 -19
  250. data/lib/selenium/webdriver/safari/service.rb +0 -4
  251. data/lib/selenium/webdriver/support.rb +1 -0
  252. data/lib/selenium/webdriver/support/color.rb +2 -2
  253. data/lib/selenium/webdriver/support/event_firing_bridge.rb +1 -1
  254. data/lib/selenium/webdriver/support/relative_locator.rb +51 -0
  255. data/lib/selenium/webdriver/version.rb +1 -1
  256. data/selenium-webdriver.gemspec +7 -6
  257. metadata +225 -21
  258. data/lib/selenium/webdriver/firefox/binary.rb +0 -110
  259. data/lib/selenium/webdriver/firefox/extension/prefs.json +0 -69
@@ -20,19 +20,44 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Chrome
23
- class Options
24
- attr_reader :args, :prefs, :options, :emulation, :extensions, :encoded_extensions
25
- attr_accessor :binary
23
+ class Options < WebDriver::Options
24
+ attr_accessor :profile
26
25
 
27
26
  KEY = 'goog:chromeOptions'
27
+ BROWSER = 'chrome'
28
+
29
+ # see: http://chromedriver.chromium.org/capabilities
30
+ CAPABILITIES = {args: 'args',
31
+ binary: 'binary',
32
+ extensions: 'extensions',
33
+ local_state: 'localState',
34
+ prefs: 'prefs',
35
+ detach: 'detach',
36
+ debugger_address: 'debuggerAddress',
37
+ exclude_switches: 'excludeSwitches',
38
+ minidump_path: 'minidumpPath',
39
+ emulation: 'mobileEmulation',
40
+ perf_logging_prefs: 'perfLoggingPrefs',
41
+ window_types: 'windowTypes'}.freeze
42
+
43
+ CAPABILITIES.each_key do |key|
44
+ define_method key do
45
+ @options[key]
46
+ end
47
+
48
+ define_method "#{key}=" do |value|
49
+ @options[key] = value
50
+ end
51
+ end
28
52
 
29
- #
30
53
  # Create a new Options instance.
31
54
  #
32
55
  # @example
33
56
  # options = Selenium::WebDriver::Chrome::Options.new(args: ['start-maximized', 'user-data-dir=/tmp/temp_profile'])
34
57
  # driver = Selenium::WebDriver.for(:chrome, options: options)
35
58
  #
59
+ # @param [Profile] :profile An instance of a Chrome::Profile Class
60
+ # @param [Array] :encoded_extensions List of extensions that do not need to be Base64 encoded
36
61
  # @param [Hash] opts the pre-defined options to create the Chrome::Options with
37
62
  # @option opts [Array<String>] :args List of command-line arguments to use when starting Chrome
38
63
  # @option opts [String] :binary Path to the Chrome executable to use
@@ -40,16 +65,21 @@ module Selenium
40
65
  # @option opts [Array<String>] :extensions A list of paths to (.crx) Chrome extensions to install on startup
41
66
  # @option opts [Hash] :options A hash for raw options
42
67
  # @option opts [Hash] :emulation A hash for raw emulation options
68
+ # @option opts [Hash] :local_state A hash for the Local State file in the user data folder
69
+ # @option opts [Boolean] :detach whether browser is closed when the driver is sent the quit command
70
+ # @option opts [String] :debugger_address address of a Chrome debugger server to connect to
71
+ # @option opts [Array<String>] :exclude_switches command line switches to exclude
72
+ # @option opts [String] :minidump_path Directory to store Chrome minidumps (linux only)
73
+ # @option opts [Hash] :perf_logging_prefs A hash for performance logging preferences
74
+ # @option opts [Array<String>] :window_types A list of window types to appear in the list of window handles
43
75
  #
44
76
 
45
- def initialize(**opts)
46
- @args = Set.new(opts.delete(:args) || [])
47
- @binary = opts.delete(:binary) || Chrome.path
48
- @prefs = opts.delete(:prefs) || {}
49
- @extensions = opts.delete(:extensions) || []
50
- @options = opts.delete(:options) || {}
51
- @emulation = opts.delete(:emulation) || {}
52
- @encoded_extensions = []
77
+ def initialize(profile: nil, encoded_extensions: nil, **opts)
78
+ super(**opts)
79
+
80
+ @profile = profile
81
+ @options[:encoded_extensions] = encoded_extensions if encoded_extensions
82
+ @options[:extensions]&.each(&method(:validate_extension))
53
83
  end
54
84
 
55
85
  #
@@ -63,10 +93,9 @@ module Selenium
63
93
  #
64
94
 
65
95
  def add_extension(path)
66
- raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
67
- raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx'
68
-
69
- @extensions << path
96
+ validate_extension(path)
97
+ @options[:extensions] ||= []
98
+ @options[:extensions] << path
70
99
  end
71
100
 
72
101
  #
@@ -80,8 +109,10 @@ module Selenium
80
109
  #
81
110
 
82
111
  def add_encoded_extension(encoded)
83
- @encoded_extensions << encoded
112
+ @options[:encoded_extensions] ||= []
113
+ @options[:encoded_extensions] << encoded
84
114
  end
115
+ alias_method :encoded_extension=, :add_encoded_extension
85
116
 
86
117
  #
87
118
  # Add a command-line argument to use when starting Chrome.
@@ -94,22 +125,8 @@ module Selenium
94
125
  #
95
126
 
96
127
  def add_argument(arg)
97
- @args << arg
98
- end
99
-
100
- #
101
- # Add a new option not yet handled by bindings.
102
- #
103
- # @example Leave Chrome open when chromedriver is killed
104
- # options = Selenium::WebDriver::Chrome::Options.new
105
- # options.add_option(:detach, true)
106
- #
107
- # @param [String, Symbol] name Name of the option
108
- # @param [Boolean, String, Integer] value Value of the option
109
- #
110
-
111
- def add_option(name, value)
112
- @options[name] = value
128
+ @options[:args] ||= []
129
+ @options[:args] << arg
113
130
  end
114
131
 
115
132
  #
@@ -124,7 +141,8 @@ module Selenium
124
141
  #
125
142
 
126
143
  def add_preference(name, value)
127
- prefs[name] = value
144
+ @options[:prefs] ||= {}
145
+ @options[:prefs][name] = value
128
146
  end
129
147
 
130
148
  #
@@ -140,7 +158,9 @@ module Selenium
140
158
  end
141
159
 
142
160
  #
143
- # Add an emulation device name
161
+ # Add emulation device information
162
+ #
163
+ # see: http://chromedriver.chromium.org/mobile-emulation
144
164
  #
145
165
  # @example Start Chrome in mobile emulation mode by device name
146
166
  # options = Selenium::WebDriver::Chrome::Options.new
@@ -150,35 +170,55 @@ module Selenium
150
170
  # options = Selenium::WebDriver::Chrome::Options.new
151
171
  # options.add_emulation(device_metrics: {width: 400, height: 800, pixelRatio: 1, touch: true})
152
172
  #
153
- # @param [String] device_name Name of the device or a hash containing width, height, pixelRatio, touch
154
- # @param [Hash] device_metrics Hash containing width, height, pixelRatio, touch
155
- # @param [String] user_agent Full user agent
173
+ # @param [Hash] opts the pre-defined options for adding mobile emulation values
174
+ # @option opts [String] :device_name A valid device name from the Chrome DevTools Emulation panel
175
+ # @option opts [Hash] :device_metrics Hash containing width, height, pixelRatio, touch
176
+ # @option opts [String] :user_agent Full user agent
156
177
  #
157
178
 
158
- def add_emulation(device_name: nil, device_metrics: nil, user_agent: nil)
159
- @emulation[:deviceName] = device_name if device_name
160
- @emulation[:deviceMetrics] = device_metrics if device_metrics
161
- @emulation[:userAgent] = user_agent if user_agent
179
+ def add_emulation(**opts)
180
+ @options[:emulation] = opts
162
181
  end
163
182
 
164
- #
165
- # @api private
166
- #
183
+ private
167
184
 
168
- def as_json(*)
169
- extensions = @extensions.map do |crx_path|
170
- File.open(crx_path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
171
- end
172
- extensions.concat(@encoded_extensions)
185
+ def process_browser_options(browser_options)
186
+ options = browser_options[KEY]
187
+ options['binary'] ||= binary_path if binary_path
188
+ (options['args'] || []) << "--user-data-dir=#{@profile.directory}" if @profile
189
+ merge_extensions(options)
190
+ end
191
+
192
+ def merge_extensions(browser_options)
193
+ extensions = browser_options['extensions'] || []
194
+ encoded_extensions = browser_options.delete(:encoded_extensions) || []
195
+
196
+ browser_options['extensions'] = extensions.map(&method(:encode_extension)) + encoded_extensions
197
+ browser_options.delete('extensions') if browser_options['extensions'].empty?
198
+ end
173
199
 
174
- opts = @options
175
- opts[:binary] = @binary if @binary
176
- opts[:args] = @args.to_a if @args.any?
177
- opts[:extensions] = extensions if extensions.any?
178
- opts[:mobileEmulation] = @emulation unless @emulation.empty?
179
- opts[:prefs] = @prefs unless @prefs.empty?
200
+ def binary_path
201
+ Chrome.path
202
+ end
203
+
204
+ def encode_extension(path)
205
+ File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
206
+ end
207
+
208
+ def validate_extension(path)
209
+ raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)
210
+ raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx'
211
+ end
180
212
 
181
- {KEY => opts}
213
+ def generate_as_json(value, camelize_keys: true)
214
+ if value.is_a?(Hash)
215
+ value.each_with_object({}) do |(key, val), hash|
216
+ key = convert_json_key(key, camelize: camelize_keys)
217
+ hash[key] = generate_as_json(val, camelize_keys: key != 'prefs')
218
+ end
219
+ else
220
+ super
221
+ end
182
222
  end
183
223
  end # Options
184
224
  end # Chrome
@@ -48,7 +48,7 @@ module Selenium
48
48
  #
49
49
  # Set a preference in the profile.
50
50
  #
51
- # See https://src.chromium.org/svn/trunk/src/chrome/common/pref_names.cc
51
+ # See https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc
52
52
  #
53
53
 
54
54
  def []=(key, value)
@@ -77,8 +77,8 @@ module Selenium
77
77
 
78
78
  extensions.concat(@encoded_extensions)
79
79
 
80
- opts = {directory: directory || layout_on_disk}
81
- opts[:extensions] = extensions if extensions.any?
80
+ opts = {'directory' => directory || layout_on_disk}
81
+ opts['extensions'] = extensions if extensions.any?
82
82
  opts
83
83
  end
84
84
 
@@ -20,10 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Chrome
23
- #
24
- # @api private
25
- #
26
-
27
23
  class Service < WebDriver::Service
28
24
  DEFAULT_PORT = 9515
29
25
  EXECUTABLE = 'chromedriver'
@@ -23,6 +23,7 @@ require 'selenium/webdriver/common/proxy'
23
23
  require 'selenium/webdriver/common/log_entry'
24
24
  require 'selenium/webdriver/common/file_reaper'
25
25
  require 'selenium/webdriver/common/service'
26
+ require 'selenium/webdriver/common/service_manager'
26
27
  require 'selenium/webdriver/common/socket_lock'
27
28
  require 'selenium/webdriver/common/socket_poller'
28
29
  require 'selenium/webdriver/common/port_prober'
@@ -49,7 +50,6 @@ require 'selenium/webdriver/common/action_builder'
49
50
  require 'selenium/webdriver/common/html5/shared_web_storage'
50
51
  require 'selenium/webdriver/common/html5/local_storage'
51
52
  require 'selenium/webdriver/common/html5/session_storage'
52
- require 'selenium/webdriver/common/driver_extensions/takes_screenshot'
53
53
  require 'selenium/webdriver/common/driver_extensions/rotatable'
54
54
  require 'selenium/webdriver/common/driver_extensions/has_web_storage'
55
55
  require 'selenium/webdriver/common/driver_extensions/downloads_files'
@@ -62,7 +62,12 @@ require 'selenium/webdriver/common/driver_extensions/has_permissions'
62
62
  require 'selenium/webdriver/common/driver_extensions/has_debugger'
63
63
  require 'selenium/webdriver/common/driver_extensions/uploads_files'
64
64
  require 'selenium/webdriver/common/driver_extensions/has_addons'
65
+ require 'selenium/webdriver/common/driver_extensions/has_devtools'
66
+ require 'selenium/webdriver/common/driver_extensions/has_authentication'
67
+ require 'selenium/webdriver/common/driver_extensions/has_log_events'
65
68
  require 'selenium/webdriver/common/keys'
66
69
  require 'selenium/webdriver/common/profile_helper'
70
+ require 'selenium/webdriver/common/options'
71
+ require 'selenium/webdriver/common/takes_screenshot'
67
72
  require 'selenium/webdriver/common/driver'
68
73
  require 'selenium/webdriver/common/element'
@@ -30,6 +30,7 @@ module Selenium
30
30
 
31
31
  class Driver
32
32
  include SearchContext
33
+ include TakesScreenshot
33
34
 
34
35
  class << self
35
36
  #
@@ -43,17 +44,21 @@ module Selenium
43
44
  def for(browser, opts = {})
44
45
  case browser
45
46
  when :chrome
46
- Chrome::Driver.new(opts)
47
+ Chrome::Driver.new(**opts)
47
48
  when :internet_explorer, :ie
48
- IE::Driver.new(opts)
49
+ IE::Driver.new(**opts)
49
50
  when :safari
50
- Safari::Driver.new(opts)
51
+ Safari::Driver.new(**opts)
51
52
  when :firefox, :ff
52
- Firefox::Driver.new(opts)
53
+ Firefox::Driver.new(**opts)
53
54
  when :edge
54
- Edge::Driver.new(opts)
55
+ Edge::Driver.new(**opts)
56
+ when :edge_chrome
57
+ EdgeChrome::Driver.new(**opts)
58
+ when :edge_html
59
+ EdgeHtml::Driver.new(**opts)
55
60
  when :remote
56
- Remote::Driver.new(opts)
61
+ Remote::Driver.new(**opts)
57
62
  else
58
63
  raise ArgumentError, "unknown driver: #{browser.inspect}"
59
64
  end
@@ -67,9 +72,10 @@ module Selenium
67
72
  # @api private
68
73
  #
69
74
 
70
- def initialize(bridge, listener: nil)
71
- @bridge = bridge
72
- @bridge = Support::EventFiringBridge.new(bridge, listener) if listener
75
+ def initialize(bridge: nil, listener: nil, **opts)
76
+ @service = nil
77
+ bridge ||= create_bridge(**opts)
78
+ @bridge = listener ? Support::EventFiringBridge.new(bridge, listener) : bridge
73
79
  end
74
80
 
75
81
  def inspect
@@ -164,6 +170,8 @@ module Selenium
164
170
 
165
171
  def quit
166
172
  bridge.quit
173
+ ensure
174
+ @service&.stop
167
175
  end
168
176
 
169
177
  #
@@ -269,7 +277,7 @@ module Selenium
269
277
  end
270
278
 
271
279
  def browser
272
- bridge.browser
280
+ bridge&.browser
273
281
  end
274
282
 
275
283
  def capabilities
@@ -287,20 +295,76 @@ module Selenium
287
295
 
288
296
  attr_reader :bridge
289
297
 
298
+ def create_bridge(**opts)
299
+ opts[:url] ||= service_url(opts)
300
+ caps = opts.delete(:capabilities)
301
+ # Note: This is deprecated
302
+ cap_array = caps.is_a?(Hash) ? [caps] : Array(caps)
303
+
304
+ desired_capabilities = opts.delete(:desired_capabilities)
305
+ if desired_capabilities
306
+ WebDriver.logger.deprecate(':desired_capabilities as a parameter for driver initialization',
307
+ ':capabilities with an Array value of capabilities/options if necessary',
308
+ id: :desired_capabilities)
309
+ desired_capabilities = Remote::Capabilities.new(desired_capabilities) if desired_capabilities.is_a?(Hash)
310
+ cap_array << desired_capabilities
311
+ end
312
+
313
+ options = opts.delete(:options)
314
+ if options
315
+ WebDriver.logger.deprecate(':options as a parameter for driver initialization',
316
+ ':capabilities with an Array of value capabilities/options if necessary',
317
+ id: :browser_options)
318
+ cap_array << options
319
+ end
320
+
321
+ capabilities = generate_capabilities(cap_array)
322
+
323
+ bridge_opts = {http_client: opts.delete(:http_client), url: opts.delete(:url)}
324
+ raise ArgumentError, "Unable to create a driver with parameters: #{opts}" unless opts.empty?
325
+
326
+ bridge = (respond_to?(:bridge_class) ? bridge_class : Remote::Bridge).new(**bridge_opts)
327
+
328
+ bridge.create_session(capabilities)
329
+ bridge
330
+ end
331
+
332
+ def generate_capabilities(cap_array)
333
+ cap_array.map { |cap|
334
+ if cap.is_a? Symbol
335
+ cap = Remote::Capabilities.send(cap)
336
+ elsif cap.is_a? Hash
337
+ WebDriver.logger.deprecate("passing a Hash value to :capabilities",
338
+ 'Capabilities instance initialized with the Hash, or build values with Options class',
339
+ id: :capabilities_hash)
340
+ cap = Remote::Capabilities.new(cap)
341
+ elsif !cap.respond_to? :as_json
342
+ msg = ":capabilities parameter only accepts objects responding to #as_json which #{cap.class} does not"
343
+ raise ArgumentError, msg
344
+ end
345
+ cap&.as_json
346
+ }.inject(:merge) || Remote::Capabilities.send(browser || :new)
347
+ end
348
+
290
349
  def service_url(opts)
291
- @service = opts.delete(:service)
350
+ service_config = opts.delete(:service)
292
351
  %i[driver_opts driver_path port].each do |key|
293
352
  next unless opts.key? key
294
353
 
295
- WebDriver.logger.deprecate(":#{key}", ':service with an instance of Selenium::WebDriver::Service')
354
+ WebDriver.logger.deprecate(":#{key}", ':service with an instance of Selenium::WebDriver::Service',
355
+ id: "service_#{key}".to_sym)
296
356
  end
297
- @service ||= Service.send(browser,
298
- args: opts.delete(:driver_opts),
299
- path: opts.delete(:driver_path),
300
- port: opts.delete(:port))
301
- @service.start
357
+ service_config ||= Service.send(browser,
358
+ args: opts.delete(:driver_opts),
359
+ path: opts.delete(:driver_path),
360
+ port: opts.delete(:port))
361
+ @service = service_config.launch
302
362
  @service.uri
303
363
  end
364
+
365
+ def screenshot
366
+ bridge.screenshot
367
+ end
304
368
  end # Driver
305
369
  end # WebDriver
306
370
  end # Selenium
@@ -0,0 +1,89 @@
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 HasAuthentication
24
+
25
+ #
26
+ # Registers basic authentication handler which is automatically
27
+ # used whenever browser gets an authentication required response.
28
+ # This currently relies on DevTools so is only supported in
29
+ # Chromium browsers.
30
+ #
31
+ # @example Authenticate any request
32
+ # driver.register(username: 'admin', password: '123456')
33
+ #
34
+ # @example Authenticate based on URL
35
+ # driver.register(username: 'admin1', password: '123456', uri: /mysite1\.com/)
36
+ # driver.register(username: 'admin2', password: '123456', uri: /mysite2\.com/)
37
+ #
38
+ # @param [String] username
39
+ # @param [String] password
40
+ # @param [Regexp] uri to associate the credentials with
41
+ #
42
+
43
+ def register(username:, password:, uri: //)
44
+ auth_handlers << {username: username, password: password, uri: uri}
45
+
46
+ devtools.network.set_cache_disabled(cache_disabled: true)
47
+ devtools.fetch.on(:auth_required) do |params|
48
+ authenticate(params['requestId'], params.dig('request', 'url'))
49
+ end
50
+ devtools.fetch.on(:request_paused) do |params|
51
+ devtools.fetch.continue_request(request_id: params['requestId'])
52
+ end
53
+ devtools.fetch.enable(handle_auth_requests: true)
54
+ end
55
+
56
+ private
57
+
58
+ def auth_handlers
59
+ @auth_handlers ||= []
60
+ end
61
+
62
+ def authenticate(request_id, url)
63
+ credentials = auth_handlers.find do |handler|
64
+ url.match?(handler[:uri])
65
+ end
66
+
67
+ if credentials
68
+ devtools.fetch.continue_with_auth(
69
+ request_id: request_id,
70
+ auth_challenge_response: {
71
+ response: 'ProvideCredentials',
72
+ username: credentials[:username],
73
+ password: credentials[:password]
74
+ }
75
+ )
76
+ else
77
+ devtools.fetch.continue_with_auth(
78
+ request_id: request_id,
79
+ auth_challenge_response: {
80
+ response: 'CancelAuth'
81
+ }
82
+ )
83
+ end
84
+ end
85
+
86
+ end # HasAuthentication
87
+ end # DriverExtensions
88
+ end # WebDriver
89
+ end # Selenium