selenium-webdriver 4.0.0.alpha2 → 4.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +38 -0
  3. data/lib/selenium/server.rb +2 -2
  4. data/lib/selenium/webdriver.rb +9 -7
  5. data/lib/selenium/webdriver/chrome.rb +6 -7
  6. data/lib/selenium/webdriver/chrome/bridge.rb +21 -3
  7. data/lib/selenium/webdriver/chrome/driver.rb +3 -41
  8. data/lib/selenium/webdriver/chrome/options.rb +87 -52
  9. data/lib/selenium/webdriver/chrome/profile.rb +2 -2
  10. data/lib/selenium/webdriver/common.rb +1 -0
  11. data/lib/selenium/webdriver/common/driver.rb +7 -0
  12. data/lib/selenium/webdriver/common/options.rb +92 -0
  13. data/lib/selenium/webdriver/common/profile_helper.rb +10 -2
  14. data/lib/selenium/webdriver/common/service.rb +35 -11
  15. data/lib/selenium/webdriver/edge.rb +25 -7
  16. data/lib/selenium/webdriver/edge_chrome/bridge.rb +30 -0
  17. data/lib/selenium/webdriver/edge_chrome/driver.rb +38 -0
  18. data/lib/selenium/webdriver/edge_chrome/options.rb +34 -0
  19. data/lib/selenium/webdriver/edge_chrome/profile.rb +33 -0
  20. data/lib/selenium/webdriver/edge_chrome/service.rb +40 -0
  21. data/lib/selenium/webdriver/{edge → edge_html}/driver.rb +2 -19
  22. data/lib/selenium/webdriver/{edge → edge_html}/options.rb +26 -15
  23. data/lib/selenium/webdriver/{edge → edge_html}/service.rb +1 -1
  24. data/lib/selenium/webdriver/firefox.rb +9 -12
  25. data/lib/selenium/webdriver/firefox/binary.rb +2 -2
  26. data/lib/selenium/webdriver/firefox/driver.rb +3 -19
  27. data/lib/selenium/webdriver/firefox/extension.rb +8 -0
  28. data/lib/selenium/webdriver/firefox/options.rb +45 -48
  29. data/lib/selenium/webdriver/firefox/profile.rb +5 -3
  30. data/lib/selenium/webdriver/ie.rb +4 -5
  31. data/lib/selenium/webdriver/ie/driver.rb +3 -20
  32. data/lib/selenium/webdriver/ie/options.rb +9 -29
  33. data/lib/selenium/webdriver/remote.rb +16 -10
  34. data/lib/selenium/webdriver/remote/capabilities.rb +10 -0
  35. data/lib/selenium/webdriver/remote/http/default.rb +6 -1
  36. data/lib/selenium/webdriver/remote/http/persistent.rb +5 -6
  37. data/lib/selenium/webdriver/safari.rb +5 -6
  38. data/lib/selenium/webdriver/safari/bridge.rb +3 -3
  39. data/lib/selenium/webdriver/safari/driver.rb +4 -18
  40. data/lib/selenium/webdriver/safari/options.rb +18 -12
  41. data/lib/selenium/webdriver/version.rb +1 -1
  42. metadata +11 -5
@@ -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
 
@@ -64,5 +64,6 @@ require 'selenium/webdriver/common/driver_extensions/uploads_files'
64
64
  require 'selenium/webdriver/common/driver_extensions/has_addons'
65
65
  require 'selenium/webdriver/common/keys'
66
66
  require 'selenium/webdriver/common/profile_helper'
67
+ require 'selenium/webdriver/common/options'
67
68
  require 'selenium/webdriver/common/driver'
68
69
  require 'selenium/webdriver/common/element'
@@ -52,6 +52,10 @@ module Selenium
52
52
  Firefox::Driver.new(opts)
53
53
  when :edge
54
54
  Edge::Driver.new(opts)
55
+ when :edge_chrome
56
+ EdgeChrome::Driver.new(opts)
57
+ when :edge_html
58
+ EdgeHtml::Driver.new(opts)
55
59
  when :remote
56
60
  Remote::Driver.new(opts)
57
61
  else
@@ -68,6 +72,7 @@ module Selenium
68
72
  #
69
73
 
70
74
  def initialize(bridge, listener: nil)
75
+ @service = nil
71
76
  @bridge = bridge
72
77
  @bridge = Support::EventFiringBridge.new(bridge, listener) if listener
73
78
  end
@@ -164,6 +169,8 @@ module Selenium
164
169
 
165
170
  def quit
166
171
  bridge.quit
172
+ ensure
173
+ @service&.stop
167
174
  end
168
175
 
169
176
  #
@@ -0,0 +1,92 @@
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 Options
23
+ attr_accessor :options
24
+
25
+ def initialize(options: nil, **opts)
26
+ @options = if options
27
+ WebDriver.logger.deprecate(":options as keyword for initializing #{self.class}",
28
+ "custom values directly in #new constructor")
29
+ opts.merge(options)
30
+ else
31
+ opts
32
+ end
33
+ end
34
+
35
+ #
36
+ # Add a new option not yet handled by bindings.
37
+ #
38
+ # @example Leave Chrome open when chromedriver is killed
39
+ # options = Selenium::WebDriver::Chrome::Options.new
40
+ # options.add_option(:detach, true)
41
+ #
42
+ # @param [String, Symbol] name Name of the option
43
+ # @param [Boolean, String, Integer] value Value of the option
44
+ #
45
+
46
+ def add_option(name, value)
47
+ @options[name] = value
48
+ end
49
+
50
+ #
51
+ # @api private
52
+ #
53
+
54
+ def as_json(*)
55
+ options = @options.dup
56
+
57
+ opts = self.class::CAPABILITIES.each_with_object({}) do |(capability_alias, capability_name), hash|
58
+ capability_value = options.delete(capability_alias)
59
+ hash[capability_name] = capability_value unless capability_value.nil?
60
+ end
61
+ opts.merge(options)
62
+ end
63
+
64
+ private
65
+
66
+ def generate_as_json(value)
67
+ if value.respond_to?(:as_json)
68
+ value.as_json
69
+ elsif value.is_a?(Hash)
70
+ value.each_with_object({}) { |(key, val), hash| hash[convert_json_key(key)] = generate_as_json(val) }
71
+ elsif value.is_a?(Array)
72
+ value.map(&method(:generate_as_json))
73
+ elsif value.is_a?(Symbol)
74
+ value.to_s
75
+ else
76
+ value
77
+ end
78
+ end
79
+
80
+ def convert_json_key(key)
81
+ key = camel_case(key) if key.is_a?(Symbol)
82
+ return key if key.is_a?(String)
83
+
84
+ raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class}"
85
+ end
86
+
87
+ def camel_case(str)
88
+ str.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
89
+ end
90
+ end # Options
91
+ end # WebDriver
92
+ end # Selenium
@@ -31,8 +31,16 @@ module Selenium
31
31
  base.extend ClassMethods
32
32
  end
33
33
 
34
+ def self.decoded(json)
35
+ JSON.parse(json).fetch('zip')
36
+ end
37
+
38
+ def encoded
39
+ Zipper.zip(layout_on_disk)
40
+ end
41
+
34
42
  def as_json(*)
35
- {"zip" => Zipper.zip(layout_on_disk)}
43
+ {"zip" => encoded}
36
44
  end
37
45
 
38
46
  def to_json(*)
@@ -63,7 +71,7 @@ module Selenium
63
71
 
64
72
  module ClassMethods
65
73
  def from_json(json)
66
- data = JSON.parse(json).fetch('zip')
74
+ data = decoded(json)
67
75
 
68
76
  # can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
69
77
  # can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
@@ -32,25 +32,46 @@ module Selenium
32
32
  class << self
33
33
  attr_reader :driver_path
34
34
 
35
- def chrome(*args)
36
- Chrome::Service.new(*args)
35
+ def chrome(**opts)
36
+ Chrome::Service.new(**opts)
37
37
  end
38
38
 
39
- def firefox(*args)
40
- Firefox::Service.new(*args)
39
+ def firefox(**opts)
40
+ binary_path = Firefox::Binary.path
41
+ args = opts.delete(:args)
42
+ case args
43
+ when Hash
44
+ args[:binary] ||= binary_path
45
+ opts[:args] = args
46
+ when Array
47
+ opts[:args] = ["--binary=#{binary_path}"]
48
+ opts[:args] += args
49
+ else
50
+ opts[:args] = ["--binary=#{binary_path}"]
51
+ end
52
+
53
+ Firefox::Service.new(**opts)
41
54
  end
42
55
 
43
- def ie(*args)
44
- IE::Service.new(*args)
56
+ def ie(**opts)
57
+ IE::Service.new(**opts)
45
58
  end
46
59
  alias_method :internet_explorer, :ie
47
60
 
48
- def edge(*args)
49
- Edge::Service.new(*args)
61
+ def edge(**opts)
62
+ Edge::Service.new(**opts)
50
63
  end
51
64
 
52
- def safari(*args)
53
- Safari::Service.new(*args)
65
+ def edge_chrome(**opts)
66
+ EdgeChrome::Service.new(**opts)
67
+ end
68
+
69
+ def edge_html(**opts)
70
+ EdgeHtml::Service.new(**opts)
71
+ end
72
+
73
+ def safari(**opts)
74
+ Safari::Service.new(**opts)
54
75
  end
55
76
 
56
77
  def driver_path=(path)
@@ -164,7 +185,10 @@ module Selenium
164
185
  def stop_server
165
186
  return if process_exited?
166
187
 
167
- connect_to_server { |http| http.get('/shutdown') }
188
+ connect_to_server do |http|
189
+ headers = WebDriver::Remote::Http::Common::DEFAULT_HEADERS.dup
190
+ http.get('/shutdown', headers)
191
+ end
168
192
  end
169
193
 
170
194
  def process_running?
@@ -19,12 +19,13 @@
19
19
 
20
20
  require 'net/http'
21
21
 
22
- require 'selenium/webdriver/edge/driver'
23
- require 'selenium/webdriver/edge/options'
24
-
25
22
  module Selenium
26
23
  module WebDriver
27
- module Edge
24
+ module EdgeHtml
25
+ autoload :Driver, 'selenium/webdriver/edge_html/driver'
26
+ autoload :Options, 'selenium/webdriver/edge_html/options'
27
+ autoload :Service, 'selenium/webdriver/edge_html/service'
28
+
28
29
  def self.driver_path=(path)
29
30
  WebDriver.logger.deprecate 'Selenium::WebDriver::Edge#driver_path=',
30
31
  'Selenium::WebDriver::Edge::Service#driver_path='
@@ -36,8 +37,25 @@ module Selenium
36
37
  'Selenium::WebDriver::Edge::Service#driver_path'
37
38
  Selenium::WebDriver::Edge::Service.driver_path
38
39
  end
39
- end # Edge
40
+ end # EdgeHtml
41
+
42
+ module EdgeChrome
43
+ autoload :Bridge, 'selenium/webdriver/edge_chrome/bridge'
44
+ autoload :Driver, 'selenium/webdriver/edge_chrome/driver'
45
+ autoload :Profile, 'selenium/webdriver/edge_chrome/profile'
46
+ autoload :Options, 'selenium/webdriver/edge_chrome/options'
47
+ autoload :Service, 'selenium/webdriver/edge_chrome/service'
48
+
49
+ def self.path=(path)
50
+ Platform.assert_executable path
51
+ @path = path
52
+ end
53
+
54
+ def self.path
55
+ @path ||= nil
56
+ end
57
+ end # EdgeChrome
58
+
59
+ Edge = EdgeHtml # Alias EdgeHtml as Edge for now
40
60
  end # WebDriver
41
61
  end # Selenium
42
-
43
- require 'selenium/webdriver/edge/service'
@@ -0,0 +1,30 @@
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 'selenium/webdriver/chrome/bridge'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ module EdgeChrome
25
+ module Bridge
26
+ include Selenium::WebDriver::Chrome::Bridge
27
+ end # Bridge
28
+ end # EdgeChrome
29
+ end # WebDriver
30
+ end # Selenium
@@ -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
+ require 'selenium/webdriver/chrome/driver'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ module EdgeChrome
25
+
26
+ #
27
+ # Driver implementation for EdgeChrome.
28
+ # @api private
29
+ #
30
+
31
+ class Driver < Selenium::WebDriver::Chrome::Driver
32
+ def browser
33
+ :edge_chrome
34
+ end
35
+ end # Driver
36
+ end # Chrome
37
+ end # WebDriver
38
+ end # Selenium
@@ -0,0 +1,34 @@
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 'selenium/webdriver/chrome/options'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ module EdgeChrome
25
+ class Options < Selenium::WebDriver::Chrome::Options
26
+ private
27
+
28
+ def binary_path
29
+ EdgeChrome.path
30
+ end
31
+ end # Options
32
+ end # EdgeChrome
33
+ end # WebDriver
34
+ 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
+ require 'selenium/webdriver/chrome/profile'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ module EdgeChrome
25
+ #
26
+ # @private
27
+ #
28
+
29
+ class Profile < Selenium::WebDriver::Chrome::Profile
30
+ end # Profile
31
+ end # EdgeChrome
32
+ end # WebDriver
33
+ end # Selenium
@@ -0,0 +1,40 @@
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 'selenium/webdriver/chrome/service'
21
+
22
+ module Selenium
23
+ module WebDriver
24
+ module EdgeChrome
25
+ #
26
+ # @api private
27
+ #
28
+
29
+ class Service < Selenium::WebDriver::Chrome::Service
30
+ DEFAULT_PORT = 9515
31
+ EXECUTABLE = 'msedgedriver'
32
+ MISSING_TEXT = <<~ERROR
33
+ Unable to find msedgedriver. Please download the server from
34
+ https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ and place it somewhere on your PATH.
35
+ ERROR
36
+ SHUTDOWN_SUPPORTED = true
37
+ end # Service
38
+ end # EdgeChrome
39
+ end # WebDriver
40
+ end # Selenium