selenium-webdriver 2.53.4 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +363 -10
  3. data/LICENSE +1 -1
  4. data/README.md +2 -3
  5. data/lib/selenium-webdriver.rb +0 -2
  6. data/lib/selenium/server.rb +69 -70
  7. data/lib/selenium/webdriver.rb +32 -23
  8. data/lib/selenium/webdriver/atoms.rb +18 -0
  9. data/lib/selenium/webdriver/atoms/getAttribute.js +8 -0
  10. data/lib/selenium/webdriver/chrome.rb +8 -6
  11. data/lib/selenium/webdriver/chrome/driver.rb +112 -0
  12. data/lib/selenium/webdriver/chrome/options.rb +168 -0
  13. data/lib/selenium/webdriver/chrome/profile.rb +17 -17
  14. data/lib/selenium/webdriver/chrome/service.rb +22 -89
  15. data/lib/selenium/webdriver/common.rb +13 -6
  16. data/lib/selenium/webdriver/common/action_builder.rb +49 -57
  17. data/lib/selenium/webdriver/common/alert.rb +5 -15
  18. data/lib/selenium/webdriver/common/bridge_helper.rb +10 -17
  19. data/lib/selenium/webdriver/common/driver.rb +53 -68
  20. data/lib/selenium/webdriver/common/driver_extensions/{has_input_devices.rb → has_addons.rb} +13 -23
  21. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +4 -8
  22. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +4 -7
  23. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +0 -4
  24. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +0 -4
  25. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +1 -5
  26. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +0 -5
  27. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +4 -9
  28. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +7 -7
  29. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +2 -7
  30. data/lib/selenium/webdriver/common/element.rb +57 -39
  31. data/lib/selenium/webdriver/common/error.rb +204 -106
  32. data/lib/selenium/webdriver/common/file_reaper.rb +3 -11
  33. data/lib/selenium/webdriver/common/html5/local_storage.rb +6 -10
  34. data/lib/selenium/webdriver/common/html5/session_storage.rb +6 -10
  35. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +7 -18
  36. data/lib/selenium/webdriver/{safari/options.rb → common/interactions/input_device.rb} +20 -31
  37. data/lib/selenium/webdriver/common/interactions/interaction.rb +50 -0
  38. data/lib/selenium/webdriver/{safari/browser.rb → common/interactions/interactions.rb} +16 -15
  39. data/lib/selenium/webdriver/common/interactions/key_actions.rb +143 -0
  40. data/lib/selenium/webdriver/common/interactions/key_input.rb +62 -0
  41. data/lib/selenium/webdriver/{android.rb → common/interactions/none_input.rb} +11 -6
  42. data/lib/selenium/webdriver/common/interactions/pointer_actions.rb +353 -0
  43. data/lib/selenium/webdriver/common/interactions/pointer_input.rb +132 -0
  44. data/lib/selenium/webdriver/common/keyboard.rb +7 -14
  45. data/lib/selenium/webdriver/common/keys.rb +99 -82
  46. data/lib/selenium/webdriver/common/log_entry.rb +3 -6
  47. data/lib/selenium/webdriver/common/logger.rb +140 -0
  48. data/lib/selenium/webdriver/common/logs.rb +2 -6
  49. data/lib/selenium/webdriver/common/mouse.rb +9 -14
  50. data/lib/selenium/webdriver/common/navigation.rb +2 -6
  51. data/lib/selenium/webdriver/common/options.rb +20 -23
  52. data/lib/selenium/webdriver/common/platform.rb +70 -97
  53. data/lib/selenium/webdriver/common/port_prober.rb +3 -4
  54. data/lib/selenium/webdriver/common/profile_helper.rb +6 -11
  55. data/lib/selenium/webdriver/common/proxy.rb +58 -72
  56. data/lib/selenium/webdriver/common/search_context.rb +22 -29
  57. data/lib/selenium/webdriver/common/service.rb +161 -0
  58. data/lib/selenium/webdriver/common/socket_lock.rb +6 -14
  59. data/lib/selenium/webdriver/common/socket_poller.rb +5 -12
  60. data/lib/selenium/webdriver/common/target_locator.rb +11 -15
  61. data/lib/selenium/webdriver/common/timeouts.rb +4 -8
  62. data/lib/selenium/webdriver/common/touch_action_builder.rb +2 -6
  63. data/lib/selenium/webdriver/common/touch_screen.rb +19 -23
  64. data/lib/selenium/webdriver/common/w3c_action_builder.rb +209 -0
  65. data/lib/selenium/webdriver/{phantomjs.rb → common/w3c_options.rb} +16 -14
  66. data/lib/selenium/webdriver/common/wait.rb +6 -13
  67. data/lib/selenium/webdriver/common/window.rb +48 -17
  68. data/lib/selenium/webdriver/common/zipper.rb +6 -10
  69. data/lib/selenium/webdriver/edge.rb +5 -12
  70. data/lib/selenium/webdriver/edge/bridge.rb +32 -63
  71. data/lib/selenium/webdriver/edge/driver.rb +73 -0
  72. data/lib/selenium/webdriver/edge/service.rb +18 -87
  73. data/lib/selenium/webdriver/firefox.rb +20 -11
  74. data/lib/selenium/webdriver/firefox/binary.rb +40 -56
  75. data/lib/selenium/webdriver/firefox/driver.rb +48 -0
  76. data/lib/selenium/webdriver/firefox/extension.rb +18 -8
  77. data/lib/selenium/webdriver/firefox/extension/prefs.json +3 -11
  78. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  79. data/lib/selenium/webdriver/firefox/launcher.rb +13 -22
  80. data/lib/selenium/webdriver/firefox/legacy/driver.rb +79 -0
  81. data/lib/selenium/webdriver/{iphone.rb → firefox/marionette/bridge.rb} +25 -6
  82. data/lib/selenium/webdriver/firefox/marionette/driver.rb +96 -0
  83. data/lib/selenium/webdriver/firefox/options.rb +149 -0
  84. data/lib/selenium/webdriver/firefox/profile.rb +46 -46
  85. data/lib/selenium/webdriver/firefox/profiles_ini.rb +8 -18
  86. data/lib/selenium/webdriver/firefox/service.rb +23 -83
  87. data/lib/selenium/webdriver/firefox/util.rb +0 -4
  88. data/lib/selenium/webdriver/ie.rb +4 -8
  89. data/lib/selenium/webdriver/ie/driver.rb +90 -0
  90. data/lib/selenium/webdriver/ie/options.rb +136 -0
  91. data/lib/selenium/webdriver/ie/service.rb +58 -0
  92. data/lib/selenium/webdriver/remote.rb +8 -16
  93. data/lib/selenium/webdriver/remote/bridge.rb +96 -565
  94. data/lib/selenium/webdriver/remote/capabilities.rb +76 -94
  95. data/lib/selenium/webdriver/remote/driver.rb +49 -0
  96. data/lib/selenium/webdriver/remote/http/common.rb +22 -20
  97. data/lib/selenium/webdriver/remote/http/curb.rb +9 -12
  98. data/lib/selenium/webdriver/remote/http/default.rb +54 -41
  99. data/lib/selenium/webdriver/remote/http/persistent.rb +9 -8
  100. data/lib/selenium/webdriver/remote/oss/bridge.rb +586 -0
  101. data/lib/selenium/webdriver/remote/oss/commands.rb +221 -0
  102. data/lib/selenium/webdriver/remote/response.rb +39 -27
  103. data/lib/selenium/webdriver/remote/server_error.rb +1 -5
  104. data/lib/selenium/webdriver/remote/w3c/bridge.rb +573 -0
  105. data/lib/selenium/webdriver/remote/w3c/capabilities.rb +290 -0
  106. data/lib/selenium/webdriver/remote/w3c/commands.rb +148 -0
  107. data/lib/selenium/webdriver/safari.rb +20 -29
  108. data/lib/selenium/webdriver/{firefox/w3c_bridge.rb → safari/driver.rb} +21 -30
  109. data/lib/selenium/webdriver/safari/service.rb +57 -0
  110. data/lib/selenium/webdriver/support.rb +1 -2
  111. data/lib/selenium/webdriver/support/abstract_event_listener.rb +17 -4
  112. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -5
  113. data/lib/selenium/webdriver/support/color.rb +57 -42
  114. data/lib/selenium/webdriver/support/escaper.rb +41 -0
  115. data/lib/selenium/webdriver/support/event_firing_bridge.rb +36 -40
  116. data/lib/selenium/webdriver/support/select.rb +33 -86
  117. data/selenium-webdriver.gemspec +22 -25
  118. metadata +254 -261
  119. data/lib/selenium-client.rb +0 -21
  120. data/lib/selenium/client.rb +0 -57
  121. data/lib/selenium/client/base.rb +0 -151
  122. data/lib/selenium/client/driver.rb +0 -29
  123. data/lib/selenium/client/errors.rb +0 -28
  124. data/lib/selenium/client/extensions.rb +0 -132
  125. data/lib/selenium/client/idiomatic.rb +0 -507
  126. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  127. data/lib/selenium/client/javascript_frameworks/jquery.rb +0 -32
  128. data/lib/selenium/client/javascript_frameworks/prototype.rb +0 -32
  129. data/lib/selenium/client/legacy_driver.rb +0 -1722
  130. data/lib/selenium/client/protocol.rb +0 -123
  131. data/lib/selenium/client/selenium_helper.rb +0 -49
  132. data/lib/selenium/rake/server_task.rb +0 -176
  133. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  134. data/lib/selenium/webdriver/chrome/bridge.rb +0 -139
  135. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  136. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  137. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  138. data/lib/selenium/webdriver/common/w3c_error.rb +0 -194
  139. data/lib/selenium/webdriver/edge/legacy_support.rb +0 -117
  140. data/lib/selenium/webdriver/firefox/bridge.rb +0 -89
  141. data/lib/selenium/webdriver/ie/bridge.rb +0 -88
  142. data/lib/selenium/webdriver/ie/server.rb +0 -133
  143. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
  144. data/lib/selenium/webdriver/phantomjs/bridge.rb +0 -78
  145. data/lib/selenium/webdriver/phantomjs/service.rb +0 -130
  146. data/lib/selenium/webdriver/remote/commands.rb +0 -211
  147. data/lib/selenium/webdriver/remote/w3c_bridge.rb +0 -668
  148. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +0 -236
  149. data/lib/selenium/webdriver/remote/w3c_commands.rb +0 -132
  150. data/lib/selenium/webdriver/safari/bridge.rb +0 -135
  151. data/lib/selenium/webdriver/safari/resources/client.js +0 -7255
  152. data/lib/selenium/webdriver/safari/server.rb +0 -187
@@ -0,0 +1,73 @@
1
+ # Licensed to the Software Freedom Conservancy (SFC) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The SFC licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Selenium
19
+ module WebDriver
20
+ module Edge
21
+
22
+ #
23
+ # Driver implementation for Microsoft Edge.
24
+ # @api private
25
+ #
26
+
27
+ class Driver < WebDriver::Driver
28
+ include DriverExtensions::TakesScreenshot
29
+
30
+ def initialize(opts = {})
31
+ opts[:desired_capabilities] ||= Remote::W3C::Capabilities.edge
32
+
33
+ unless opts.key?(:url)
34
+ driver_path = opts.delete(:driver_path) || Edge.driver_path
35
+ driver_opts = opts.delete(:driver_opts) || {}
36
+ port = opts.delete(:port) || Service::DEFAULT_PORT
37
+
38
+ @service = Service.new(driver_path, port, driver_opts)
39
+ @service.host = 'localhost' if @service.host == '127.0.0.1'
40
+ @service.start
41
+ opts[:url] = @service.uri
42
+ end
43
+
44
+ listener = opts.delete(:listener)
45
+
46
+ # Edge is mostly using W3C dialect, but a request to
47
+ # create session responds with OSS-like body,
48
+ # so we need to force W3C implementation.
49
+ desired_capabilities = opts.delete(:desired_capabilities)
50
+ bridge = Remote::Bridge.new(opts)
51
+ capabilities = bridge.create_session(desired_capabilities)
52
+
53
+ WebDriver.logger.info 'Forcing W3C dialect.'
54
+ @bridge = Remote::W3C::Bridge.new(capabilities, bridge.session_id, opts)
55
+ @bridge.extend Edge::Bridge
56
+
57
+ super(@bridge, listener: listener)
58
+ end
59
+
60
+ def browser
61
+ :edge
62
+ end
63
+
64
+ def quit
65
+ super
66
+ ensure
67
+ @service.stop if @service
68
+ end
69
+
70
+ end # Driver
71
+ end # Edge
72
+ end # WebDriver
73
+ end # Selenium
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
2
  # or more contributor license agreements. See the NOTICE file
5
3
  # distributed with this work for additional information
@@ -20,104 +18,37 @@
20
18
  module Selenium
21
19
  module WebDriver
22
20
  module Edge
23
-
24
21
  #
25
22
  # @api private
26
23
  #
27
24
 
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
52
- 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
25
+ class Service < WebDriver::Service
26
+ DEFAULT_PORT = 17556
27
+ @executable = 'MicrosoftWebDriver'.freeze
28
+ @missing_text = <<-ERROR.gsub(/\n +| {2,}/, ' ').freeze
29
+ Unable to find MicrosoftWebDriver. Please download the server from
30
+ https://www.microsoft.com/en-us/download/details.aspx?id=48212 and place it somewhere on your PATH.
31
+ More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver.
32
+ ERROR
66
33
 
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
34
+ private
94
35
 
95
36
  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
37
+ @process = build_process(@executable_path, "--port=#{@port}", *@extra_args)
100
38
  @process.start
101
39
  end
102
40
 
103
- def stop_process
104
- @process.poll_for_exit STOP_TIMEOUT
105
- rescue ChildProcess::TimeoutError
106
- @process.stop STOP_TIMEOUT
41
+ def cannot_connect_error_text
42
+ "unable to connect to MicrosoftWebDriver #{@host}:#{@port}"
107
43
  end
108
44
 
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
45
+ def extract_service_args(driver_opts)
46
+ driver_args = super
47
+ driver_args << "–host=#{driver_opts[:host]}" if driver_opts.key? :host
48
+ driver_args << "–package=#{driver_opts[:package]}" if driver_opts.key? :package
49
+ driver_args << "-verbose" if driver_opts[:verbose] == true
50
+ driver_args
115
51
  end
116
-
117
- def socket_lock
118
- @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
119
- end
120
-
121
52
  end # Service
122
53
  end # Edge
123
54
  end # WebDriver
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
2
  # or more contributor license agreements. See the NOTICE file
5
3
  # distributed with this work for additional information
@@ -21,31 +19,42 @@ require 'timeout'
21
19
  require 'socket'
22
20
  require 'rexml/document'
23
21
 
22
+ require 'selenium/webdriver/firefox/driver'
23
+
24
24
  require 'selenium/webdriver/firefox/util'
25
25
  require 'selenium/webdriver/firefox/extension'
26
26
  require 'selenium/webdriver/firefox/binary'
27
27
  require 'selenium/webdriver/firefox/profiles_ini'
28
28
  require 'selenium/webdriver/firefox/profile'
29
29
  require 'selenium/webdriver/firefox/launcher'
30
- require 'selenium/webdriver/firefox/bridge'
31
- require 'selenium/webdriver/firefox/w3c_bridge'
32
- require 'selenium/webdriver/firefox/binary'
30
+ require 'selenium/webdriver/firefox/legacy/driver'
31
+
32
+ require 'selenium/webdriver/firefox/marionette/bridge'
33
+ require 'selenium/webdriver/firefox/marionette/driver'
34
+ require 'selenium/webdriver/firefox/options'
33
35
  require 'selenium/webdriver/firefox/service'
34
36
 
35
37
  module Selenium
36
38
  module WebDriver
37
39
  module Firefox
38
-
39
- DEFAULT_PORT = 7055
40
- DEFAULT_ENABLE_NATIVE_EVENTS = Platform.os == :windows
41
- DEFAULT_SECURE_SSL = false
40
+ DEFAULT_PORT = 7055
41
+ DEFAULT_ENABLE_NATIVE_EVENTS = Platform.os == :windows
42
+ DEFAULT_SECURE_SSL = false
42
43
  DEFAULT_ASSUME_UNTRUSTED_ISSUER = true
43
- DEFAULT_LOAD_NO_FOCUS_LIB = false
44
+ DEFAULT_LOAD_NO_FOCUS_LIB = false
45
+
46
+ def self.driver_path=(path)
47
+ Platform.assert_executable path
48
+ @driver_path = path
49
+ end
50
+
51
+ def self.driver_path
52
+ @driver_path ||= nil
53
+ end
44
54
 
45
55
  def self.path=(path)
46
56
  Binary.path = path
47
57
  end
48
-
49
58
  end # Firefox
50
59
  end # WebDriver
51
60
  end # Selenium
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # Licensed to the Software Freedom Conservancy (SFC) under one
4
2
  # or more contributor license agreements. See the NOTICE file
5
3
  # distributed with this work for additional information
@@ -20,38 +18,37 @@
20
18
  module Selenium
21
19
  module WebDriver
22
20
  module Firefox
23
-
24
21
  # @api private
25
22
  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
- ]
23
+ NO_FOCUS_LIBRARY_NAME = 'x_ignore_nofocus.so'.freeze
24
+ NO_FOCUS_LIBRARIES = [
25
+ ["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/amd64/#{NO_FOCUS_LIBRARY_NAME}",
26
+ "amd64/#{NO_FOCUS_LIBRARY_NAME}"],
27
+ ["#{WebDriver.root}/selenium/webdriver/firefox/native/linux/x86/#{NO_FOCUS_LIBRARY_NAME}",
28
+ "x86/#{NO_FOCUS_LIBRARY_NAME}"]
29
+ ].freeze
32
30
 
33
31
  WAIT_TIMEOUT = 90
34
32
  QUIT_TIMEOUT = 5
35
33
 
36
34
  def start_with(profile, profile_path, *args)
37
35
  if Platform.cygwin?
38
- profile_path = Platform.cygwin_path(profile_path, :windows => true)
36
+ profile_path = Platform.cygwin_path(profile_path, windows: true)
39
37
  elsif Platform.windows?
40
- profile_path = profile_path.gsub("/", "\\")
38
+ profile_path = profile_path.tr('/', '\\')
41
39
  end
42
40
 
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
41
+ ENV['XRE_CONSOLE_LOG'] = profile.log_file if profile.log_file
42
+ ENV['XRE_PROFILE_PATH'] = profile_path
43
+ ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
46
44
  ENV['MOZ_CRASHREPORTER_DISABLE'] = '1' # disable breakpad
47
- ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
45
+ ENV['NO_EM_RESTART'] = '1' # prevent the binary from detaching from the console
48
46
 
49
47
  if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
50
48
  modify_link_library_path profile_path
51
49
  end
52
50
 
53
51
  execute(*args)
54
- cope_with_mac_strangeness(args) if Platform.mac?
55
52
  end
56
53
 
57
54
  def quit
@@ -76,26 +73,12 @@ module Selenium
76
73
  private
77
74
 
78
75
  def execute(*extra_args)
79
- args = [self.class.path, "-no-remote"] + extra_args
76
+ args = [self.class.path, '-no-remote'] + extra_args
80
77
  @process = ChildProcess.build(*args)
81
- @process.io.inherit! if $DEBUG
82
- @process.start
83
- end
84
-
85
- def cope_with_mac_strangeness(args)
86
- sleep 0.3
78
+ WebDriver.logger.debug("Executing Process #{args}")
87
79
 
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
80
+ @process.io.stdout = @process.io.stderr = WebDriver.logger.io if WebDriver.logger.debug?
81
+ @process.start
99
82
  end
100
83
 
101
84
  def modify_link_library_path(profile_path)
@@ -112,11 +95,10 @@ module Selenium
112
95
  paths += ENV['LD_LIBRARY_PATH'].to_s.split(File::PATH_SEPARATOR)
113
96
 
114
97
  ENV['LD_LIBRARY_PATH'] = paths.uniq.join(File::PATH_SEPARATOR)
115
- ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
98
+ ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
116
99
  end
117
100
 
118
101
  class << self
119
-
120
102
  #
121
103
  # @api private
122
104
  #
@@ -139,7 +121,7 @@ module Selenium
139
121
  when :windows
140
122
  windows_path
141
123
  when :linux, :unix
142
- Platform.find_binary("firefox3", "firefox2", "firefox") || "/usr/bin/firefox"
124
+ Platform.find_binary('firefox3', 'firefox2', 'firefox') || '/usr/bin/firefox'
143
125
  else
144
126
  raise Error::WebDriverError, "unknown platform: #{Platform.os}"
145
127
  end
@@ -147,7 +129,9 @@ module Selenium
147
129
  @path = Platform.cygwin_path(@path) if Platform.cygwin?
148
130
 
149
131
  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="
132
+ error = "Could not find Firefox binary (os=#{Platform.os}). "
133
+ error << "Make sure Firefox is installed or set the path manually with #{self}.path="
134
+ raise Error::WebDriverError, error
151
135
  end
152
136
 
153
137
  @path
@@ -155,27 +139,29 @@ module Selenium
155
139
 
156
140
  def version
157
141
  @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
142
+ when :macosx
143
+ `#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
144
+ when :windows
145
+ `\"#{path}\" -v | more`.strip[/[^\s]*$/][/^\d+/].to_i
146
+ when :linux
147
+ `#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
148
+ else
149
+ 0
150
+ end
167
151
  end
168
152
 
169
153
  private
170
154
 
171
155
  def windows_path
172
- windows_registry_path || Platform.find_in_program_files("\\Mozilla Firefox\\firefox.exe") || Platform.find_binary("firefox")
156
+ windows_registry_path ||
157
+ Platform.find_in_program_files('\\Mozilla Firefox\\firefox.exe') ||
158
+ Platform.find_binary('firefox')
173
159
  end
174
160
 
175
161
  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)
162
+ path = '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
163
+ path = File.expand_path('~/Applications/Firefox.app/Contents/MacOS/firefox-bin') unless File.exist?(path)
164
+ path = Platform.find_binary('firefox-bin') unless File.exist?(path)
179
165
 
180
166
  path
181
167
  end
@@ -184,18 +170,16 @@ module Selenium
184
170
  require 'win32/registry'
185
171
 
186
172
  lm = Win32::Registry::HKEY_LOCAL_MACHINE
187
- lm.open("SOFTWARE\\Mozilla\\Mozilla Firefox") do |reg|
173
+ lm.open('SOFTWARE\\Mozilla\\Mozilla Firefox') do |reg|
188
174
  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
175
+ entry = main.find { |key, _type, _data| key =~ /pathtoexe/i }
176
+ return entry.last if entry
192
177
  end
193
178
  rescue LoadError
194
179
  # older JRuby or IronRuby does not have win32/registry
195
180
  rescue Win32::Registry::Error
196
181
  end
197
182
  end # class << self
198
-
199
183
  end # Binary
200
184
  end # Firefox
201
185
  end # WebDriver
@@ -0,0 +1,48 @@
1
+ # Licensed to the Software Freedom Conservancy (SFC) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The SFC licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Selenium
19
+ module WebDriver
20
+ module Firefox
21
+ module Driver
22
+ class << self
23
+
24
+ #
25
+ # Instantiates correct Firefox driver implementation
26
+ # @return [Marionette::Driver, Legacy::Driver]
27
+ #
28
+
29
+ def new(**opts)
30
+ if marionette?(opts)
31
+ Firefox::Marionette::Driver.new(opts)
32
+ else
33
+ Firefox::Legacy::Driver.new(opts)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def marionette?(opts)
40
+ opts.delete(:marionette) != false &&
41
+ (!opts[:desired_capabilities] || opts[:desired_capabilities][:marionette] != false)
42
+ end
43
+ end
44
+
45
+ end # Driver
46
+ end # Firefox
47
+ end # WebDriver
48
+ end # Selenium