selenium-webdriver 3.141.0 → 3.141.592

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +78 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE +1 -1
  5. data/lib/selenium-webdriver.rb +2 -0
  6. data/lib/selenium/server.rb +9 -7
  7. data/lib/selenium/webdriver.rb +3 -1
  8. data/lib/selenium/webdriver/atoms.rb +20 -1
  9. data/lib/selenium/webdriver/atoms/getAttribute.js +6 -7
  10. data/lib/selenium/webdriver/atoms/isDisplayed.js +60 -59
  11. data/lib/selenium/webdriver/chrome.rb +10 -4
  12. data/lib/selenium/webdriver/chrome/bridge.rb +5 -3
  13. data/lib/selenium/webdriver/chrome/driver.rb +10 -13
  14. data/lib/selenium/webdriver/chrome/options.rb +4 -4
  15. data/lib/selenium/webdriver/chrome/profile.rb +4 -3
  16. data/lib/selenium/webdriver/chrome/service.rb +13 -13
  17. data/lib/selenium/webdriver/common.rb +4 -2
  18. data/lib/selenium/webdriver/common/action_builder.rb +2 -0
  19. data/lib/selenium/webdriver/common/alert.rb +2 -0
  20. data/lib/selenium/webdriver/common/bridge_helper.rb +8 -5
  21. data/lib/selenium/webdriver/common/driver.rb +22 -7
  22. data/lib/selenium/webdriver/common/driver_extensions/downloads_files.rb +2 -0
  23. data/lib/selenium/webdriver/common/driver_extensions/has_addons.rb +2 -0
  24. data/lib/selenium/webdriver/common/driver_extensions/has_debugger.rb +2 -0
  25. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +3 -3
  26. data/lib/selenium/webdriver/common/driver_extensions/has_network_conditions.rb +2 -0
  27. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +3 -1
  28. data/lib/selenium/webdriver/common/driver_extensions/has_permissions.rb +2 -0
  29. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +2 -0
  30. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +2 -0
  31. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +2 -0
  32. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +2 -0
  33. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +3 -1
  34. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -0
  35. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +3 -3
  36. data/lib/selenium/webdriver/common/element.rb +3 -1
  37. data/lib/selenium/webdriver/common/error.rb +74 -18
  38. data/lib/selenium/webdriver/common/file_reaper.rb +3 -3
  39. data/lib/selenium/webdriver/common/html5/local_storage.rb +2 -0
  40. data/lib/selenium/webdriver/common/html5/session_storage.rb +2 -0
  41. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +4 -1
  42. data/lib/selenium/webdriver/common/interactions/input_device.rb +3 -0
  43. data/lib/selenium/webdriver/common/interactions/interaction.rb +3 -0
  44. data/lib/selenium/webdriver/common/interactions/interactions.rb +3 -1
  45. data/lib/selenium/webdriver/common/interactions/key_actions.rb +2 -0
  46. data/lib/selenium/webdriver/common/interactions/key_input.rb +4 -0
  47. data/lib/selenium/webdriver/common/interactions/none_input.rb +3 -0
  48. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +2 -0
  49. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +7 -0
  50. data/lib/selenium/webdriver/common/keyboard.rb +4 -1
  51. data/lib/selenium/webdriver/common/keys.rb +3 -0
  52. data/lib/selenium/webdriver/common/log_entry.rb +4 -2
  53. data/lib/selenium/webdriver/common/logger.rb +15 -40
  54. data/lib/selenium/webdriver/common/logs.rb +2 -0
  55. data/lib/selenium/webdriver/common/manager.rb +177 -0
  56. data/lib/selenium/webdriver/common/mouse.rb +3 -0
  57. data/lib/selenium/webdriver/common/navigation.rb +2 -0
  58. data/lib/selenium/webdriver/common/options.rb +26 -0
  59. data/lib/selenium/webdriver/common/platform.rb +26 -30
  60. data/lib/selenium/webdriver/common/port_prober.rb +6 -19
  61. data/lib/selenium/webdriver/common/profile_helper.rb +2 -0
  62. data/lib/selenium/webdriver/common/proxy.rb +13 -5
  63. data/lib/selenium/webdriver/common/search_context.rb +4 -6
  64. data/lib/selenium/webdriver/common/service.rb +74 -29
  65. data/lib/selenium/webdriver/common/socket_lock.rb +10 -3
  66. data/lib/selenium/webdriver/common/socket_poller.rb +45 -48
  67. data/lib/selenium/webdriver/common/target_locator.rb +6 -4
  68. data/lib/selenium/webdriver/common/timeouts.rb +2 -0
  69. data/lib/selenium/webdriver/common/touch_action_builder.rb +5 -6
  70. data/lib/selenium/webdriver/common/touch_screen.rb +4 -1
  71. data/lib/selenium/webdriver/common/w3c_action_builder.rb +3 -0
  72. data/lib/selenium/webdriver/common/w3c_manager.rb +45 -0
  73. data/lib/selenium/webdriver/common/w3c_options.rb +2 -0
  74. data/lib/selenium/webdriver/common/wait.rb +11 -3
  75. data/lib/selenium/webdriver/common/window.rb +2 -0
  76. data/lib/selenium/webdriver/common/zipper.rb +3 -3
  77. data/lib/selenium/webdriver/edge.rb +11 -5
  78. data/lib/selenium/webdriver/edge/bridge.rb +2 -0
  79. data/lib/selenium/webdriver/edge/driver.rb +5 -12
  80. data/lib/selenium/webdriver/edge/options.rb +3 -0
  81. data/lib/selenium/webdriver/edge/service.rb +8 -12
  82. data/lib/selenium/webdriver/firefox.rb +10 -4
  83. data/lib/selenium/webdriver/firefox/binary.rb +7 -6
  84. data/lib/selenium/webdriver/firefox/bridge.rb +47 -0
  85. data/lib/selenium/webdriver/firefox/driver.rb +3 -2
  86. data/lib/selenium/webdriver/firefox/extension.rb +4 -4
  87. data/lib/selenium/webdriver/firefox/launcher.rb +3 -0
  88. data/lib/selenium/webdriver/firefox/legacy/driver.rb +7 -3
  89. data/lib/selenium/webdriver/firefox/marionette/bridge.rb +4 -2
  90. data/lib/selenium/webdriver/firefox/marionette/driver.rb +5 -11
  91. data/lib/selenium/webdriver/firefox/options.rb +3 -1
  92. data/lib/selenium/webdriver/firefox/profile.rb +7 -8
  93. data/lib/selenium/webdriver/firefox/profiles_ini.rb +3 -0
  94. data/lib/selenium/webdriver/firefox/service.rb +8 -19
  95. data/lib/selenium/webdriver/firefox/util.rb +2 -0
  96. data/lib/selenium/webdriver/ie.rb +10 -4
  97. data/lib/selenium/webdriver/ie/driver.rb +4 -10
  98. data/lib/selenium/webdriver/ie/options.rb +4 -2
  99. data/lib/selenium/webdriver/ie/service.rb +8 -12
  100. data/lib/selenium/webdriver/remote.rb +2 -0
  101. data/lib/selenium/webdriver/remote/bridge.rb +6 -4
  102. data/lib/selenium/webdriver/remote/capabilities.rb +23 -10
  103. data/lib/selenium/webdriver/remote/commands.rb +156 -0
  104. data/lib/selenium/webdriver/remote/driver.rb +2 -0
  105. data/lib/selenium/webdriver/remote/http/common.rb +11 -4
  106. data/lib/selenium/webdriver/remote/http/curb.rb +4 -2
  107. data/lib/selenium/webdriver/remote/http/default.rb +31 -25
  108. data/lib/selenium/webdriver/remote/http/persistent.rb +3 -1
  109. data/lib/selenium/webdriver/remote/oss/bridge.rb +5 -2
  110. data/lib/selenium/webdriver/remote/oss/commands.rb +106 -104
  111. data/lib/selenium/webdriver/remote/response.rb +10 -4
  112. data/lib/selenium/webdriver/remote/server_error.rb +2 -0
  113. data/lib/selenium/webdriver/remote/w3c/bridge.rb +28 -13
  114. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +37 -21
  115. data/lib/selenium/webdriver/remote/w3c/commands.rb +61 -58
  116. data/lib/selenium/webdriver/safari.rb +11 -4
  117. data/lib/selenium/webdriver/safari/bridge.rb +5 -3
  118. data/lib/selenium/webdriver/safari/driver.rb +8 -10
  119. data/lib/selenium/webdriver/safari/options.rb +2 -0
  120. data/lib/selenium/webdriver/safari/service.rb +6 -25
  121. data/lib/selenium/webdriver/support.rb +2 -0
  122. data/lib/selenium/webdriver/support/abstract_event_listener.rb +2 -0
  123. data/lib/selenium/webdriver/support/block_event_listener.rb +3 -1
  124. data/lib/selenium/webdriver/support/color.rb +11 -9
  125. data/lib/selenium/webdriver/support/escaper.rb +2 -0
  126. data/lib/selenium/webdriver/support/event_firing_bridge.rb +3 -1
  127. data/lib/selenium/webdriver/support/select.rb +19 -18
  128. data/lib/selenium/webdriver/version.rb +3 -1
  129. data/selenium-webdriver.gemspec +14 -7
  130. metadata +89 -21
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -41,9 +43,7 @@ module Selenium
41
43
  def reap(file)
42
44
  return unless reap?
43
45
 
44
- unless tmp_files.include?(file)
45
- raise Error::WebDriverError, "file not added for reaping: #{file.inspect}"
46
- end
46
+ raise Error::WebDriverError, "file not added for reaping: #{file.inspect}" unless tmp_files.include?(file)
47
47
 
48
48
  FileUtils.rm_rf tmp_files.delete(file)
49
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -30,6 +32,7 @@ module Selenium
30
32
  def fetch(key)
31
33
  return self[key] if key? key
32
34
  return yield(key) if block_given?
35
+
33
36
  raise KeyError, "missing key #{key.inspect}"
34
37
  end
35
38
 
@@ -40,7 +43,7 @@ module Selenium
40
43
  def each
41
44
  return enum_for(:each) unless block_given?
42
45
 
43
- keys.each do |k| # rubocop:disable Performance/HashEachMethods
46
+ keys.each do |k|
44
47
  yield k, self[k]
45
48
  end
46
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -30,6 +32,7 @@ module Selenium
30
32
 
31
33
  def add_action(action)
32
34
  raise TypeError, "#{action.inspect} is not a valid action" unless action.class < Interaction
35
+
33
36
  @actions << action
34
37
  end
35
38
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -25,6 +27,7 @@ module Selenium
25
27
 
26
28
  def initialize(source)
27
29
  raise TypeError, "#{source.type} is not a valid input type" unless Interactions::SOURCE_TYPES.include? source.type
30
+
28
31
  @source = source
29
32
  end
30
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -13,7 +15,7 @@
13
15
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
16
  # KIND, either express or implied. See the License for the
15
17
  # specific language governing permissions and limitations
16
- # under the License
18
+ # under the License.
17
19
 
18
20
  module Selenium
19
21
  module WebDriver
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -27,6 +29,7 @@ module Selenium
27
29
 
28
30
  def encode
29
31
  return nil if no_actions?
32
+
30
33
  {type: type, id: name, actions: @actions.map(&:encode)}
31
34
  end
32
35
 
@@ -49,6 +52,7 @@ module Selenium
49
52
 
50
53
  def assert_type(type)
51
54
  raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
55
+
52
56
  KeyInput::SUBTYPES[type]
53
57
  end
54
58
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -25,6 +27,7 @@ module Selenium
25
27
 
26
28
  def encode
27
29
  return nil if no_actions?
30
+
28
31
  {type: type, id: name, actions: @actions.map(&:encode)}
29
32
  end
30
33
  end # NoneInput
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -34,6 +36,7 @@ module Selenium
34
36
 
35
37
  def encode
36
38
  return nil if no_actions?
39
+
37
40
  output = {type: type, id: name, actions: @actions.map(&:encode)}
38
41
  output[:parameters] = {pointerType: kind}
39
42
  output
@@ -41,6 +44,7 @@ module Selenium
41
44
 
42
45
  def assert_kind(pointer)
43
46
  raise TypeError, "#{pointer.inspect} is not a valid pointer type" unless KIND.key? pointer
47
+
44
48
  KIND[pointer]
45
49
  end
46
50
 
@@ -78,14 +82,17 @@ module Selenium
78
82
  def assert_button(button)
79
83
  if button.is_a? Symbol
80
84
  raise TypeError, "#{button.inspect} is not a valid button!" unless BUTTONS.key? button
85
+
81
86
  button = BUTTONS[button]
82
87
  end
83
88
  raise ArgumentError, 'Button number cannot be negative!' unless button >= 0
89
+
84
90
  button
85
91
  end
86
92
 
87
93
  def assert_direction(direction)
88
94
  raise TypeError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction
95
+
89
96
  DIRECTIONS[direction]
90
97
  end
91
98
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -56,10 +58,11 @@ module Selenium
56
58
 
57
59
  private
58
60
 
59
- MODIFIERS = [:control, :shift, :alt, :command, :meta].freeze
61
+ MODIFIERS = %i[control shift alt command meta].freeze
60
62
 
61
63
  def assert_modifier(key)
62
64
  return if MODIFIERS.include? key
65
+
63
66
  raise ArgumentError, "#{key.inspect} is not a modifier key, expected one of #{MODIFIERS.inspect}"
64
67
  end
65
68
  end # Keyboard
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -110,6 +112,7 @@ module Selenium
110
112
 
111
113
  def self.[](key)
112
114
  return KEYS[key] if KEYS[key]
115
+
113
116
  raise Error::UnsupportedOperationError, "no such key #{key.inspect}"
114
117
  end
115
118
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -28,9 +30,9 @@ module Selenium
28
30
 
29
31
  def as_json(*)
30
32
  {
31
- 'level' => level,
33
+ 'level' => level,
32
34
  'timestamp' => timestamp,
33
- 'message' => message
35
+ 'message' => message
34
36
  }
35
37
  end
36
38
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -33,54 +35,27 @@ module Selenium
33
35
  #
34
36
  class Logger
35
37
  extend Forwardable
36
- include ::Logger::Severity
37
38
 
38
- def_delegators :@logger, :debug, :debug?,
39
+ def_delegators :@logger,
40
+ :close,
41
+ :debug, :debug?,
39
42
  :info, :info?,
40
43
  :warn, :warn?,
41
44
  :error, :error?,
42
45
  :fatal, :fatal?,
43
- :level
46
+ :level, :level=
44
47
 
45
48
  def initialize
46
49
  @logger = create_logger($stdout)
47
50
  end
48
51
 
49
- def output=(io)
50
- # `Logger#reopen` was added in Ruby 2.3
51
- if @logger.respond_to?(:reopen)
52
- @logger.reopen(io)
53
- else
54
- @logger = create_logger(io)
55
- end
56
- end
57
-
58
52
  #
59
- # For Ruby < 2.3 compatibility
60
- # Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250
53
+ # Changes logger output to a new IO.
61
54
  #
62
-
63
- def level=(severity)
64
- if severity.is_a?(Integer)
65
- @logger.level = severity
66
- else
67
- case severity.to_s.downcase
68
- when 'debug'.freeze
69
- @logger.level = DEBUG
70
- when 'info'.freeze
71
- @logger.level = INFO
72
- when 'warn'.freeze
73
- @logger.level = WARN
74
- when 'error'.freeze
75
- @logger.level = ERROR
76
- when 'fatal'.freeze
77
- @logger.level = FATAL
78
- when 'unknown'.freeze
79
- @logger.level = UNKNOWN
80
- else
81
- raise ArgumentError, "invalid log level: #{severity}"
82
- end
83
- end
55
+ # @param [String] io
56
+ #
57
+ def output=(io)
58
+ @logger.reopen(io)
84
59
  end
85
60
 
86
61
  #
@@ -95,7 +70,7 @@ module Selenium
95
70
  # @api private
96
71
  #
97
72
  def io
98
- @logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
73
+ @logger.instance_variable_get(:@logdev).dev
99
74
  end
100
75
 
101
76
  #
@@ -105,7 +80,7 @@ module Selenium
105
80
  # @param [String, nil] new
106
81
  #
107
82
  def deprecate(old, new = nil)
108
- message = "[DEPRECATION] #{old} is deprecated"
83
+ message = +"[DEPRECATION] #{old} is deprecated"
109
84
  message << if new
110
85
  ". Use #{new} instead."
111
86
  else
@@ -130,9 +105,9 @@ module Selenium
130
105
 
131
106
  def default_level
132
107
  if $DEBUG || ENV.key?('DEBUG')
133
- DEBUG
108
+ :debug
134
109
  else
135
- WARN
110
+ :warn
136
111
  end
137
112
  end
138
113
  end # Logger
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Licensed to the Software Freedom Conservancy (SFC) under one
2
4
  # or more contributor license agreements. See the NOTICE file
3
5
  # distributed with this work for additional information
@@ -0,0 +1,177 @@
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 Manager
23
+ #
24
+ # @api private
25
+ #
26
+
27
+ def initialize(bridge)
28
+ @bridge = bridge
29
+ end
30
+
31
+ #
32
+ # Add a cookie to the browser
33
+ #
34
+ # @param [Hash] opts the options to create a cookie with.
35
+ # @option opts [String] :name A name
36
+ # @option opts [String] :value A value
37
+ # @option opts [String] :path ('/') A path
38
+ # @option opts [String] :secure (false) A boolean
39
+ # @option opts [Time,DateTime,Numeric,nil] :expires (nil) Expiry date, either as a Time, DateTime, or seconds since epoch.
40
+ #
41
+ # @raise [ArgumentError] if :name or :value is not specified
42
+ #
43
+
44
+ def add_cookie(opts = {})
45
+ raise ArgumentError, 'name is required' unless opts[:name]
46
+ raise ArgumentError, 'value is required' unless opts[:value]
47
+
48
+ opts[:path] ||= '/'
49
+ opts[:secure] ||= false
50
+
51
+ obj = opts.delete(:expires)
52
+ opts[:expiry] = seconds_from(obj).to_i if obj
53
+
54
+ @bridge.add_cookie opts
55
+ end
56
+
57
+ #
58
+ # Get the cookie with the given name
59
+ #
60
+ # @param [String] name the name of the cookie
61
+ # @return [Hash, nil] the cookie, or nil if it wasn't found.
62
+ #
63
+
64
+ def cookie_named(name)
65
+ all_cookies.find { |c| c[:name] == name }
66
+ end
67
+
68
+ #
69
+ # Delete the cookie with the given name
70
+ #
71
+ # @param [String] name the name of the cookie to delete
72
+ #
73
+
74
+ def delete_cookie(name)
75
+ @bridge.delete_cookie name
76
+ end
77
+
78
+ #
79
+ # Delete all cookies
80
+ #
81
+
82
+ def delete_all_cookies
83
+ @bridge.delete_all_cookies
84
+ end
85
+
86
+ #
87
+ # Get all cookies
88
+ #
89
+ # @return [Array<Hash>] list of cookies
90
+ #
91
+
92
+ def all_cookies
93
+ @bridge.cookies.map { |cookie| convert_cookie(cookie) }
94
+ end
95
+
96
+ def timeouts
97
+ @timeouts ||= Timeouts.new(@bridge)
98
+ end
99
+
100
+ #
101
+ # @api beta This API may be changed or removed in a future release.
102
+ #
103
+
104
+ def logs
105
+ @logs ||= Logs.new(@bridge)
106
+ end
107
+
108
+ #
109
+ # Create a new top-level browsing context
110
+ # https://w3c.github.io/webdriver/#new-window
111
+ # @param type [Symbol] Supports two values: :tab and :window.
112
+ # Use :tab if you'd like the new window to share an OS-level window
113
+ # with the current browsing context.
114
+ # Use :window otherwise
115
+ # @return [String] The value of the window handle
116
+ #
117
+ def new_window(type = :tab)
118
+ case type
119
+ when :tab, :window
120
+ result = @bridge.new_window(type)
121
+ unless result.key?('handle')
122
+ raise UnknownError, "the driver did not return a handle. " \
123
+ "The returned result: #{result.inspect}"
124
+ end
125
+ result['handle']
126
+ else
127
+ raise ArgumentError, "invalid argument for type. Got: '#{type.inspect}'. " \
128
+ "Try :tab or :window"
129
+ end
130
+ end
131
+
132
+ #
133
+ # @api beta This API may be changed or removed in a future release.
134
+ #
135
+
136
+ def window
137
+ @window ||= Window.new(@bridge)
138
+ end
139
+
140
+ private
141
+
142
+ SECONDS_PER_DAY = 86_400.0
143
+
144
+ def datetime_at(int)
145
+ DateTime.civil(1970) + (int / SECONDS_PER_DAY)
146
+ end
147
+
148
+ def seconds_from(obj)
149
+ case obj
150
+ when Time
151
+ obj.to_f
152
+ when DateTime
153
+ (obj - DateTime.civil(1970)) * SECONDS_PER_DAY
154
+ when Numeric
155
+ obj
156
+ else
157
+ raise ArgumentError, "invalid value for expiration date: #{obj.inspect}"
158
+ end
159
+ end
160
+
161
+ def strip_port(str)
162
+ str.split(':', 2).first
163
+ end
164
+
165
+ def convert_cookie(cookie)
166
+ {
167
+ name: cookie['name'],
168
+ value: cookie['value'],
169
+ path: cookie['path'],
170
+ domain: cookie['domain'] && strip_port(cookie['domain']),
171
+ expires: cookie['expiry'] && datetime_at(cookie['expiry']),
172
+ secure: cookie['secure']
173
+ }
174
+ end
175
+ end # Options
176
+ end # WebDriver
177
+ end # Selenium