selenium-webdriver 2.53.3 → 3.142.7

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 (162) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +665 -8
  3. data/Gemfile +2 -0
  4. data/LICENSE +1 -1
  5. data/README.md +2 -3
  6. data/lib/selenium/server.rb +76 -73
  7. data/lib/selenium/webdriver/atoms/getAttribute.js +7 -0
  8. data/lib/selenium/webdriver/atoms/isDisplayed.js +102 -0
  9. data/lib/selenium/webdriver/{phantomjs.rb → atoms.rb} +10 -14
  10. data/lib/selenium/webdriver/chrome/bridge.rb +30 -101
  11. data/lib/selenium/webdriver/chrome/driver.rb +127 -0
  12. data/lib/selenium/webdriver/chrome/options.rb +190 -0
  13. data/lib/selenium/webdriver/chrome/profile.rb +21 -20
  14. data/lib/selenium/webdriver/chrome/service.rb +26 -93
  15. data/lib/selenium/webdriver/chrome.rb +15 -6
  16. data/lib/selenium/webdriver/common/action_builder.rb +52 -58
  17. data/lib/selenium/webdriver/common/alert.rb +7 -15
  18. data/lib/selenium/webdriver/common/bridge_helper.rb +18 -22
  19. data/lib/selenium/webdriver/common/driver.rb +72 -72
  20. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +45 -0
  21. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +50 -0
  22. data/lib/selenium/webdriver/common/driver_extensions/{has_input_devices.rb → has_debugger.rb} +11 -27
  23. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +6 -10
  24. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +51 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +7 -8
  26. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +51 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +2 -4
  28. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +2 -4
  29. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +3 -5
  30. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +2 -5
  31. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +6 -9
  32. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +9 -7
  33. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +3 -8
  34. data/lib/selenium/webdriver/common/element.rb +59 -39
  35. data/lib/selenium/webdriver/common/error.rb +259 -104
  36. data/lib/selenium/webdriver/common/file_reaper.rb +6 -14
  37. data/lib/selenium/webdriver/common/html5/local_storage.rb +8 -10
  38. data/lib/selenium/webdriver/common/html5/session_storage.rb +8 -10
  39. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +8 -16
  40. data/lib/selenium/webdriver/common/interactions/input_device.rb +54 -0
  41. data/lib/selenium/webdriver/common/interactions/interaction.rb +53 -0
  42. data/lib/selenium/webdriver/{safari/browser.rb → common/interactions/interactions.rb} +17 -14
  43. data/lib/selenium/webdriver/common/interactions/key_actions.rb +145 -0
  44. data/lib/selenium/webdriver/common/interactions/key_input.rb +66 -0
  45. data/lib/selenium/webdriver/{android.rb → common/interactions/none_input.rb} +14 -6
  46. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +363 -0
  47. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +139 -0
  48. data/lib/selenium/webdriver/common/keyboard.rb +10 -14
  49. data/lib/selenium/webdriver/common/keys.rb +102 -82
  50. data/lib/selenium/webdriver/common/log_entry.rb +7 -8
  51. data/lib/selenium/webdriver/common/logger.rb +115 -0
  52. data/lib/selenium/webdriver/common/logs.rb +4 -6
  53. data/lib/selenium/webdriver/common/manager.rb +177 -0
  54. data/lib/selenium/webdriver/common/mouse.rb +12 -14
  55. data/lib/selenium/webdriver/common/navigation.rb +4 -6
  56. data/lib/selenium/webdriver/common/options.rb +26 -127
  57. data/lib/selenium/webdriver/common/platform.rb +75 -101
  58. data/lib/selenium/webdriver/common/port_prober.rb +7 -19
  59. data/lib/selenium/webdriver/common/profile_helper.rb +8 -11
  60. data/lib/selenium/webdriver/common/proxy.rb +68 -74
  61. data/lib/selenium/webdriver/common/search_context.rb +28 -37
  62. data/lib/selenium/webdriver/common/service.rb +219 -0
  63. data/lib/selenium/webdriver/common/socket_lock.rb +15 -16
  64. data/lib/selenium/webdriver/common/socket_poller.rb +30 -28
  65. data/lib/selenium/webdriver/common/target_locator.rb +16 -18
  66. data/lib/selenium/webdriver/common/timeouts.rb +6 -8
  67. data/lib/selenium/webdriver/common/touch_action_builder.rb +5 -10
  68. data/lib/selenium/webdriver/common/touch_screen.rb +22 -23
  69. data/lib/selenium/webdriver/common/w3c_action_builder.rb +212 -0
  70. data/lib/selenium/webdriver/common/w3c_manager.rb +45 -0
  71. data/lib/selenium/webdriver/common/wait.rb +17 -16
  72. data/lib/selenium/webdriver/common/window.rb +50 -17
  73. data/lib/selenium/webdriver/common/zipper.rb +9 -13
  74. data/lib/selenium/webdriver/common.rb +21 -7
  75. data/lib/selenium/webdriver/edge/bridge.rb +34 -63
  76. data/lib/selenium/webdriver/edge/driver.rb +66 -0
  77. data/lib/selenium/webdriver/edge/options.rb +80 -0
  78. data/lib/selenium/webdriver/edge/service.rb +23 -95
  79. data/lib/selenium/webdriver/edge.rb +13 -13
  80. data/lib/selenium/webdriver/firefox/binary.rb +45 -60
  81. data/lib/selenium/webdriver/firefox/driver.rb +50 -0
  82. data/lib/selenium/webdriver/firefox/extension/prefs.json +3 -12
  83. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  84. data/lib/selenium/webdriver/firefox/extension.rb +20 -10
  85. data/lib/selenium/webdriver/firefox/launcher.rb +16 -22
  86. data/lib/selenium/webdriver/firefox/legacy/driver.rb +83 -0
  87. data/lib/selenium/webdriver/firefox/marionette/bridge.rb +49 -0
  88. data/lib/selenium/webdriver/firefox/marionette/driver.rb +90 -0
  89. data/lib/selenium/webdriver/firefox/options.rb +162 -0
  90. data/lib/selenium/webdriver/firefox/profile.rb +47 -48
  91. data/lib/selenium/webdriver/firefox/profiles_ini.rb +11 -18
  92. data/lib/selenium/webdriver/firefox/service.rb +24 -95
  93. data/lib/selenium/webdriver/firefox/util.rb +2 -4
  94. data/lib/selenium/webdriver/firefox.rb +27 -12
  95. data/lib/selenium/webdriver/ie/driver.rb +85 -0
  96. data/lib/selenium/webdriver/ie/options.rb +138 -0
  97. data/lib/selenium/webdriver/ie/service.rb +54 -0
  98. data/lib/selenium/webdriver/ie.rb +12 -10
  99. data/lib/selenium/webdriver/remote/bridge.rb +100 -564
  100. data/lib/selenium/webdriver/remote/capabilities.rb +98 -100
  101. data/lib/selenium/webdriver/remote/driver.rb +51 -0
  102. data/lib/selenium/webdriver/remote/http/common.rb +34 -22
  103. data/lib/selenium/webdriver/remote/http/curb.rb +13 -14
  104. data/lib/selenium/webdriver/remote/http/default.rb +62 -43
  105. data/lib/selenium/webdriver/remote/http/persistent.rb +12 -9
  106. data/lib/selenium/webdriver/remote/oss/bridge.rb +594 -0
  107. data/lib/selenium/webdriver/remote/oss/commands.rb +223 -0
  108. data/lib/selenium/webdriver/remote/response.rb +48 -28
  109. data/lib/selenium/webdriver/remote/server_error.rb +3 -5
  110. data/lib/selenium/webdriver/remote/w3c/bridge.rb +605 -0
  111. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +310 -0
  112. data/lib/selenium/webdriver/remote/w3c/commands.rb +157 -0
  113. data/lib/selenium/webdriver/remote.rb +10 -16
  114. data/lib/selenium/webdriver/safari/bridge.rb +17 -101
  115. data/lib/selenium/webdriver/{firefox/w3c_bridge.rb → safari/driver.rb} +27 -25
  116. data/lib/selenium/webdriver/safari/options.rb +29 -31
  117. data/lib/selenium/webdriver/safari/service.rb +38 -0
  118. data/lib/selenium/webdriver/safari.rb +27 -27
  119. data/lib/selenium/webdriver/support/abstract_event_listener.rb +19 -4
  120. data/lib/selenium/webdriver/support/block_event_listener.rb +3 -5
  121. data/lib/selenium/webdriver/support/color.rb +60 -43
  122. data/lib/selenium/webdriver/support/escaper.rb +43 -0
  123. data/lib/selenium/webdriver/support/event_firing_bridge.rb +39 -41
  124. data/lib/selenium/webdriver/support/select.rb +45 -97
  125. data/lib/selenium/webdriver/support.rb +3 -2
  126. data/lib/selenium/webdriver/{iphone.rb → version.rb} +3 -7
  127. data/lib/selenium/webdriver.rb +36 -23
  128. data/lib/selenium-webdriver.rb +2 -2
  129. data/selenium-webdriver.gemspec +42 -29
  130. metadata +331 -262
  131. data/lib/selenium/client/base.rb +0 -151
  132. data/lib/selenium/client/driver.rb +0 -29
  133. data/lib/selenium/client/errors.rb +0 -28
  134. data/lib/selenium/client/extensions.rb +0 -132
  135. data/lib/selenium/client/idiomatic.rb +0 -507
  136. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  137. data/lib/selenium/client/javascript_frameworks/jquery.rb +0 -32
  138. data/lib/selenium/client/javascript_frameworks/prototype.rb +0 -32
  139. data/lib/selenium/client/legacy_driver.rb +0 -1722
  140. data/lib/selenium/client/protocol.rb +0 -123
  141. data/lib/selenium/client/selenium_helper.rb +0 -49
  142. data/lib/selenium/client.rb +0 -57
  143. data/lib/selenium/rake/server_task.rb +0 -176
  144. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  145. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  146. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  147. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  148. data/lib/selenium/webdriver/common/w3c_error.rb +0 -194
  149. data/lib/selenium/webdriver/edge/legacy_support.rb +0 -117
  150. data/lib/selenium/webdriver/firefox/bridge.rb +0 -89
  151. data/lib/selenium/webdriver/ie/bridge.rb +0 -88
  152. data/lib/selenium/webdriver/ie/server.rb +0 -133
  153. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
  154. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -78
  155. data/lib/selenium/webdriver/phantomjs/service.rb +0 -130
  156. data/lib/selenium/webdriver/remote/commands.rb +0 -211
  157. data/lib/selenium/webdriver/remote/w3c_bridge.rb +0 -668
  158. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +0 -236
  159. data/lib/selenium/webdriver/remote/w3c_commands.rb +0 -132
  160. data/lib/selenium/webdriver/safari/resources/client.js +0 -7255
  161. data/lib/selenium/webdriver/safari/server.rb +0 -187
  162. data/lib/selenium-client.rb +0 -21
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -19,48 +19,50 @@
19
19
 
20
20
  module Selenium
21
21
  module WebDriver
22
- module Firefox
22
+ module Safari
23
23
 
24
+ #
25
+ # Driver implementation for Safari.
24
26
  # @api private
25
- class W3CBridge < Remote::W3CBridge
27
+ #
28
+
29
+ class Driver < WebDriver::Driver
30
+ include DriverExtensions::HasDebugger
31
+ include DriverExtensions::HasPermissions
32
+ include DriverExtensions::TakesScreenshot
26
33
 
27
34
  def initialize(opts = {})
28
- caps = opts[:desired_capabilities] ||= Remote::W3CCapabilities.firefox
29
- Binary.path = caps[:firefox_binary] if caps[:firefox_binary]
35
+ opts[:desired_capabilities] = create_capabilities(opts)
30
36
 
31
- @service = Service.default_service(*extract_service_args(opts))
32
- @service.start
33
- opts[:url] = @service.uri
37
+ opts[:url] ||= service_url(opts)
34
38
 
35
- super
36
- end
39
+ listener = opts.delete(:listener)
40
+ @bridge = Remote::Bridge.handshake(**opts)
41
+ @bridge.extend Bridge
37
42
 
38
- def browser
39
- :firefox
43
+ super(@bridge, listener: listener)
40
44
  end
41
45
 
42
- def driver_extensions
43
- [
44
- DriverExtensions::TakesScreenshot,
45
- DriverExtensions::HasInputDevices,
46
- DriverExtensions::HasWebStorage
47
- ]
46
+ def browser
47
+ :safari
48
48
  end
49
49
 
50
50
  def quit
51
51
  super
52
52
  ensure
53
- @service.stop if @service
53
+ @service&.stop
54
54
  end
55
55
 
56
56
  private
57
57
 
58
- def extract_service_args(opts)
59
- service_log_path = opts.delete(:service_log_path)
60
- service_log_path ? ["--log-path=#{service_log_path}"] : []
58
+ def create_capabilities(opts = {})
59
+ caps = opts.delete(:desired_capabilities) { Remote::Capabilities.safari }
60
+ options = opts.delete(:options) { Options.new }
61
+ caps.merge!(options.as_json)
62
+ caps
61
63
  end
62
64
 
63
- end # W3CBridge
64
- end # Firefox
65
+ end # Driver
66
+ end # Safari
65
67
  end # WebDriver
66
68
  end # Selenium
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -21,41 +21,39 @@ module Selenium
21
21
  module WebDriver
22
22
  module Safari
23
23
  class Options
24
- DEFAULT_PORT = 56485
25
-
26
- attr_accessor :port, :data_dir, :skip_extension_installation
27
-
28
- def initialize(opts = {})
29
- extract_options(opts)
30
- end
31
-
32
- def clean_session?
33
- !!@clean_session
24
+ attr_accessor :automatic_inspection, :automatic_profiling
25
+
26
+ #
27
+ # Create a new Options instance for W3C-capable versions of Safari.
28
+ #
29
+ # @example
30
+ # options = Selenium::WebDriver::Safari::Options.new(automatic_inspection: true)
31
+ # driver = Selenium::WebDriver.for :safari, options: options
32
+ #
33
+ # @param [Hash] opts the pre-defined options to create the Safari::Options with
34
+ # @option opts [Boolean] :automatic_inspection Preloads Web Inspector and JavaScript debugger. Default is false
35
+ # @option opts [Boolean] :automatic_profiling Preloads Web Inspector and starts a timeline recording. Default is false
36
+ #
37
+ # @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
38
+ #
39
+
40
+ def initialize(**opts)
41
+ @automatic_inspection = opts.delete(:automatic_inspection) || false
42
+ @automatic_profiling = opts.delete(:automatic_profiling) || false
34
43
  end
35
44
 
36
- def to_capabilities
37
- caps = Remote::Capabilities.safari
38
- caps.merge!('safari.options' => as_json)
45
+ #
46
+ # @api private
47
+ #
39
48
 
40
- caps
41
- end
49
+ def as_json(*)
50
+ opts = {}
42
51
 
43
- def as_json
44
- {
45
- 'port' => port,
46
- 'dataDir' => data_dir,
47
- 'cleanSession' => clean_session?,
48
- }
49
- end
52
+ opts['safari:automaticInspection'] = true if @automatic_inspection
53
+ opts['safari:automaticProfiling'] = true if @automatic_profiling
50
54
 
51
- private
52
-
53
- def extract_options(opts)
54
- @port = Integer(opts[:port] || DEFAULT_PORT)
55
- @data_dir = opts[:custom_data_dir] || opts[:data_dir]
56
- @clean_session = opts[:clean_session]
55
+ opts
57
56
  end
58
-
59
57
  end # Options
60
58
  end # Safari
61
59
  end # WebDriver
@@ -0,0 +1,38 @@
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 Safari
23
+ #
24
+ # @api private
25
+ #
26
+
27
+ class Service < WebDriver::Service
28
+ @default_port = 7050
29
+ @executable = 'safaridriver'
30
+ @missing_text = <<~ERROR
31
+ Unable to find Apple's safaridriver which comes with Safari 10.
32
+ More info at https://webkit.org/blog/6900/webdriver-support-in-safari-10/
33
+ ERROR
34
+ @shutdown_supported = false
35
+ end # Service
36
+ end # Safari
37
+ end # WebDriver
38
+ end # Selenium
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -17,49 +17,49 @@
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
19
 
20
- require 'websocket'
21
- require 'pathname'
20
+ require 'selenium/webdriver/safari/bridge'
21
+ require 'selenium/webdriver/safari/driver'
22
+ require 'selenium/webdriver/safari/options'
22
23
 
23
24
  module Selenium
24
25
  module WebDriver
25
26
  module Safari
26
-
27
27
  class << self
28
+ def technology_preview
29
+ "/Applications/Safari\ Technology\ Preview.app/Contents/MacOS/safaridriver"
30
+ end
31
+
32
+ def technology_preview!
33
+ self.driver_path = technology_preview
34
+ end
35
+
28
36
  def path=(path)
29
37
  Platform.assert_executable(path)
30
38
  @path = path
31
39
  end
32
40
 
33
41
  def path
34
- @path ||= (
35
- path = case Platform.os
36
- when :windows
37
- Platform.find_in_program_files("Safari\\Safari.exe")
38
- when :macosx
39
- "/Applications/Safari.app/Contents/MacOS/Safari"
40
- else
41
- Platform.find_binary("Safari")
42
- end
42
+ @path ||= '/Applications/Safari.app/Contents/MacOS/Safari'
43
+ return @path if File.file?(@path) && File.executable?(@path)
44
+ raise Error::WebDriverError, 'Safari is only supported on Mac' unless Platform.os.mac?
43
45
 
44
- unless File.file?(path) && File.executable?(path)
45
- raise Error::WebDriverError, "unable to find the Safari executable, please set Selenium::WebDriver::Safari.path= or add it to your PATH."
46
- end
46
+ raise Error::WebDriverError, 'Unable to find Safari'
47
+ end
47
48
 
48
- path
49
- )
49
+ def driver_path=(path)
50
+ WebDriver.logger.deprecate 'Selenium::WebDriver::Safari#driver_path=',
51
+ 'Selenium::WebDriver::Safari::Service#driver_path='
52
+ Selenium::WebDriver::Safari::Service.driver_path = path
50
53
  end
51
54
 
52
- def resource_path
53
- @resource_path ||= Pathname.new(File.expand_path("../safari/resources", __FILE__))
55
+ def driver_path
56
+ WebDriver.logger.deprecate 'Selenium::WebDriver::Safari#driver_path',
57
+ 'Selenium::WebDriver::Safari::Service#driver_path'
58
+ Selenium::WebDriver::Safari::Service.driver_path
54
59
  end
55
60
  end
56
-
57
61
  end # Safari
58
62
  end # WebDriver
59
63
  end # Selenium
60
64
 
61
- require 'selenium/webdriver/safari/browser'
62
- require 'selenium/webdriver/safari/server'
63
- require 'selenium/webdriver/safari/options'
64
- require 'selenium/webdriver/safari/bridge'
65
-
65
+ require 'selenium/webdriver/safari/service'
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -20,7 +20,6 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Support
23
-
24
23
  #
25
24
  # Subclass and override methods from this class
26
25
  # to implement your own event listener.
@@ -48,24 +47,40 @@ module Selenium
48
47
 
49
48
  class AbstractEventListener
50
49
  def before_navigate_to(url, driver) end
50
+
51
51
  def after_navigate_to(url, driver) end
52
+
52
53
  def before_navigate_back(driver) end
54
+
53
55
  def after_navigate_back(driver) end
56
+
54
57
  def before_navigate_forward(driver) end
58
+
55
59
  def after_navigate_forward(driver) end
60
+
56
61
  def before_find(by, what, driver) end
62
+
57
63
  def after_find(by, what, driver) end
64
+
58
65
  def before_click(element, driver) end
66
+
59
67
  def after_click(element, driver) end
68
+
60
69
  def before_change_value_of(element, driver) end
70
+
61
71
  def after_change_value_of(element, driver) end
72
+
62
73
  def before_execute_script(script, driver) end
74
+
63
75
  def after_execute_script(script, driver) end
76
+
64
77
  def before_quit(driver) end
78
+
65
79
  def after_quit(driver) end
80
+
66
81
  def before_close(driver) end
67
- def after_close(driver) end
68
82
 
83
+ def after_close(driver) end
69
84
  end # AbstractEventListener
70
85
  end # Support
71
86
  end # WebDriver
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -20,16 +20,14 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Support
23
-
24
23
  class BlockEventListener
25
24
  def initialize(callback)
26
25
  @callback = callback
27
26
  end
28
27
 
29
- def method_missing(meth, *args, &blk)
28
+ def method_missing(meth, *args) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
30
29
  @callback.call meth, *args
31
30
  end
32
-
33
31
  end # BlockEventListener
34
32
  end # Support
35
33
  end # WebDriver
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -21,86 +21,104 @@ module Selenium
21
21
  module WebDriver
22
22
  module Support
23
23
  class Color
24
- RGB_PATTERN = /^\s*rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)\s*$/
25
- RGB_PCT_PATTERN = /^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$/
26
- RGBA_PATTERN = /^\s*rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0\.\d+)\s*\)\s*$/
27
- RGBA_PCT_PATTERN = /^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,\s*(0|1|0\.\d+)\s*\)\s*$/
28
- HEX_PATTERN = /#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})/ # \p{XDigit} or \h only works on Ruby 1.9
29
- HEX3_PATTERN = /#([A-Fa-f0-9])([A-Fa-f0-9])([A-Fa-f0-9])/ # \p{XDigit} or \h only works on Ruby 1.9
30
- HSL_PATTERN = /^\s*hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)\s*$/
31
- HSLA_PATTERN = /^\s*hsla\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*,\s*(0|1|0\.\d+)\s*\)\s*$/
24
+ RGB_PATTERN = %r{^\s*rgb\(\s*(\d{1,3})\s*,
25
+ \s*(\d{1,3})\s*,
26
+ \s*(\d{1,3})\s*\)\s*$}x.freeze
27
+ RGB_PCT_PATTERN = %r{^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
28
+ \s*(\d{1,3}|\d{1,2}\.\d+)%\s*,
29
+ \s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$}x.freeze
30
+ RGBA_PATTERN = %r{^\s*rgba\(\s*(\d{1,3})\s*,
31
+ \s*(\d{1,3})\s*,
32
+ \s*(\d{1,3})\s*,
33
+ \s*(0|1|0\.\d+)\s*\)\s*$}x.freeze
34
+ RGBA_PCT_PATTERN = %r{^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+)
35
+ %\s*,\s*(\d{1,3}|\d{1,2}\.\d+)
36
+ %\s*,\s*(\d{1,3}|\d{1,2}\.\d+)
37
+ %\s*,\s*(0|1|0\.\d+)\s*\)\s*$}x.freeze
38
+ HEX_PATTERN = /#(\h{2})(\h{2})(\h{2})/.freeze
39
+ HEX3_PATTERN = /#(\h)(\h)(\h)/.freeze
40
+ HSL_PATTERN = %r{^\s*hsl\(\s*(\d{1,3})\s*,
41
+ \s*(\d{1,3})%\s*,
42
+ \s*(\d{1,3})%\s*\)\s*$}x.freeze
43
+ HSLA_PATTERN = %r{^\s*hsla\(\s*(\d{1,3})\s*,
44
+ \s*(\d{1,3})%\s*,
45
+ \s*(\d{1,3})%\s*,
46
+ \s*(0|1|0\.\d+)\s*\)\s*$}x.freeze
32
47
 
33
48
  attr_reader :red, :green, :blue, :alpha
34
49
 
35
50
  def self.from_string(str)
36
51
  case str
37
52
  when RGB_PATTERN
38
- new $1, $2, $3
53
+ new Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)
39
54
  when RGB_PCT_PATTERN
40
- new(*[$1, $2, $3].map { |e| Float(e) / 100 * 255 })
55
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
56
+ new(*array.map { |e| Float(e) / 100 * 255 })
41
57
  when RGBA_PATTERN
42
- new $1, $2, $3, $4
58
+ new Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4)
43
59
  when RGBA_PCT_PATTERN
44
- new(*[$1, $2, $3].map { |e| Float(e) / 100 * 255 } << $4)
60
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
61
+ new(*array.map { |e| Float(e) / 100 * 255 } << Regexp.last_match(4))
45
62
  when HEX_PATTERN
46
- new(*[$1, $2, $3].map { |e| e.to_i(16) })
63
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
64
+ new(*array.map { |e| e.to_i(16) })
47
65
  when HEX3_PATTERN
48
- new(*[$1, $2, $3].map { |e| (e * 2).to_i(16) })
66
+ array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)]
67
+ new(*array.map { |e| (e * 2).to_i(16) })
49
68
  when HSL_PATTERN, HSLA_PATTERN
50
- from_hsl($1, $2, $3, $4)
69
+ from_hsl(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4))
51
70
  else
52
71
  raise ArgumentError, "could not convert #{str.inspect} into color"
53
72
  end
54
73
  end
55
74
 
56
- def self.from_hsl(h, s, l, a)
75
+ def self.from_hsl(h, s, l, a) # rubocop:disable Naming/UncommunicativeMethodParamName
57
76
  h = Float(h) / 360
58
77
  s = Float(s) / 100
59
78
  l = Float(l) / 100
60
79
  a = Float(a || 1)
61
80
 
62
- if s == 0
81
+ if s.zero?
63
82
  r = l
64
83
  g = r
65
84
  b = r
66
85
  else
67
- luminocity2 = (l < 0.5) ? l * (1 + s) : l + s - l * s
86
+ luminocity2 = l < 0.5 ? l * (1 + s) : l + s - l * s
68
87
  luminocity1 = 2 * l - luminocity2
69
88
 
70
- hue_to_rgb = lambda do |lum1, lum2, hue|
71
- hue += 1 if hue < 0.0
72
- hue -= 1 if hue > 1.0
73
-
74
- if hue < 1.0 / 6.0
75
- (lum1 + (lum2 - lum1) * 6.0 * hue)
76
- elsif hue < 1.0 / 2.0
77
- lum2
78
- elsif hue < 2.0 / 3.0
79
- lum1 + (lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0
80
- else
81
- lum1
82
- end
83
- end
84
-
85
- r = hue_to_rgb.call(luminocity1, luminocity2, h + 1.0 / 3.0)
86
- g = hue_to_rgb.call(luminocity1, luminocity2, h)
87
- b = hue_to_rgb.call(luminocity1, luminocity2, h - 1.0 / 3.0)
89
+ r = hue_to_rgb(luminocity1, luminocity2, h + 1.0 / 3.0)
90
+ g = hue_to_rgb(luminocity1, luminocity2, h)
91
+ b = hue_to_rgb(luminocity1, luminocity2, h - 1.0 / 3.0)
88
92
  end
89
93
 
90
94
  new (r * 255).round, (g * 255).round, (b * 255).round, a
91
95
  end
92
96
 
97
+ def self.hue_to_rgb(lum1, lum2, hue)
98
+ hue += 1 if hue < 0.0
99
+ hue -= 1 if hue > 1.0
100
+
101
+ if hue < 1.0 / 6.0
102
+ (lum1 + (lum2 - lum1) * 6.0 * hue)
103
+ elsif hue < 1.0 / 2.0
104
+ lum2
105
+ elsif hue < 2.0 / 3.0
106
+ lum1 + (lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0
107
+ else
108
+ lum1
109
+ end
110
+ end
93
111
 
94
112
  def initialize(red, green, blue, alpha = 1)
95
- @red = Integer(red)
113
+ @red = Integer(red)
96
114
  @green = Integer(green)
97
- @blue = Integer(blue)
115
+ @blue = Integer(blue)
98
116
  @alpha = Float(alpha)
99
117
  end
100
118
 
101
119
  def ==(other)
102
120
  return true if equal?(other)
103
- return false unless other.kind_of?(self.class)
121
+ return false unless other.is_a?(self.class)
104
122
 
105
123
  [red, green, blue, alpha] == [other.red, other.green, other.blue, other.alpha]
106
124
  end
@@ -120,9 +138,8 @@ module Selenium
120
138
  end
121
139
 
122
140
  def hex
123
- "#%02x%02x%02x" % [red, green, blue]
141
+ format '#%02x%02x%02x', red, green, blue
124
142
  end
125
-
126
143
  end # Color
127
144
  end # Support
128
145
  end # WebDriver
@@ -0,0 +1,43 @@
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 Support
23
+ module Escaper
24
+ def self.escape(str)
25
+ if str.include?('"') && str.include?("'")
26
+ parts = str.split('"', -1).map { |part| %("#{part}") }
27
+
28
+ quoted = parts.join(%(, '"', ))
29
+ .gsub(/^"", |, ""$/, '')
30
+
31
+ "concat(#{quoted})"
32
+ elsif str.include?('"')
33
+ # escape string with just a quote into being single quoted: f"oo -> 'f"oo'
34
+ "'#{str}'"
35
+ else
36
+ # otherwise return the quoted string
37
+ %("#{str}")
38
+ end
39
+ end
40
+ end # Escaper
41
+ end # Support
42
+ end # WebDriver
43
+ end # Selenium