selenium-webdriver 2.53.3 → 3.142.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -20,104 +20,32 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Edge
23
-
24
23
  #
25
24
  # @api private
26
25
  #
27
26
 
28
- class Service
29
- START_TIMEOUT = 20
30
- SOCKET_LOCK_TIMEOUT = 45
31
- STOP_TIMEOUT = 5
32
- DEFAULT_PORT = 17556
33
- MISSING_TEXT = "Unable to find MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver."
34
-
35
- def self.executable_path
36
- @executable_path ||= (
37
- path = Platform.find_binary "MicrosoftWebDriver"
38
- path or raise Error::WebDriverError, MISSING_TEXT
39
- Platform.assert_executable path
40
-
41
- path
42
- )
43
- end
44
-
45
- def self.executable_path=(path)
46
- Platform.assert_executable path
47
- @executable_path = path
48
- end
49
-
50
- def self.default_service(*extra_args)
51
- new executable_path, DEFAULT_PORT, *extra_args
27
+ class Service < WebDriver::Service
28
+ @default_port = 17556
29
+ @executable = 'MicrosoftWebDriver'
30
+ @missing_text = <<~ERROR
31
+ Unable to find MicrosoftWebDriver. Please download the server from
32
+ https://www.microsoft.com/en-us/download/details.aspx?id=48212 and place it somewhere on your PATH.
33
+ More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver.
34
+ ERROR
35
+ @shutdown_supported = true
36
+
37
+ private
38
+
39
+ # Note: This processing is deprecated
40
+ def extract_service_args(driver_opts)
41
+ driver_args = super
42
+ driver_opts = driver_opts.dup
43
+ driver_args << "--host=#{driver_opts[:host]}" if driver_opts.key? :host
44
+ driver_args << "--package=#{driver_opts[:package]}" if driver_opts.key? :package
45
+ driver_args << "--silent" if driver_opts[:silent] == true
46
+ driver_args << "--verbose" if driver_opts[:verbose] == true
47
+ driver_args
52
48
  end
53
-
54
- def initialize(executable_path, port, *extra_args)
55
- @executable_path = executable_path
56
- @host = Platform.localhost
57
- @port = Integer(port)
58
-
59
- raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
60
-
61
- @extra_args = extra_args
62
- end
63
-
64
- def start
65
- Platform.exit_hook { stop } # make sure we don't leave the server running
66
-
67
- socket_lock.locked do
68
- find_free_port
69
- start_process
70
- connect_until_stable
71
- end
72
- end
73
-
74
- def stop
75
- return if @process.nil? || @process.exited?
76
-
77
- Net::HTTP.start(@host, @port) do |http|
78
- http.open_timeout = STOP_TIMEOUT / 2
79
- http.read_timeout = STOP_TIMEOUT / 2
80
-
81
- http.head("/shutdown")
82
- end
83
- ensure
84
- stop_process
85
- end
86
-
87
- def uri
88
- URI.parse "http://#{@host}:#{@port}"
89
- end
90
-
91
- def find_free_port
92
- @port = PortProber.above @port
93
- end
94
-
95
- def start_process
96
- server_command = [@executable_path, "--port=#{@port}", *@extra_args]
97
- @process = ChildProcess.build(*server_command)
98
-
99
- @process.io.inherit! if $DEBUG == true
100
- @process.start
101
- end
102
-
103
- def stop_process
104
- @process.poll_for_exit STOP_TIMEOUT
105
- rescue ChildProcess::TimeoutError
106
- @process.stop STOP_TIMEOUT
107
- end
108
-
109
- def connect_until_stable
110
- socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
111
-
112
- unless socket_poller.connected?
113
- raise Error::WebDriverError, "unable to connect to MicrosoftWebDriver #{@host}:#{@port}"
114
- end
115
- end
116
-
117
- def socket_lock
118
- @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
119
- end
120
-
121
49
  end # Service
122
50
  end # Edge
123
51
  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
@@ -19,26 +19,26 @@
19
19
 
20
20
  require 'net/http'
21
21
 
22
- require 'selenium/webdriver/edge/service'
23
22
  require 'selenium/webdriver/edge/bridge'
23
+ require 'selenium/webdriver/edge/driver'
24
+ require 'selenium/webdriver/edge/options'
24
25
 
25
26
  module Selenium
26
27
  module WebDriver
27
-
28
28
  module Edge
29
29
  def self.driver_path=(path)
30
- Service.executable_path = path
30
+ WebDriver.logger.deprecate 'Selenium::WebDriver::Edge#driver_path=',
31
+ 'Selenium::WebDriver::Edge::Service#driver_path='
32
+ Selenium::WebDriver::Edge::Service.driver_path = path
31
33
  end
32
34
 
33
- def self.path=(path)
34
- Platform.assert_executable path
35
- @path = path
35
+ def self.driver_path
36
+ WebDriver.logger.deprecate 'Selenium::WebDriver::Edge#driver_path',
37
+ 'Selenium::WebDriver::Edge::Service#driver_path'
38
+ Selenium::WebDriver::Edge::Service.driver_path
36
39
  end
37
-
38
- def self.path
39
- @path ||= nil
40
- end
41
-
42
40
  end # Edge
43
41
  end # WebDriver
44
42
  end # Selenium
43
+
44
+ require 'selenium/webdriver/edge/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,42 +20,40 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Firefox
23
-
24
23
  # @api private
25
24
  class Binary
26
-
27
- NO_FOCUS_LIBRARY_NAME = "x_ignore_nofocus.so"
28
- NO_FOCUS_LIBRARIES = [
29
- ["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}", "amd64/#{NO_FOCUS_LIBRARY_NAME}"],
30
- ["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}", "x86/#{NO_FOCUS_LIBRARY_NAME}"],
31
- ]
25
+ NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'
26
+ NO_FOCUS_LIBRARIES = [
27
+ ["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}",
28
+ "amd64/#{NO_FOCUS_LIBRARY_NAME}"],
29
+ ["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}",
30
+ "x86/#{NO_FOCUS_LIBRARY_NAME}"]
31
+ ].freeze
32
32
 
33
33
  WAIT_TIMEOUT = 90
34
34
  QUIT_TIMEOUT = 5
35
35
 
36
36
  def start_with(profile, profile_path, *args)
37
37
  if Platform.cygwin?
38
- profile_path = Platform.cygwin_path(profile_path, :windows => true)
38
+ profile_path = Platform.cygwin_path(profile_path, windows: true)
39
39
  elsif Platform.windows?
40
- profile_path = profile_path.gsub("/", "\\")
40
+ profile_path = Platform.windows_path(profile_path)
41
41
  end
42
42
 
43
- ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
44
- ENV['XRE_PROFILE_PATH'] = profile_path
45
- ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
43
+ ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
44
+ ENV['XRE_PROFILE_PATH'] = profile_path
45
+ ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
46
46
  ENV['MOZ_CRASHREPORTER_DISABLE'] = '1' # disable breakpad
47
- ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
47
+ ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
48
48
 
49
- if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
50
- modify_link_library_path profile_path
51
- end
49
+ modify_link_library_path profile_path if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
52
50
 
53
51
  execute(*args)
54
- cope_with_mac_strangeness(args) if Platform.mac?
55
52
  end
56
53
 
57
54
  def quit
58
55
  return unless @process
56
+
59
57
  @process.poll_for_exit QUIT_TIMEOUT
60
58
  rescue ChildProcess::TimeoutError
61
59
  # ok, force quit
@@ -76,26 +74,12 @@ module Selenium
76
74
  private
77
75
 
78
76
  def execute(*extra_args)
79
- args = [self.class.path, "-no-remote"] + extra_args
77
+ args = [self.class.path, '-no-remote'] + extra_args
80
78
  @process = ChildProcess.build(*args)
81
- @process.io.inherit! if $DEBUG
82
- @process.start
83
- end
79
+ WebDriver.logger.debug("Executing Process #{args}")
84
80
 
85
- def cope_with_mac_strangeness(args)
86
- sleep 0.3
87
-
88
- if @process.crashed?
89
- # ok, trying a restart
90
- sleep 7
91
- execute(*args)
92
- end
93
-
94
- # ensure we're ok
95
- sleep 0.3
96
- if @process.crashed?
97
- raise Error::WebDriverError, "unable to start Firefox cleanly, args: #{args.inspect}"
98
- end
81
+ @process.io.stdout = @process.io.stderr = WebDriver.logger.io if WebDriver.logger.debug?
82
+ @process.start
99
83
  end
100
84
 
101
85
  def modify_link_library_path(profile_path)
@@ -112,11 +96,10 @@ module Selenium
112
96
  paths += ENV['LD_LIBRARY_PATH'].to_s.split(File::PATH_SEPARATOR)
113
97
 
114
98
  ENV['LD_LIBRARY_PATH'] = paths.uniq.join(File::PATH_SEPARATOR)
115
- ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
99
+ ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
116
100
  end
117
101
 
118
102
  class << self
119
-
120
103
  #
121
104
  # @api private
122
105
  #
@@ -139,15 +122,17 @@ module Selenium
139
122
  when :windows
140
123
  windows_path
141
124
  when :linux, :unix
142
- Platform.find_binary("firefox3", "firefox2", "firefox") || "/usr/bin/firefox"
125
+ Platform.find_binary('firefox3', 'firefox2', 'firefox') || '/usr/bin/firefox'
143
126
  else
144
127
  raise Error::WebDriverError, "unknown platform: #{Platform.os}"
145
128
  end
146
129
 
147
- @path = Platform.cygwin_path(@path) if Platform.cygwin?
130
+ @path = Platform.cygwin_path(@path, windows: true) if Platform.cygwin?
148
131
 
149
132
  unless File.file?(@path.to_s)
150
- raise Error::WebDriverError, "Could not find Firefox binary (os=#{Platform.os}). Make sure Firefox is installed or set the path manually with #{self}.path="
133
+ error = "Could not find Firefox binary (os=#{Platform.os}). " \
134
+ "Make sure Firefox is installed or set the path manually with #{self}.path="
135
+ raise Error::WebDriverError, error
151
136
  end
152
137
 
153
138
  @path
@@ -155,27 +140,29 @@ module Selenium
155
140
 
156
141
  def version
157
142
  @version = case Platform.os
158
- when :macosx
159
- `#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
160
- when :windows
161
- `\"#{path}\" -v | more`.strip[/[^\s]*$/][/^\d+/].to_i
162
- when :linux
163
- `#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
164
- else
165
- 0
166
- end
143
+ when :macosx
144
+ `#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
145
+ when :windows
146
+ `\"#{path}\" -v | more`.strip[/[^\s]*$/][/^\d+/].to_i
147
+ when :linux
148
+ `#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
149
+ else
150
+ 0
151
+ end
167
152
  end
168
153
 
169
154
  private
170
155
 
171
156
  def windows_path
172
- windows_registry_path || Platform.find_in_program_files("\\Mozilla Firefox\\firefox.exe") || Platform.find_binary("firefox")
157
+ windows_registry_path ||
158
+ Platform.find_in_program_files('\\Mozilla Firefox\\firefox.exe') ||
159
+ Platform.find_binary('firefox')
173
160
  end
174
161
 
175
162
  def macosx_path
176
- path = "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
177
- path = File.expand_path("~/Applications/Firefox.app/Contents/MacOS/firefox-bin") unless File.exist?(path)
178
- path = Platform.find_binary("firefox-bin") unless File.exist?(path)
163
+ path = '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
164
+ path = File.expand_path('~/Applications/Firefox.app/Contents/MacOS/firefox-bin') unless File.exist?(path)
165
+ path = Platform.find_binary('firefox-bin') unless File.exist?(path)
179
166
 
180
167
  path
181
168
  end
@@ -184,18 +171,16 @@ module Selenium
184
171
  require 'win32/registry'
185
172
 
186
173
  lm = Win32::Registry::HKEY_LOCAL_MACHINE
187
- lm.open("SOFTWARE\\Mozilla\\Mozilla Firefox") do |reg|
174
+ lm.open('SOFTWARE\\Mozilla\\Mozilla Firefox') do |reg|
188
175
  main = lm.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{reg.keys[0]}\\Main")
189
- if entry = main.find { |key, type, data| key =~ /pathtoexe/i }
190
- return entry.last
191
- end
176
+ entry = main.find { |key, _type, _data| key =~ /pathtoexe/i }
177
+ return entry.last if entry
192
178
  end
193
179
  rescue LoadError
194
180
  # older JRuby or IronRuby does not have win32/registry
195
181
  rescue Win32::Registry::Error
196
182
  end
197
183
  end # class << self
198
-
199
184
  end # Binary
200
185
  end # Firefox
201
186
  end # WebDriver
@@ -0,0 +1,50 @@
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 Firefox
23
+ module Driver
24
+ class << self
25
+
26
+ #
27
+ # Instantiates correct Firefox driver implementation
28
+ # @return [Marionette::Driver, Legacy::Driver]
29
+ #
30
+
31
+ def new(**opts)
32
+ if marionette?(opts)
33
+ Firefox::Marionette::Driver.new(opts)
34
+ else
35
+ Firefox::Legacy::Driver.new(opts)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def marionette?(opts)
42
+ opts.delete(:marionette) != false &&
43
+ (!opts[:desired_capabilities] || opts[:desired_capabilities][:marionette] != false)
44
+ end
45
+ end
46
+
47
+ end # Driver
48
+ end # Firefox
49
+ end # WebDriver
50
+ end # Selenium
@@ -29,7 +29,6 @@
29
29
  "extensions.autoDisableScopes": 10,
30
30
  "extensions.blocklist.enabled": false,
31
31
  "extensions.checkCompatibility.nightly": false,
32
- "extensions.logging.enabled": true,
33
32
  "extensions.update.enabled": false,
34
33
  "extensions.update.notifyUser": false,
35
34
  "javascript.enabled": true,
@@ -37,18 +36,8 @@
37
36
  "network.http.phishy-userpass-length": 255,
38
37
  "offline-apps.allow_by_default": true,
39
38
  "prompts.tab_modal.enabled": false,
40
- "security.csp.enable": false,
41
39
  "security.fileuri.origin_policy": 3,
42
40
  "security.fileuri.strict_origin_policy": false,
43
- "security.warn_entering_secure": false,
44
- "security.warn_entering_secure.show_once": false,
45
- "security.warn_entering_weak": false,
46
- "security.warn_entering_weak.show_once": false,
47
- "security.warn_leaving_secure": false,
48
- "security.warn_leaving_secure.show_once": false,
49
- "security.warn_submit_insecure": false,
50
- "security.warn_viewing_mixed": false,
51
- "security.warn_viewing_mixed.show_once": false,
52
41
  "signon.rememberSignons": false,
53
42
  "toolkit.networkmanager.disable": true,
54
43
  "toolkit.telemetry.prompted": 2,
@@ -64,12 +53,14 @@
64
53
  "browser.newtabpage.enabled": false,
65
54
  "browser.startup.page": 0,
66
55
  "browser.startup.homepage": "about:blank",
56
+ "browser.startup.homepage_override.mstone": "ignore",
67
57
  "browser.usedOnWindows10.introURL": "about:blank",
68
58
  "dom.max_chrome_script_run_time": 30,
69
59
  "dom.max_script_run_time": 30,
70
60
  "dom.report_all_js_exceptions": true,
71
61
  "javascript.options.showInConsole": true,
72
- "network.http.max-connections-per-server": 10,
62
+ "network.captive-portal-service.enabled": false,
63
+ "security.csp.enable": false,
73
64
  "startup.homepage_welcome_url": "about:blank",
74
65
  "startup.homepage_welcome_url.additional": "about:blank",
75
66
  "webdriver_accept_untrusted_certs": true,
@@ -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 Firefox
23
-
24
23
  #
25
24
  # @api private
26
25
  #
@@ -29,9 +28,7 @@ module Selenium
29
28
  NAMESPACE = 'http://www.mozilla.org/2004/em-rdf#'
30
29
 
31
30
  def initialize(path)
32
- unless File.exist?(path)
33
- raise Error::WebDriverError, "could not find extension at #{path.inspect}"
34
- end
31
+ raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.exist?(path)
35
32
 
36
33
  @path = path
37
34
  @should_reap_root = false
@@ -39,10 +36,10 @@ module Selenium
39
36
 
40
37
  def write_to(extensions_dir)
41
38
  root_dir = create_root
42
- ext_path = File.join extensions_dir, read_id_from_install_rdf(root_dir)
39
+ ext_path = File.join extensions_dir, read_id(root_dir)
43
40
 
44
41
  FileUtils.rm_rf ext_path
45
- FileUtils.mkdir_p File.dirname(ext_path), :mode => 0700
42
+ FileUtils.mkdir_p File.dirname(ext_path), mode: 0o700
46
43
  FileUtils.cp_r root_dir, ext_path
47
44
 
48
45
  FileReaper.reap(root_dir) if @should_reap_root
@@ -55,7 +52,7 @@ module Selenium
55
52
  @path
56
53
  else
57
54
  unless Zipper::EXTENSIONS.include? File.extname(@path)
58
- raise Error::WebDriverError, "expected #{Zipper::EXTENSIONS.join(" or ")}, got #{@path.inspect}"
55
+ raise Error::WebDriverError, "expected #{Zipper::EXTENSIONS.join(' or ')}, got #{@path.inspect}"
59
56
  end
60
57
 
61
58
  @should_reap_root = true
@@ -63,8 +60,14 @@ module Selenium
63
60
  end
64
61
  end
65
62
 
63
+ def read_id(directory)
64
+ read_id_from_install_rdf(directory) || read_id_from_manifest_json(directory)
65
+ end
66
+
66
67
  def read_id_from_install_rdf(directory)
67
- rdf_path = File.join(directory, "install.rdf")
68
+ rdf_path = File.join(directory, 'install.rdf')
69
+ return unless File.exist?(rdf_path)
70
+
68
71
  doc = REXML::Document.new(File.read(rdf_path))
69
72
  namespace = doc.root.namespaces.key(NAMESPACE)
70
73
 
@@ -79,6 +82,13 @@ module Selenium
79
82
  raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}"
80
83
  end
81
84
 
85
+ def read_id_from_manifest_json(directory)
86
+ manifest_path = File.join(directory, 'manifest.json')
87
+ return unless File.exist?(manifest_path)
88
+
89
+ manifest = JSON.parse(File.read(manifest_path))
90
+ [manifest['name'].delete(' '), manifest['version']].join('@')
91
+ end
82
92
  end # Extension
83
93
  end # Firefox
84
94
  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,10 +20,8 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Firefox
23
-
24
23
  # @api private
25
24
  class Launcher
26
-
27
25
  SOCKET_LOCK_TIMEOUT = 45
28
26
  STABLE_CONNECTION_TIMEOUT = 60
29
27
 
@@ -33,14 +31,14 @@ module Selenium
33
31
 
34
32
  raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
35
33
 
36
- if profile.kind_of? Profile
34
+ if profile.is_a? Profile
37
35
  @profile = profile
38
36
  else
39
37
  @profile_name = profile
40
38
  @profile = nil
41
39
  end
42
40
 
43
- @host = "127.0.0.1"
41
+ @host = '127.0.0.1'
44
42
  end
45
43
 
46
44
  def url
@@ -79,38 +77,34 @@ module Selenium
79
77
 
80
78
  def start
81
79
  assert_profile
82
- @binary.start_with @profile, @profile_dir, "-foreground"
80
+ @binary.start_with @profile, @profile_dir, '-foreground'
83
81
  end
84
82
 
85
83
  def connect_until_stable
86
84
  poller = SocketPoller.new(@host, @port, STABLE_CONNECTION_TIMEOUT)
87
85
 
88
- unless poller.connected?
89
- @binary.quit
90
- raise Error::WebDriverError, "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds (#{@host}:#{@port})"
91
- end
86
+ return if poller.connected?
87
+
88
+ @binary.quit
89
+ error = "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds (#{@host}:#{@port})"
90
+ raise Error::WebDriverError, error
92
91
  end
93
92
 
94
93
  def fetch_profile
95
- if @profile_name
96
- @profile = Profile.from_name @profile_name
97
-
98
- unless @profile
99
- raise Error::WebDriverError, "unable to find profile named: #{@profile_name.inspect}"
100
- end
101
- else
102
- @profile = Profile.new
103
- end
94
+ @profile = if @profile_name
95
+ Profile.from_name @profile_name
96
+ else
97
+ Profile.new
98
+ end
104
99
  end
105
100
 
106
101
  def assert_profile
107
- raise Error::WebDriverError, "must create_profile first" unless @profile && @profile_dir
102
+ raise Error::WebDriverError, 'must create_profile first' unless @profile && @profile_dir
108
103
  end
109
104
 
110
105
  def socket_lock
111
106
  @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
112
107
  end
113
-
114
108
  end # Launcher
115
109
  end # Firefox
116
110
  end # WebDriver