selenium-webdriver 2.53.4 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +24 -18
  2. data/README.md +2 -3
  3. data/lib/selenium/server.rb +64 -68
  4. data/lib/selenium/webdriver.rb +5 -9
  5. data/lib/selenium/webdriver/chrome.rb +18 -3
  6. data/lib/selenium/webdriver/chrome/bridge.rb +13 -16
  7. data/lib/selenium/webdriver/chrome/profile.rb +7 -9
  8. data/lib/selenium/webdriver/chrome/service.rb +8 -84
  9. data/lib/selenium/webdriver/common.rb +1 -2
  10. data/lib/selenium/webdriver/common/action_builder.rb +28 -38
  11. data/lib/selenium/webdriver/common/alert.rb +7 -10
  12. data/lib/selenium/webdriver/common/bridge_helper.rb +10 -15
  13. data/lib/selenium/webdriver/common/driver.rb +19 -28
  14. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +0 -3
  15. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +4 -6
  16. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +4 -5
  17. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +0 -2
  18. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +0 -2
  19. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +0 -2
  20. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +0 -3
  21. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +3 -6
  22. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -5
  23. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +2 -5
  24. data/lib/selenium/webdriver/common/element.rb +27 -29
  25. data/lib/selenium/webdriver/common/error.rb +17 -20
  26. data/lib/selenium/webdriver/common/file_reaper.rb +3 -9
  27. data/lib/selenium/webdriver/common/html5/local_storage.rb +6 -8
  28. data/lib/selenium/webdriver/common/html5/session_storage.rb +6 -8
  29. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +6 -15
  30. data/lib/selenium/webdriver/common/keyboard.rb +7 -12
  31. data/lib/selenium/webdriver/common/keys.rb +67 -69
  32. data/lib/selenium/webdriver/common/log_entry.rb +3 -4
  33. data/lib/selenium/webdriver/common/logs.rb +2 -4
  34. data/lib/selenium/webdriver/common/mouse.rb +9 -12
  35. data/lib/selenium/webdriver/common/navigation.rb +2 -4
  36. data/lib/selenium/webdriver/common/options.rb +16 -19
  37. data/lib/selenium/webdriver/common/platform.rb +61 -90
  38. data/lib/selenium/webdriver/common/port_prober.rb +1 -2
  39. data/lib/selenium/webdriver/common/profile_helper.rb +5 -8
  40. data/lib/selenium/webdriver/common/proxy.rb +58 -70
  41. data/lib/selenium/webdriver/common/search_context.rb +15 -19
  42. data/lib/selenium/webdriver/common/service.rb +127 -0
  43. data/lib/selenium/webdriver/common/socket_lock.rb +5 -11
  44. data/lib/selenium/webdriver/common/socket_poller.rb +4 -9
  45. data/lib/selenium/webdriver/common/target_locator.rb +11 -13
  46. data/lib/selenium/webdriver/common/timeouts.rb +4 -6
  47. data/lib/selenium/webdriver/common/touch_action_builder.rb +2 -4
  48. data/lib/selenium/webdriver/common/touch_screen.rb +15 -18
  49. data/lib/selenium/webdriver/common/w3c_error.rb +3 -6
  50. data/lib/selenium/webdriver/common/wait.rb +6 -11
  51. data/lib/selenium/webdriver/common/window.rb +12 -15
  52. data/lib/selenium/webdriver/common/zipper.rb +6 -8
  53. data/lib/selenium/webdriver/edge.rb +18 -3
  54. data/lib/selenium/webdriver/edge/bridge.rb +11 -16
  55. data/lib/selenium/webdriver/edge/legacy_support.rb +38 -39
  56. data/lib/selenium/webdriver/edge/service.rb +8 -82
  57. data/lib/selenium/webdriver/firefox.rb +25 -6
  58. data/lib/selenium/webdriver/firefox/binary.rb +37 -53
  59. data/lib/selenium/webdriver/firefox/bridge.rb +3 -6
  60. data/lib/selenium/webdriver/firefox/extension.rb +4 -6
  61. data/lib/selenium/webdriver/firefox/extension/prefs.json +1 -10
  62. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  63. data/lib/selenium/webdriver/firefox/launcher.rb +8 -11
  64. data/lib/selenium/webdriver/firefox/profile.rb +40 -42
  65. data/lib/selenium/webdriver/firefox/profiles_ini.rb +8 -15
  66. data/lib/selenium/webdriver/firefox/service.rb +23 -79
  67. data/lib/selenium/webdriver/firefox/util.rb +0 -2
  68. data/lib/selenium/webdriver/firefox/w3c_bridge.rb +2 -4
  69. data/lib/selenium/webdriver/ie.rb +16 -7
  70. data/lib/selenium/webdriver/ie/bridge.rb +16 -23
  71. data/lib/selenium/webdriver/{iphone.rb → ie/service.rb} +26 -4
  72. data/lib/selenium/webdriver/phantomjs.rb +8 -3
  73. data/lib/selenium/webdriver/phantomjs/bridge.rb +9 -11
  74. data/lib/selenium/webdriver/phantomjs/service.rb +17 -81
  75. data/lib/selenium/webdriver/remote.rb +0 -2
  76. data/lib/selenium/webdriver/remote/bridge.rb +193 -191
  77. data/lib/selenium/webdriver/remote/capabilities.rb +60 -90
  78. data/lib/selenium/webdriver/remote/commands.rb +197 -192
  79. data/lib/selenium/webdriver/remote/http/common.rb +15 -13
  80. data/lib/selenium/webdriver/remote/http/curb.rb +5 -9
  81. data/lib/selenium/webdriver/remote/http/default.rb +32 -37
  82. data/lib/selenium/webdriver/remote/http/persistent.rb +4 -6
  83. data/lib/selenium/webdriver/remote/response.rb +13 -21
  84. data/lib/selenium/webdriver/remote/server_error.rb +1 -3
  85. data/lib/selenium/webdriver/remote/w3c_bridge.rb +200 -195
  86. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +38 -46
  87. data/lib/selenium/webdriver/remote/w3c_commands.rb +116 -113
  88. data/lib/selenium/webdriver/safari.rb +23 -7
  89. data/lib/selenium/{client/javascript_frameworks/jquery.rb → webdriver/safari/apple_bridge.rb} +28 -9
  90. data/lib/selenium/webdriver/safari/browser.rb +0 -2
  91. data/lib/selenium/webdriver/safari/{bridge.rb → legacy_bridge.rb} +12 -9
  92. data/lib/selenium/webdriver/safari/options.rb +3 -4
  93. data/lib/selenium/webdriver/safari/resources/client.js +56 -7255
  94. data/lib/selenium/webdriver/safari/server.rb +18 -24
  95. data/lib/selenium/{client/javascript_frameworks/prototype.rb → webdriver/safari/service.rb} +27 -9
  96. data/lib/selenium/webdriver/support.rb +1 -0
  97. data/lib/selenium/webdriver/support/abstract_event_listener.rb +17 -2
  98. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -3
  99. data/lib/selenium/webdriver/support/color.rb +55 -38
  100. data/lib/selenium/webdriver/{android.rb → support/escaper.rb} +19 -4
  101. data/lib/selenium/webdriver/support/event_firing_bridge.rb +36 -38
  102. data/lib/selenium/webdriver/support/select.rb +33 -84
  103. data/selenium-webdriver.gemspec +23 -23
  104. metadata +19 -30
  105. data/lib/selenium-client.rb +0 -21
  106. data/lib/selenium/client.rb +0 -57
  107. data/lib/selenium/client/base.rb +0 -151
  108. data/lib/selenium/client/driver.rb +0 -29
  109. data/lib/selenium/client/errors.rb +0 -28
  110. data/lib/selenium/client/extensions.rb +0 -132
  111. data/lib/selenium/client/idiomatic.rb +0 -507
  112. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  113. data/lib/selenium/client/legacy_driver.rb +0 -1722
  114. data/lib/selenium/client/protocol.rb +0 -123
  115. data/lib/selenium/client/selenium_helper.rb +0 -49
  116. data/lib/selenium/rake/server_task.rb +0 -176
  117. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  118. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  119. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  120. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  121. data/lib/selenium/webdriver/ie/server.rb +0 -133
  122. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
@@ -20,38 +20,37 @@
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'.freeze
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 = profile_path.tr('/', '\\')
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
49
  if Platform.linux? && (profile.native_events? || profile.load_no_focus_lib?)
50
50
  modify_link_library_path profile_path
51
51
  end
52
52
 
53
53
  execute(*args)
54
- cope_with_mac_strangeness(args) if Platform.mac?
55
54
  end
56
55
 
57
56
  def quit
@@ -76,28 +75,12 @@ module Selenium
76
75
  private
77
76
 
78
77
  def execute(*extra_args)
79
- args = [self.class.path, "-no-remote"] + extra_args
78
+ args = [self.class.path, '-no-remote'] + extra_args
80
79
  @process = ChildProcess.build(*args)
81
80
  @process.io.inherit! if $DEBUG
82
81
  @process.start
83
82
  end
84
83
 
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
99
- end
100
-
101
84
  def modify_link_library_path(profile_path)
102
85
  paths = []
103
86
 
@@ -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
@@ -20,10 +20,8 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Firefox
23
-
24
23
  # @api private
25
24
  class Bridge < Remote::Bridge
26
-
27
25
  def initialize(opts = {})
28
26
  port = opts.delete(:port) || DEFAULT_PORT
29
27
  profile = opts.delete(:profile)
@@ -45,11 +43,11 @@ module Selenium
45
43
  caps.proxy = proxy if proxy
46
44
 
47
45
  remote_opts = {
48
- :url => @launcher.url,
49
- :desired_capabilities => caps
46
+ url: @launcher.url,
47
+ desired_capabilities: caps
50
48
  }
51
49
 
52
- remote_opts.merge!(:http_client => http_client) if http_client
50
+ remote_opts[:http_client] = http_client if http_client
53
51
 
54
52
  begin
55
53
  super(remote_opts)
@@ -82,7 +80,6 @@ module Selenium
82
80
  def create_launcher(port, profile)
83
81
  Launcher.new Binary.new, port, profile
84
82
  end
85
-
86
83
  end # Bridge
87
84
  end # Firefox
88
85
  end # WebDriver
@@ -20,13 +20,12 @@
20
20
  module Selenium
21
21
  module WebDriver
22
22
  module Firefox
23
-
24
23
  #
25
24
  # @api private
26
25
  #
27
26
 
28
27
  class Extension
29
- NAMESPACE = 'http://www.mozilla.org/2004/em-rdf#'
28
+ NAMESPACE = 'http://www.mozilla.org/2004/em-rdf#'.freeze
30
29
 
31
30
  def initialize(path)
32
31
  unless File.exist?(path)
@@ -42,7 +41,7 @@ module Selenium
42
41
  ext_path = File.join extensions_dir, read_id_from_install_rdf(root_dir)
43
42
 
44
43
  FileUtils.rm_rf ext_path
45
- FileUtils.mkdir_p File.dirname(ext_path), :mode => 0700
44
+ FileUtils.mkdir_p File.dirname(ext_path), mode: 0700
46
45
  FileUtils.cp_r root_dir, ext_path
47
46
 
48
47
  FileReaper.reap(root_dir) if @should_reap_root
@@ -55,7 +54,7 @@ module Selenium
55
54
  @path
56
55
  else
57
56
  unless Zipper::EXTENSIONS.include? File.extname(@path)
58
- raise Error::WebDriverError, "expected #{Zipper::EXTENSIONS.join(" or ")}, got #{@path.inspect}"
57
+ raise Error::WebDriverError, "expected #{Zipper::EXTENSIONS.join(' or ')}, got #{@path.inspect}"
59
58
  end
60
59
 
61
60
  @should_reap_root = true
@@ -64,7 +63,7 @@ module Selenium
64
63
  end
65
64
 
66
65
  def read_id_from_install_rdf(directory)
67
- rdf_path = File.join(directory, "install.rdf")
66
+ rdf_path = File.join(directory, 'install.rdf')
68
67
  doc = REXML::Document.new(File.read(rdf_path))
69
68
  namespace = doc.root.namespaces.key(NAMESPACE)
70
69
 
@@ -78,7 +77,6 @@ module Selenium
78
77
 
79
78
  raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}"
80
79
  end
81
-
82
80
  end # Extension
83
81
  end # Firefox
84
82
  end # WebDriver
@@ -40,15 +40,6 @@
40
40
  "security.csp.enable": false,
41
41
  "security.fileuri.origin_policy": 3,
42
42
  "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
43
  "signon.rememberSignons": false,
53
44
  "toolkit.networkmanager.disable": true,
54
45
  "toolkit.telemetry.prompted": 2,
@@ -64,12 +55,12 @@
64
55
  "browser.newtabpage.enabled": false,
65
56
  "browser.startup.page": 0,
66
57
  "browser.startup.homepage": "about:blank",
58
+ "browser.startup.homepage_override.mstone": "ignore",
67
59
  "browser.usedOnWindows10.introURL": "about:blank",
68
60
  "dom.max_chrome_script_run_time": 30,
69
61
  "dom.max_script_run_time": 30,
70
62
  "dom.report_all_js_exceptions": true,
71
63
  "javascript.options.showInConsole": true,
72
- "network.http.max-connections-per-server": 10,
73
64
  "startup.homepage_welcome_url": "about:blank",
74
65
  "startup.homepage_welcome_url.additional": "about:blank",
75
66
  "webdriver_accept_untrusted_certs": true,
@@ -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,16 +77,16 @@ 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
+ @binary.quit
88
+ error = "unable to obtain stable firefox connection in #{STABLE_CONNECTION_TIMEOUT} seconds (#{@host}:#{@port})"
89
+ raise Error::WebDriverError, error
92
90
  end
93
91
 
94
92
  def fetch_profile
@@ -104,13 +102,12 @@ module Selenium
104
102
  end
105
103
 
106
104
  def assert_profile
107
- raise Error::WebDriverError, "must create_profile first" unless @profile && @profile_dir
105
+ raise Error::WebDriverError, 'must create_profile first' unless @profile && @profile_dir
108
106
  end
109
107
 
110
108
  def socket_lock
111
109
  @socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT)
112
110
  end
113
-
114
111
  end # Launcher
115
112
  end # Firefox
116
113
  end # WebDriver
@@ -23,15 +23,15 @@ module Selenium
23
23
  class Profile
24
24
  include ProfileHelper
25
25
 
26
- VALID_PREFERENCE_TYPES = [TrueClass, FalseClass, Integer, Float, String]
26
+ VALID_PREFERENCE_TYPES = [TrueClass, FalseClass, Integer, Float, String].freeze
27
27
  WEBDRIVER_EXTENSION_PATH = File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/webdriver.xpi")
28
28
  WEBDRIVER_PREFS = {
29
- :native_events => 'webdriver_enable_native_events',
30
- :untrusted_certs => 'webdriver_accept_untrusted_certs',
31
- :untrusted_issuer => 'webdriver_assume_untrusted_issuer',
32
- :port => 'webdriver_firefox_port',
33
- :log_file => 'webdriver.log.file'
34
- }
29
+ native_events: 'webdriver_enable_native_events',
30
+ untrusted_certs: 'webdriver_accept_untrusted_certs',
31
+ untrusted_issuer: 'webdriver_assume_untrusted_issuer',
32
+ port: 'webdriver_firefox_port',
33
+ log_file: 'webdriver.log.file'
34
+ }.freeze
35
35
 
36
36
  attr_reader :name, :log_file
37
37
  attr_writer :secure_ssl, :native_events, :load_no_focus_lib
@@ -78,18 +78,19 @@ module Selenium
78
78
  @additional_prefs = {}
79
79
  else
80
80
  # TODO: clean this up
81
- @native_events = model_prefs.delete(WEBDRIVER_PREFS[:native_events]) == "true"
82
- @secure_ssl = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_certs]) != "true"
83
- @untrusted_issuer = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_issuer]) == "true"
84
- @load_no_focus_lib = model_prefs.delete(WEBDRIVER_PREFS[:load_no_focus_lib]) == "true" # not stored in profile atm, so will always be false.
81
+ @native_events = model_prefs.delete(WEBDRIVER_PREFS[:native_events]) == 'true'
82
+ @secure_ssl = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_certs]) != 'true'
83
+ @untrusted_issuer = model_prefs.delete(WEBDRIVER_PREFS[:untrusted_issuer]) == 'true'
84
+ # not stored in profile atm, so will always be false.
85
+ @load_no_focus_lib = model_prefs.delete(WEBDRIVER_PREFS[:load_no_focus_lib]) == 'true'
85
86
  @additional_prefs = model_prefs
86
87
  end
87
88
 
88
- @extensions = {}
89
+ @extensions = {}
89
90
  end
90
91
 
91
92
  def layout_on_disk
92
- profile_dir = @model ? create_tmp_copy(@model) : Dir.mktmpdir("webdriver-profile")
93
+ profile_dir = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-profile')
93
94
  FileReaper << profile_dir
94
95
 
95
96
  install_extensions(profile_dir)
@@ -100,7 +101,6 @@ module Selenium
100
101
  profile_dir
101
102
  end
102
103
 
103
-
104
104
  #
105
105
  # Set a preference for this particular profile.
106
106
  #
@@ -109,11 +109,11 @@ module Selenium
109
109
  #
110
110
 
111
111
  def []=(key, value)
112
- unless VALID_PREFERENCE_TYPES.any? { |e| value.kind_of? e }
112
+ unless VALID_PREFERENCE_TYPES.any? { |e| value.is_a? e }
113
113
  raise TypeError, "expected one of #{VALID_PREFERENCE_TYPES.inspect}, got #{value.inspect}:#{value.class}"
114
114
  end
115
115
 
116
- if value.kind_of?(String) && Util.stringified?(value)
116
+ if value.is_a?(String) && Util.stringified?(value)
117
117
  raise ArgumentError, "preference values must be plain strings: #{key.inspect} => #{value.inspect}"
118
118
  end
119
119
 
@@ -130,9 +130,8 @@ module Selenium
130
130
  end
131
131
 
132
132
  def add_webdriver_extension
133
- unless @extensions.has_key?(:webdriver)
134
- add_extension(WEBDRIVER_EXTENSION_PATH, :webdriver)
135
- end
133
+ return if @extensions.key?(:webdriver)
134
+ add_extension(WEBDRIVER_EXTENSION_PATH, :webdriver)
136
135
  end
137
136
 
138
137
  #
@@ -164,7 +163,7 @@ module Selenium
164
163
  end
165
164
 
166
165
  def proxy=(proxy)
167
- unless proxy.kind_of? Proxy
166
+ unless proxy.is_a? Proxy
168
167
  raise TypeError, "expected #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}"
169
168
  end
170
169
 
@@ -172,16 +171,16 @@ module Selenium
172
171
  when :manual
173
172
  self['network.proxy.type'] = 1
174
173
 
175
- set_manual_proxy_preference "ftp", proxy.ftp
176
- set_manual_proxy_preference "http", proxy.http
177
- set_manual_proxy_preference "ssl", proxy.ssl
178
- set_manual_proxy_preference "socks", proxy.socks
174
+ set_manual_proxy_preference 'ftp', proxy.ftp
175
+ set_manual_proxy_preference 'http', proxy.http
176
+ set_manual_proxy_preference 'ssl', proxy.ssl
177
+ set_manual_proxy_preference 'socks', proxy.socks
179
178
 
180
- if proxy.no_proxy
181
- self["network.proxy.no_proxies_on"] = proxy.no_proxy
182
- else
183
- self["network.proxy.no_proxies_on"] = ""
184
- end
179
+ self['network.proxy.no_proxies_on'] = if proxy.no_proxy
180
+ proxy.no_proxy
181
+ else
182
+ ''
183
+ end
185
184
  when :pac
186
185
  self['network.proxy.type'] = 2
187
186
  self['network.proxy.autoconfig_url'] = proxy.pac
@@ -199,17 +198,17 @@ module Selenium
199
198
  def set_manual_proxy_preference(key, value)
200
199
  return unless value
201
200
 
202
- host, port = value.to_s.split(":", 2)
201
+ host, port = value.to_s.split(':', 2)
203
202
 
204
203
  self["network.proxy.#{key}"] = host
205
204
  self["network.proxy.#{key}_port"] = Integer(port) if port
206
205
  end
207
206
 
208
207
  def install_extensions(directory)
209
- destination = File.join(directory, "extensions")
208
+ destination = File.join(directory, 'extensions')
210
209
 
211
210
  @extensions.each do |name, extension|
212
- p :extension => name if $DEBUG
211
+ p extension: name if $DEBUG
213
212
  extension.write_to(destination)
214
213
  end
215
214
  end
@@ -221,7 +220,7 @@ module Selenium
221
220
  end
222
221
 
223
222
  def delete_extensions_cache(directory)
224
- FileUtils.rm_f File.join(directory, "extensions.cache")
223
+ FileUtils.rm_f File.join(directory, 'extensions.cache')
225
224
  end
226
225
 
227
226
  def delete_lock_files(directory)
@@ -247,7 +246,7 @@ module Selenium
247
246
  prefs[WEBDRIVER_PREFS[:untrusted_issuer]] = assume_untrusted_certificate_issuer?
248
247
 
249
248
  # If the user sets the home page, we should also start up there
250
- prefs["startup.homepage_welcome_url"] = prefs["browser.startup.homepage"]
249
+ prefs['startup.homepage_welcome_url'] = prefs['browser.startup.homepage']
251
250
 
252
251
  write_prefs prefs, path
253
252
  end
@@ -257,25 +256,24 @@ module Selenium
257
256
  return prefs unless File.exist?(path)
258
257
 
259
258
  File.read(path).split("\n").each do |line|
260
- if line =~ /user_pref\("([^"]+)"\s*,\s*(.+?)\);/
261
- key, value = $1.strip, $2.strip
259
+ next unless line =~ /user_pref\("([^"]+)"\s*,\s*(.+?)\);/
260
+ key = Regexp.last_match(1).strip
261
+ value = Regexp.last_match(2).strip
262
262
 
263
- # wrap the value in an array to make it a valid JSON string.
264
- prefs[key] = JSON.parse("[#{value}]").first
265
- end
263
+ # wrap the value in an array to make it a valid JSON string.
264
+ prefs[key] = JSON.parse("[#{value}]").first
266
265
  end
267
266
 
268
267
  prefs
269
268
  end
270
269
 
271
270
  def write_prefs(prefs, path)
272
- File.open(path, "w") { |file|
271
+ File.open(path, 'w') do |file|
273
272
  prefs.each do |key, value|
274
273
  file.puts %{user_pref("#{key}", #{value.to_json});}
275
274
  end
276
- }
275
+ end
277
276
  end
278
-
279
277
  end # Profile
280
278
  end # Firefox
281
279
  end # WebDriver