selenium-webdriver 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ 0.0.28 (2010-08-23)
2
+ ===================
3
+
4
+ * Fix behaviour of Element#==, Element#eql? and Element#hash (#hash still has issues on IE / remote).
5
+ * Include remote server backtrace in raised errors (if available).
6
+ * Chrome: Untrusted certificate support.
7
+ * IE: Fix NoMethodError when getElementAttribute returns nil.
8
+ * Driver#[] shorthand can take a locator hash, not just an id string.
9
+
1
10
  0.0.27 (2010-07-22)
2
11
  ===================
3
12
 
@@ -6,9 +6,12 @@ module Selenium
6
6
  class Bridge < Remote::Bridge
7
7
 
8
8
  def initialize(opts = {})
9
- @executor = CommandExecutor.new
9
+ @launcher = Launcher.launcher(
10
+ :default_profile => opts[:default_profile],
11
+ :secure_ssl => opts[:secure_ssl]
12
+ )
10
13
 
11
- @launcher = Launcher.launcher(:default_profile => opts[:default_profile])
14
+ @executor = CommandExecutor.new
12
15
  @launcher.launch(@executor.uri)
13
16
  end
14
17
 
@@ -66,6 +69,10 @@ module Selenium
66
69
  execute :implicitlyWait, :ms => milliseconds
67
70
  end
68
71
 
72
+ def elementEquals(element, other)
73
+ element.ref == other.ref
74
+ end
75
+
69
76
  private
70
77
 
71
78
  def execute(command_name, opts = {}, args = nil)
@@ -117,4 +124,4 @@ module Selenium
117
124
  end # Bridge
118
125
  end # Chrome
119
126
  end # WebDriver
120
- end # Selenium
127
+ end # Selenium
@@ -24,8 +24,8 @@ module Selenium
24
24
  end
25
25
 
26
26
  def initialize(opts = {})
27
- super()
28
27
  @default_profile = opts[:default_profile]
28
+ @secure_ssl = !!opts[:secure_ssl]
29
29
  end
30
30
 
31
31
  def self.binary_path
@@ -81,6 +81,10 @@ module Selenium
81
81
  args << "--user-data-dir=#{Platform.wrap_in_quotes_if_necessary tmp_profile_dir}"
82
82
  end
83
83
 
84
+ unless @secure_ssl
85
+ args << "--ignore-certificate-errors"
86
+ end
87
+
84
88
  args << server_url
85
89
 
86
90
  @process = ChildProcess.new(*args).start
@@ -91,23 +95,23 @@ module Selenium
91
95
  end
92
96
 
93
97
  def tmp_extension_dir
94
- @tmp_extension_dir ||= begin
98
+ @tmp_extension_dir ||= (
95
99
  dir = Dir.mktmpdir("webdriver-chrome-extension")
96
100
  Platform.make_writable(dir)
97
101
  FileReaper << dir
98
102
 
99
103
  dir
100
- end
104
+ )
101
105
  end
102
106
 
103
107
  def tmp_profile_dir
104
- @tmp_profile_dir ||= begin
108
+ @tmp_profile_dir ||= (
105
109
  dir = Dir.mktmpdir("webdriver-chrome-profile")
106
110
  Platform.make_writable(dir)
107
111
  FileReaper << dir
108
112
 
109
113
  dir
110
- end
114
+ )
111
115
  end
112
116
 
113
117
  class WindowsLauncher < Launcher
@@ -149,7 +153,10 @@ module Selenium
149
153
 
150
154
  class MacOSXLauncher < UnixLauncher
151
155
  def self.possible_paths
152
- ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "#{Platform.home}/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"]
156
+ [
157
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
158
+ "#{Platform.home}/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
159
+ ]
153
160
  end
154
161
  end
155
162
 
@@ -229,16 +229,22 @@ module Selenium
229
229
 
230
230
  alias_method :script, :execute_script
231
231
 
232
- # Get the first element matching the given id.
232
+ # Get the first element matching the given selector. If given a
233
+ # String or Symbol, it will be used as the id of the element.
233
234
  #
234
- # @param [String] id
235
+ # @param [String,Hash] id or selector
235
236
  # @return [WebDriver::Element]
236
237
  #
237
- # driver['someElementId'] #=> #<WebDriver::Element:0x1011c3b88>
238
+ # driver['someElementId'] #=> #<WebDriver::Element:0x1011c3b88>
239
+ # driver[:tag_name => 'div'] #=> #<WebDriver::Element:0x1011c3b88>
238
240
  #
239
241
 
240
- def [](id)
241
- find_element :id, id
242
+ def [](sel)
243
+ if sel.kind_of?(String) || sel.kind_of?(Symbol)
244
+ sel = { :id => sel }
245
+ end
246
+
247
+ find_element sel
242
248
  end
243
249
 
244
250
 
@@ -254,4 +260,4 @@ module Selenium
254
260
 
255
261
  end # Driver
256
262
  end # WebDriver
257
- end # Selenium
263
+ end # Selenium
@@ -19,6 +19,15 @@ module Selenium
19
19
  '#<%s:0x%x id=%s tag_name=%s>' % [self.class, hash*2, @id.inspect, tag_name.inspect]
20
20
  end
21
21
 
22
+ def ==(other)
23
+ other.kind_of?(self.class) && bridge.elementEquals(self, other)
24
+ end
25
+ alias_method :eql?, :==
26
+
27
+ def hash
28
+ ref.hash
29
+ end
30
+
22
31
  #
23
32
  # Click the element
24
33
  #
@@ -105,7 +105,7 @@ module Selenium
105
105
  when :linux, :unix
106
106
  Platform.find_binary("firefox3", "firefox2", "firefox") || "/usr/bin/firefox"
107
107
  else
108
- raise "Unknown platform: #{Platform.os}"
108
+ raise Error::WebDriverError, "unknown platform: #{Platform.os}"
109
109
  end
110
110
 
111
111
  unless File.file?(@path)
@@ -11,14 +11,14 @@ module Selenium
11
11
  STABLE_CONNECTION_TIMEOUT = 60
12
12
 
13
13
  def initialize(binary, port = DEFAULT_PORT, profile = DEFAULT_PROFILE_NAME)
14
- @binary = binary
15
- @port = port.to_i
14
+ @binary = binary
15
+ @port = port.to_i
16
16
 
17
17
  if profile.kind_of? Profile
18
18
  @profile = profile
19
19
  else
20
20
  @profile_name = profile
21
- @profile = nil
21
+ @profile = nil
22
22
  end
23
23
 
24
24
  # need to be really specific about what host to use
@@ -137,14 +137,14 @@ module Selenium
137
137
  @binary.create_base_profile @profile_name
138
138
  Profile.ini.refresh
139
139
  existing = Profile.from_name @profile_name
140
- raise "unable to find or create new profile" unless existing
140
+ raise Error::WebDriverError, "unable to find or create new profile" unless existing
141
141
  end
142
142
 
143
143
  @profile = existing
144
144
  end
145
145
 
146
146
  def assert_profile
147
- raise "must create_profile first" if @profile.nil?
147
+ raise Error::WebDriverError, "must create_profile first" unless @profile
148
148
  end
149
149
 
150
150
  end # Launcher
@@ -8,8 +8,8 @@ module Selenium
8
8
  EM_NAMESPACE_URI = "http://www.mozilla.org/2004/em-rdf#"
9
9
  WEBDRIVER_EXTENSION_PATH = File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/webdriver.xpi")
10
10
 
11
- attr_reader :name, :directory
12
- attr_writer :secure_ssl, :native_events, :load_no_focus_lib
11
+ attr_reader :name, :directory
12
+ attr_writer :secure_ssl, :native_events, :load_no_focus_lib
13
13
  attr_accessor :port
14
14
 
15
15
  class << self
@@ -131,8 +131,7 @@ module Selenium
131
131
  root = ZipHelper.unzip(path)
132
132
  end
133
133
 
134
- id = read_id_from_install_rdf(root)
135
- ext_path = File.join(extensions_dir, id)
134
+ ext_path = File.join extensions_dir, read_id_from_install_rdf(root)
136
135
 
137
136
  FileUtils.rm_rf ext_path
138
137
  FileUtils.mkdir_p File.dirname(ext_path), :mode => 0700
@@ -208,12 +207,12 @@ module Selenium
208
207
  end
209
208
 
210
209
  def write_prefs(prefs)
211
- File.open(user_prefs_path, "w") do |file|
210
+ File.open(user_prefs_path, "w") { |file|
212
211
  prefs.each do |key, value|
213
212
  p key => value if $DEBUG
214
213
  file.puts %{user_pref("#{key}", #{value});}
215
214
  end
216
- end
215
+ }
217
216
  end
218
217
 
219
218
  OVERRIDABLE_PREFERENCES = {
@@ -350,14 +350,17 @@ module Selenium
350
350
  end
351
351
 
352
352
  def getElementValue(element_pointer)
353
- getElementAttribute(element_pointer, 'value').gsub("\r\n", "\n")
353
+ val = getElementAttribute(element_pointer, 'value')
354
+ val.gsub("\r\n", "\n") if val
354
355
  end
355
356
 
356
357
  def getElementText(element_pointer)
357
- create_string do |string_pointer|
358
+ val = create_string do |string_pointer|
358
359
  check_error_code Lib.wdeGetText(element_pointer, string_pointer),
359
360
  "unable to get text"
360
- end.gsub("\r\n", "\n")
361
+ end
362
+
363
+ val.gsub("\r\n", "\n") if val
361
364
  end
362
365
 
363
366
  def sendKeysToElement(element_pointer, string)
@@ -434,6 +437,10 @@ module Selenium
434
437
  raise NotImplementedError
435
438
  end
436
439
 
440
+ def elementEquals(element, other)
441
+ executeScript "return arguments[0] === arguments[1]", element, other
442
+ end
443
+
437
444
  def dragElement(element_pointer, right_by, down_by)
438
445
  # TODO: check return values?
439
446
  hwnd = FFI::MemoryPointer.new :pointer
@@ -339,6 +339,10 @@ module Selenium
339
339
  execute :dragElement, {:id => element}, :x => rigth_by, :y => down_by
340
340
  end
341
341
 
342
+ def elementEquals(element, other)
343
+ execute :elementEquals, :id => element.ref, :other => other.ref
344
+ end
345
+
342
346
  private
343
347
 
344
348
  def find_element_by(how, what, parent = nil)
@@ -16,11 +16,22 @@ module Selenium
16
16
  end
17
17
 
18
18
  def error
19
- Error.for_code @payload['status']
19
+ klass = Error.for_code(@payload['status']) || return
20
+
21
+ ex = klass.new(error_message)
22
+ ex.set_backtrace(caller)
23
+ add_backtrace ex
24
+
25
+ ex
20
26
  end
21
27
 
22
28
  def error_message
23
- @payload['value']['message']
29
+ val = @payload['value']
30
+ msg = val['message'] or return ""
31
+
32
+ msg << " (#{ val['class'] })" if val['class']
33
+
34
+ msg
24
35
  end
25
36
 
26
37
  def [](key)
@@ -32,13 +43,31 @@ module Selenium
32
43
  def assert_ok
33
44
  if @code.nil? || @code >= 400
34
45
  if e = error()
35
- raise(e, error_message)
46
+ raise e
36
47
  else
37
48
  raise Error::ServerError, self
38
49
  end
39
50
  end
40
51
  end
41
52
 
53
+ def add_backtrace(ex)
54
+ return unless server_trace = @payload['value']['stackTrace']
55
+
56
+ backtrace = server_trace.map do |frame|
57
+ file = frame['fileName']
58
+ line = frame['lineNumber']
59
+ meth = frame['methodName']
60
+
61
+ if class_name = frame['className']
62
+ file = "#{class_name}(#{file})"
63
+ end
64
+
65
+ "[remote server] #{file}:#{line}:in `#{meth}'"
66
+ end
67
+
68
+ ex.set_backtrace(backtrace + ex.backtrace)
69
+ end
70
+
42
71
  end # Response
43
72
  end # Remote
44
73
  end # WebDriver
@@ -2,12 +2,9 @@ require 'zip/zip'
2
2
 
3
3
  module Selenium
4
4
  module WebDriver
5
-
6
5
  module ZipHelper
7
6
 
8
- module_function
9
-
10
- def unzip(path)
7
+ def self.unzip(path)
11
8
  destination = Dir.mktmpdir("unzip")
12
9
  FileReaper << destination
13
10
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 27
9
- version: 0.0.27
8
+ - 28
9
+ version: 0.0.28
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jari Bakken
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-22 00:00:00 +02:00
17
+ date: 2010-08-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency