selenium-webdriver 4.7.1 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +29 -0
  3. data/LICENSE +1 -1
  4. data/NOTICE +1 -1
  5. data/lib/selenium/server.rb +1 -0
  6. data/lib/selenium/webdriver/atoms.rb +2 -3
  7. data/lib/selenium/webdriver/bidi/browsing_context.rb +88 -0
  8. data/lib/selenium/webdriver/bidi/browsing_context_info.rb +35 -0
  9. data/lib/selenium/webdriver/bidi/log/base_log_entry.rb +35 -0
  10. data/lib/selenium/webdriver/bidi/log/console_log_entry.rb +35 -0
  11. data/lib/selenium/webdriver/bidi/log/generic_log_entry.rb +33 -0
  12. data/lib/selenium/webdriver/bidi/log/javascript_log_entry.rb +33 -0
  13. data/lib/selenium/webdriver/bidi/log_inspector.rb +140 -0
  14. data/lib/selenium/webdriver/bidi/navigate_result.rb +33 -0
  15. data/lib/selenium/webdriver/bidi/session.rb +13 -0
  16. data/lib/selenium/webdriver/bidi.rb +2 -1
  17. data/lib/selenium/webdriver/chrome/driver.rb +19 -29
  18. data/lib/selenium/webdriver/chrome/features.rb +5 -72
  19. data/lib/selenium/webdriver/chrome/options.rb +3 -237
  20. data/lib/selenium/webdriver/chrome/profile.rb +3 -83
  21. data/lib/selenium/webdriver/chrome/service.rb +3 -18
  22. data/lib/selenium/webdriver/chromium/driver.rb +61 -0
  23. data/lib/selenium/webdriver/chromium/features.rb +103 -0
  24. data/lib/selenium/webdriver/chromium/options.rb +261 -0
  25. data/lib/selenium/webdriver/chromium/profile.rb +113 -0
  26. data/lib/selenium/webdriver/chromium/service.rb +42 -0
  27. data/lib/selenium/webdriver/chromium.rb +32 -0
  28. data/lib/selenium/webdriver/common/action_builder.rb +11 -48
  29. data/lib/selenium/webdriver/common/child_process.rb +0 -2
  30. data/lib/selenium/webdriver/common/driver.rb +34 -25
  31. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +0 -2
  32. data/lib/selenium/webdriver/common/driver_extensions/full_page_screenshot.rb +0 -1
  33. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +0 -2
  34. data/lib/selenium/webdriver/common/driver_extensions/has_apple_permissions.rb +0 -2
  35. data/lib/selenium/webdriver/common/driver_extensions/has_authentication.rb +0 -2
  36. data/lib/selenium/webdriver/common/driver_extensions/has_bidi.rb +0 -2
  37. data/lib/selenium/webdriver/common/driver_extensions/has_casting.rb +0 -1
  38. data/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb +0 -2
  39. data/lib/selenium/webdriver/common/driver_extensions/has_context.rb +0 -2
  40. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +0 -2
  41. data/lib/selenium/webdriver/common/driver_extensions/has_devtools.rb +0 -2
  42. data/lib/selenium/webdriver/common/driver_extensions/has_launching.rb +0 -2
  43. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +1 -2
  44. data/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb +0 -1
  45. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +0 -2
  46. data/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb +0 -2
  47. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +0 -2
  48. data/lib/selenium/webdriver/common/driver_extensions/has_pinned_scripts.rb +0 -2
  49. data/lib/selenium/webdriver/common/element.rb +6 -6
  50. data/lib/selenium/webdriver/common/error.rb +0 -2
  51. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +2 -2
  52. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +3 -3
  53. data/lib/selenium/webdriver/common/interactions/pointer_move.rb +2 -2
  54. data/lib/selenium/webdriver/common/interactions/scroll.rb +7 -5
  55. data/lib/selenium/webdriver/common/logger.rb +10 -2
  56. data/lib/selenium/webdriver/common/options.rb +30 -8
  57. data/lib/selenium/webdriver/common/profile_helper.rb +1 -1
  58. data/lib/selenium/webdriver/common/proxy.rb +1 -1
  59. data/lib/selenium/webdriver/common/selenium_manager.rb +10 -12
  60. data/lib/selenium/webdriver/common/service.rb +9 -5
  61. data/lib/selenium/webdriver/common/service_manager.rb +1 -1
  62. data/lib/selenium/webdriver/common/shadow_root.rb +1 -2
  63. data/lib/selenium/webdriver/common/socket_lock.rb +1 -0
  64. data/lib/selenium/webdriver/common/takes_screenshot.rb +2 -3
  65. data/lib/selenium/webdriver/common/target_locator.rb +2 -3
  66. data/lib/selenium/webdriver/common/timeouts.rb +2 -2
  67. data/lib/selenium/webdriver/common/virtual_authenticator/credential.rb +8 -6
  68. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator.rb +0 -1
  69. data/lib/selenium/webdriver/common/virtual_authenticator/virtual_authenticator_options.rb +16 -16
  70. data/lib/selenium/webdriver/common/websocket_connection.rb +1 -2
  71. data/lib/selenium/webdriver/devtools/console_event.rb +0 -2
  72. data/lib/selenium/webdriver/devtools/exception_event.rb +0 -2
  73. data/lib/selenium/webdriver/devtools/mutation_event.rb +0 -2
  74. data/lib/selenium/webdriver/devtools/network_interceptor.rb +3 -6
  75. data/lib/selenium/webdriver/devtools/pinned_script.rb +0 -2
  76. data/lib/selenium/webdriver/devtools/request.rb +0 -2
  77. data/lib/selenium/webdriver/devtools/response.rb +0 -2
  78. data/lib/selenium/webdriver/devtools.rb +0 -1
  79. data/lib/selenium/webdriver/edge/driver.rb +20 -3
  80. data/lib/selenium/webdriver/edge/features.rb +3 -4
  81. data/lib/selenium/webdriver/edge/options.rb +3 -5
  82. data/lib/selenium/webdriver/edge/profile.rb +2 -2
  83. data/lib/selenium/webdriver/edge/service.rb +2 -2
  84. data/lib/selenium/webdriver/firefox/driver.rb +19 -2
  85. data/lib/selenium/webdriver/firefox/features.rb +0 -1
  86. data/lib/selenium/webdriver/firefox/options.rb +4 -1
  87. data/lib/selenium/webdriver/firefox/profile.rb +6 -6
  88. data/lib/selenium/webdriver/firefox/service.rb +0 -1
  89. data/lib/selenium/webdriver/ie/driver.rb +20 -1
  90. data/lib/selenium/webdriver/ie/service.rb +1 -2
  91. data/lib/selenium/webdriver/remote/bridge.rb +8 -15
  92. data/lib/selenium/webdriver/remote/capabilities.rb +34 -12
  93. data/lib/selenium/webdriver/remote/commands.rb +0 -2
  94. data/lib/selenium/webdriver/remote/driver.rb +13 -13
  95. data/lib/selenium/webdriver/remote/http/curb.rb +0 -2
  96. data/lib/selenium/webdriver/remote/http/default.rb +1 -0
  97. data/lib/selenium/webdriver/remote/response.rb +0 -1
  98. data/lib/selenium/webdriver/safari/driver.rb +20 -1
  99. data/lib/selenium/webdriver/safari/features.rb +0 -2
  100. data/lib/selenium/webdriver/safari/options.rb +5 -1
  101. data/lib/selenium/webdriver/safari.rb +1 -1
  102. data/lib/selenium/webdriver/support/color.rb +15 -15
  103. data/lib/selenium/webdriver/support/guards/guard.rb +0 -2
  104. data/lib/selenium/webdriver/support/guards/guard_condition.rb +0 -2
  105. data/lib/selenium/webdriver/support/relative_locator.rb +0 -1
  106. data/lib/selenium/webdriver/version.rb +1 -1
  107. data/lib/selenium/webdriver.rb +3 -3
  108. data/selenium-webdriver.gemspec +3 -5
  109. metadata +25 -41
  110. data/lib/selenium/webdriver/support/cdp_client_generator.rb +0 -108
  111. data/lib/selenium/webdriver/support/nightly_version_generator.rb +0 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 792a45b1e527ca7fadf294d16b603fd1b4b0e34106416e4f655edfeee3bbe579
4
- data.tar.gz: e8eeec7a8d1f1f68c4b53fa6b05ae32b7ad7a6c9c27df2c589167a23d72a78ec
3
+ metadata.gz: cd585c8c3f1d0336fe186c7748cc0b473302c5e63f305804e85944764f518961
4
+ data.tar.gz: ade668c90f35b2624a4e3fe370bead6e7500073c9f1a5fcd6127f08a44c95e30
5
5
  SHA512:
6
- metadata.gz: 70c50740152826fb3d53ceef70b844b9a736051197256fdd0b35a403f6d836cb0cb06e03e0836fc570a55a03d14d01f8c547a2a221e812a0ea1a35ad7a3fff82
7
- data.tar.gz: 7dbec088649c81cb491f707416eeb3280874a6a468305098f50978f2cec7d372aa9bcba8095d80b4971b700f38bb72d3e6ed4664359e28ee5286510b255d22dd
6
+ metadata.gz: 870ccbc8b1b21afdc53ef1853e0ba19eba366ed0e42552ff442496554e6545a5d73c7450f53d0cfc555d6c8e5487a600f7b4391ed8b0ac1202c467153f86c6d9
7
+ data.tar.gz: 16034330349a65c5419cc014239d980e518cf9793d2bc24514686eb1ba35b18c818c7626467299f78bbc2b5eaf7863f61c82904787f2e4e97d50e056cd4fe5f5
data/CHANGES CHANGED
@@ -1,3 +1,32 @@
1
+ 4.8.0 (Unreleased)
2
+ =========================
3
+ Ruby:
4
+ * Allow updating instance variables on service classes
5
+ * Deprecate extract_service_args processing in service classes
6
+ * Fix bug preventing sending nil to #send_keys with Remote Driver
7
+ * Fix bug with IE specific methods not available to IE Driver
8
+ * Created Chromium superclass for Chrome and Edge
9
+ * Deprecated platform and version setters/getters in Capabilities class
10
+ * Revamped driver constructor logic
11
+ * Fix bug preventing using Safari Technology Preview when using SafariOptions
12
+ * Fix bug preventing more than one driver type to access Selenium Manager
13
+ * Defaults to using Options instead of Capabilities
14
+ * Make Options classes more strict for allowed arguments and types
15
+ * Removed previously deprecated actions class parameters
16
+ * Removed Location struct
17
+ * Add comment with name of large JS executions (#11038)
18
+ * update logger with link on how to use it (#11478)
19
+ * Deprecate #add_option for Option classes in favor of constructor and attr_accessor
20
+ * Deprecate all unrecognized capabilities for Options classes
21
+ * Deprecate support for :capabilities for local drivers
22
+ * Deprecate browser class methods for Capabilities
23
+ * Deprecate #headless! for Chrome and Firefox
24
+
25
+ BiDi:
26
+ * Released selenium-devtools 0.109.0 (supports CDP v85, v107, v108, v109)
27
+ * Add LogInspector (#11368)
28
+ * Add Browsing context commands (#11446)
29
+
1
30
  4.7.1 (2022-12-02)
2
31
  =========================
3
32
  Ruby:
data/LICENSE CHANGED
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright 2022 Software Freedom Conservancy (SFC)
190
+ Copyright 2023 Software Freedom Conservancy (SFC)
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
data/NOTICE CHANGED
@@ -1,2 +1,2 @@
1
- Copyright 2011-2022 Software Freedom Conservancy
1
+ Copyright 2011-2023 Software Freedom Conservancy
2
2
  Copyright 2004-2011 Selenium committers
@@ -210,6 +210,7 @@ module Selenium
210
210
  begin
211
211
  Net::HTTP.get(@host, '/selenium-server/driver/?cmd=shutDownSeleniumServer', @port)
212
212
  rescue Errno::ECONNREFUSED
213
+ nil
213
214
  end
214
215
 
215
216
  stop_process if @process
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Atoms
23
-
24
23
  private
25
24
 
26
25
  def read_atom(function)
@@ -28,10 +27,10 @@ module Selenium
28
27
  end
29
28
 
30
29
  def execute_atom(function_name, *arguments)
31
- script = format("return (%<atom>s).apply(null, arguments)", atom: read_atom(function_name))
30
+ script = format("/* #{function_name} */return (%<atom>s).apply(null, arguments)",
31
+ atom: read_atom(function_name))
32
32
  execute_script(script, *arguments)
33
33
  end
34
-
35
34
  end # Atoms
36
35
  end # WebDriver
37
36
  end # Selenium
@@ -0,0 +1,88 @@
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_relative 'navigate_result'
21
+ require_relative 'browsing_context_info'
22
+
23
+ module Selenium
24
+ module WebDriver
25
+ class BiDi
26
+ class BrowsingContext
27
+ attr_accessor :id
28
+
29
+ READINESS_STATE = {
30
+ none: 'none',
31
+ interactive: 'interactive',
32
+ complete: 'complete'
33
+ }.freeze
34
+
35
+ def initialize(driver:, browsing_context_id: nil, type: nil, reference_context: nil)
36
+ unless driver.capabilities.web_socket_url
37
+ raise Error::WebDriverError,
38
+ 'WebDriver instance must support BiDi protocol'
39
+ end
40
+
41
+ unless type.nil? || %i[window tab].include?(type)
42
+ raise ArgumentError,
43
+ "Valid types are :window & :tab. Received: #{type.inspect}"
44
+ end
45
+
46
+ @bidi = driver.bidi
47
+ @id = browsing_context_id.nil? ? create(type, reference_context)['context'] : browsing_context_id
48
+ end
49
+
50
+ def navigate(url:, readiness_state: nil)
51
+ unless readiness_state.nil? || READINESS_STATE.key?(readiness_state)
52
+ raise ArgumentError,
53
+ "Valid readiness states are :none, :interactive & :complete. Received: #{readiness_state.inspect}"
54
+ end
55
+
56
+ navigate_result = @bidi.send_cmd('browsingContext.navigate', context: @id, url: url,
57
+ wait: READINESS_STATE[readiness_state])
58
+
59
+ NavigateResult.new(
60
+ url: navigate_result['url'],
61
+ navigation_id: navigate_result['navigation']
62
+ )
63
+ end
64
+
65
+ def get_tree(max_depth: nil)
66
+ result = @bidi.send_cmd('browsingContext.getTree', root: @id, maxDepth: max_depth).dig('contexts', 0)
67
+
68
+ BrowsingContextInfo.new(
69
+ id: result['context'],
70
+ url: result['url'],
71
+ children: result['children'],
72
+ parent_context: result['parent']
73
+ )
74
+ end
75
+
76
+ def close
77
+ @bidi.send_cmd('browsingContext.close', context: @id)
78
+ end
79
+
80
+ private
81
+
82
+ def create(type, reference_context)
83
+ @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: reference_context)
84
+ end
85
+ end # BrowsingContext
86
+ end # BiDi
87
+ end # WebDriver
88
+ end # Selenium
@@ -0,0 +1,35 @@
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 BiDi
23
+ class BrowsingContextInfo
24
+ attr_accessor :id, :url, :children, :parent_browsing_context
25
+
26
+ def initialize(id:, url:, children:, parent_context:)
27
+ @id = id
28
+ @url = url
29
+ @children = children
30
+ @parent_browsing_context = parent_context
31
+ end
32
+ end # BrowsingContextInfo
33
+ end # BiDi
34
+ end # WebDriver
35
+ end # Selenium
@@ -0,0 +1,35 @@
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 BiDi
23
+ class BaseLogEntry
24
+ attr_accessor :level, :text, :timestamp, :stack_trace
25
+
26
+ def initialize(level:, text:, timestamp:, stack_trace:)
27
+ @level = level
28
+ @text = text
29
+ @timestamp = timestamp
30
+ @stack_trace = stack_trace
31
+ end
32
+ end # BaseLogEntry
33
+ end # BiDi
34
+ end # WebDriver
35
+ end # Selenium
@@ -0,0 +1,35 @@
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 BiDi
23
+ class ConsoleLogEntry < GenericLogEntry
24
+ attr_accessor :method, :realm, :args
25
+
26
+ def initialize(method:, realm:, args:, **opts)
27
+ super(**opts)
28
+ @method = method
29
+ @realm = realm
30
+ @args = args
31
+ end
32
+ end # ConsoleLogEntry
33
+ end # BiDi
34
+ end # WebDriver
35
+ end # Selenium
@@ -0,0 +1,33 @@
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 BiDi
23
+ class GenericLogEntry < BaseLogEntry
24
+ attr_accessor :type
25
+
26
+ def initialize(level:, text:, timestamp:, type:, stack_trace:)
27
+ super(level: level, text: text, timestamp: timestamp, stack_trace: stack_trace)
28
+ @type = type
29
+ end
30
+ end # GenericLogEntry
31
+ end # BiDi
32
+ end # WebDriver
33
+ end # Selenium
@@ -0,0 +1,33 @@
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 BiDi
23
+ class JavascriptLogEntry < GenericLogEntry
24
+ attr_accessor :type
25
+
26
+ def initialize(level:, text:, timestamp:, type:, stack_trace:)
27
+ super(level: level, text: text, timestamp: timestamp, type: type, stack_trace: stack_trace)
28
+ @type = 'javascript'
29
+ end
30
+ end # JavascriptLogEntry
31
+ end # BiDi
32
+ end # WebDriver
33
+ end # Selenium
@@ -0,0 +1,140 @@
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
+ # This file is automatically generated. Any changes will be lost!
21
+
22
+ require_relative 'log/base_log_entry'
23
+ require_relative 'log/generic_log_entry'
24
+ require_relative 'log/console_log_entry'
25
+ require_relative 'log/javascript_log_entry'
26
+
27
+ module Selenium
28
+ module WebDriver
29
+ class BiDi
30
+ class LogInspector
31
+ EVENTS = {
32
+ entry_added: 'entryAdded'
33
+ }.freeze
34
+
35
+ LOG_LEVEL = {
36
+ DEBUG: 'debug',
37
+ ERROR: 'error',
38
+ INFO: 'info',
39
+ WARNING: 'warning'
40
+ }.freeze
41
+
42
+ def initialize(driver, browsing_context_ids = nil)
43
+ unless driver.capabilities.web_socket_url
44
+ raise Error::WebDriverError,
45
+ 'WebDriver instance must support BiDi protocol'
46
+ end
47
+
48
+ @bidi = driver.bidi
49
+ @bidi.session.subscribe('log.entryAdded', browsing_context_ids)
50
+ end
51
+
52
+ def on_console_entry(&block)
53
+ enabled = log_listeners[:console].any?
54
+ log_listeners[:console] << block
55
+ return if enabled
56
+
57
+ on_log do |params|
58
+ type = params['type']
59
+ console_log_events(params) if type.eql?('console')
60
+ end
61
+ end
62
+
63
+ def on_javascript_log(&block)
64
+ enabled = log_listeners[:javascript].any?
65
+ log_listeners[:javascript] << block
66
+ return if enabled
67
+
68
+ on_log do |params|
69
+ type = params['type']
70
+ javascript_log_events(params) if type.eql?('javascript')
71
+ end
72
+ end
73
+
74
+ def on_javascript_exception(&block)
75
+ enabled = log_listeners[:js_exception].any?
76
+ log_listeners[:js_exception] << block
77
+ log_listeners[:javascript] << block
78
+ return if enabled
79
+
80
+ on_log do |params|
81
+ type = params['type']
82
+ level = params['level']
83
+
84
+ javascript_log_events(params) if type.eql?('javascript') && level.eql?(LOG_LEVEL[:ERROR])
85
+ end
86
+ end
87
+
88
+ def on_log(&block)
89
+ on(:entry_added, &block)
90
+ end
91
+
92
+ private
93
+
94
+ def on(event, &block)
95
+ event = EVENTS[event] if event.is_a?(Symbol)
96
+ @bidi.callbacks["log.#{event}"] << block
97
+ end
98
+
99
+ def log_listeners
100
+ @log_listeners ||= Hash.new { |listeners, kind| listeners[kind] = [] }
101
+ end
102
+
103
+ def console_log_events(params)
104
+ event = ConsoleLogEntry.new(
105
+ level: params['level'],
106
+ text: params['text'],
107
+ timestamp: params['timestamp'],
108
+ type: params['type'],
109
+ method: params['method'],
110
+ realm: params['realm'],
111
+ args: params['args'],
112
+ stack_trace: params['stackTrace']
113
+ )
114
+ log_listeners[:console].each do |listener|
115
+ listener.call(event)
116
+ end
117
+ end
118
+
119
+ def javascript_log_events(params)
120
+ event = JavascriptLogEntry.new(
121
+ level: params['level'],
122
+ text: params['text'],
123
+ timestamp: params['timestamp'],
124
+ type: params['type'],
125
+ stack_trace: params['stackTrace']
126
+ )
127
+ log_listeners[:javascript].each do |listener|
128
+ listener.call(event)
129
+ end
130
+
131
+ return unless params['level'].eql?(LOG_LEVEL[:ERROR])
132
+
133
+ log_listeners[:js_exception].each do |listener|
134
+ listener.call(event)
135
+ end
136
+ end
137
+ end # LogInspector
138
+ end # Bidi
139
+ end # WebDriver
140
+ end # Selenium
@@ -0,0 +1,33 @@
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 BiDi
23
+ class NavigateResult
24
+ attr_accessor :url, :navigation_id
25
+
26
+ def initialize(url:, navigation_id:)
27
+ @url = url
28
+ @navigation_id = navigation_id
29
+ end
30
+ end # NavigateResult
31
+ end # BiDi
32
+ end # WebDriver
33
+ end # Selenium
@@ -32,6 +32,19 @@ module Selenium
32
32
  Status.new(status['ready'], status['message'])
33
33
  end
34
34
 
35
+ def subscribe(events, browsing_contexts = nil)
36
+ events_list = Array(events)
37
+ browsing_contexts_list = browsing_contexts.nil? ? nil : Array(browsing_contexts)
38
+
39
+ @bidi.send_cmd('session.subscribe', events: events_list, contexts: browsing_contexts_list)
40
+ end
41
+
42
+ def unsubscribe(events, browsing_contexts = nil)
43
+ events_list = Array(events)
44
+ browsing_contexts_list = browsing_contexts.nil? ? nil : Array(browsing_contexts)
45
+
46
+ @bidi.send_cmd('session.unsubscribe', events: events_list, contexts: browsing_contexts_list)
47
+ end
35
48
  end # Session
36
49
  end # BiDi
37
50
  end # WebDriver
@@ -21,6 +21,8 @@ module Selenium
21
21
  module WebDriver
22
22
  class BiDi
23
23
  autoload :Session, 'selenium/webdriver/bidi/session'
24
+ autoload :LogInspector, 'selenium/webdriver/bidi/log_inspector'
25
+ autoload :BrowsingContext, 'selenium/webdriver/bidi/browsing_context'
24
26
 
25
27
  def initialize(url:)
26
28
  @ws = WebSocketConnection.new(url: url)
@@ -49,7 +51,6 @@ module Selenium
49
51
  def error_message(message)
50
52
  "#{message['error']}: #{message['message']}\n#{message['stacktrace']}"
51
53
  end
52
-
53
54
  end # BiDi
54
55
  end # WebDriver
55
56
  end # Selenium
@@ -17,32 +17,24 @@
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
19
 
20
+ require 'selenium/webdriver/chromium/driver'
21
+
20
22
  module Selenium
21
23
  module WebDriver
22
24
  module Chrome
23
-
24
25
  #
25
26
  # Driver implementation for Chrome.
26
27
  # @api private
27
28
  #
28
29
 
29
- class Driver < WebDriver::Driver
30
- EXTENSIONS = [DriverExtensions::HasCDP,
31
- DriverExtensions::HasBiDi,
32
- DriverExtensions::HasCasting,
33
- DriverExtensions::HasNetworkConditions,
34
- DriverExtensions::HasNetworkInterception,
35
- DriverExtensions::HasWebStorage,
36
- DriverExtensions::HasLaunching,
37
- DriverExtensions::HasLocation,
38
- DriverExtensions::HasPermissions,
39
- DriverExtensions::DownloadsFiles,
40
- DriverExtensions::HasDevTools,
41
- DriverExtensions::HasAuthentication,
42
- DriverExtensions::HasLogs,
43
- DriverExtensions::HasLogEvents,
44
- DriverExtensions::HasPinnedScripts,
45
- DriverExtensions::PrintsPage].freeze
30
+ class Driver < Chromium::Driver
31
+ def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts)
32
+ raise ArgumentError, "Can't initialize #{self.class} with :url" if url
33
+
34
+ caps = process_options(options, capabilities)
35
+ url = service_url(service || Service.chrome)
36
+ super(caps: caps, url: url, **opts)
37
+ end
46
38
 
47
39
  def browser
48
40
  :chrome
@@ -50,21 +42,19 @@ module Selenium
50
42
 
51
43
  private
52
44
 
53
- def devtools_url
54
- uri = URI(devtools_address)
55
- response = Net::HTTP.get(uri.hostname, '/json/version', uri.port)
56
-
57
- JSON.parse(response)['webSocketDebuggerUrl']
58
- end
59
-
60
- def devtools_version
61
- Integer(capabilities.browser_version.split('.').first)
62
- end
63
-
64
45
  def devtools_address
65
46
  "http://#{capabilities['goog:chromeOptions']['debuggerAddress']}"
66
47
  end
67
48
 
49
+ def process_options(options, capabilities)
50
+ if options && !options.is_a?(Options)
51
+ raise ArgumentError, ":options must be an instance of #{Options}"
52
+ elsif options.nil? && capabilities.nil?
53
+ options = Options.new
54
+ end
55
+
56
+ super(options, capabilities)
57
+ end
68
58
  end # Driver
69
59
  end # Chrome
70
60
  end # WebDriver