watir-webdriver 0.6.1 → 0.6.2

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.
Files changed (59) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +1 -0
  3. data/CHANGES.md +1693 -0
  4. data/Gemfile +0 -1
  5. data/Rakefile +22 -0
  6. data/lib/watir-webdriver/alert.rb +46 -0
  7. data/lib/watir-webdriver/aliases.rb +2 -2
  8. data/lib/watir-webdriver/atoms.rb +2 -2
  9. data/lib/watir-webdriver/atoms/README +0 -1
  10. data/lib/watir-webdriver/browser.rb +195 -14
  11. data/lib/watir-webdriver/cell_container.rb +14 -2
  12. data/lib/watir-webdriver/container.rb +22 -0
  13. data/lib/watir-webdriver/cookies.rb +41 -0
  14. data/lib/watir-webdriver/element_collection.rb +13 -3
  15. data/lib/watir-webdriver/elements/button.rb +3 -1
  16. data/lib/watir-webdriver/elements/checkbox.rb +8 -6
  17. data/lib/watir-webdriver/elements/dlist.rb +4 -4
  18. data/lib/watir-webdriver/elements/element.rb +153 -28
  19. data/lib/watir-webdriver/elements/file_field.rb +6 -4
  20. data/lib/watir-webdriver/elements/generated.rb +12 -8
  21. data/lib/watir-webdriver/elements/image.rb +10 -5
  22. data/lib/watir-webdriver/elements/input.rb +6 -0
  23. data/lib/watir-webdriver/elements/option.rb +28 -2
  24. data/lib/watir-webdriver/elements/radio.rb +5 -1
  25. data/lib/watir-webdriver/elements/select.rb +11 -9
  26. data/lib/watir-webdriver/elements/table.rb +8 -1
  27. data/lib/watir-webdriver/elements/table_cell.rb +3 -3
  28. data/lib/watir-webdriver/elements/table_row.rb +0 -1
  29. data/lib/watir-webdriver/elements/table_section.rb +8 -2
  30. data/lib/watir-webdriver/elements/text_area.rb +2 -2
  31. data/lib/watir-webdriver/elements/text_field.rb +2 -2
  32. data/lib/watir-webdriver/extensions/alerts.rb +3 -3
  33. data/lib/watir-webdriver/extensions/nokogiri.rb +2 -2
  34. data/lib/watir-webdriver/extensions/select_text.rb +2 -2
  35. data/lib/watir-webdriver/has_window.rb +23 -1
  36. data/lib/watir-webdriver/html.rb +2 -0
  37. data/lib/watir-webdriver/html/visitor.rb +2 -2
  38. data/lib/watir-webdriver/locators/element_locator.rb +8 -0
  39. data/lib/watir-webdriver/locators/text_field_locator.rb +1 -1
  40. data/lib/watir-webdriver/row_container.rb +11 -3
  41. data/lib/watir-webdriver/screenshot.rb +11 -0
  42. data/lib/watir-webdriver/user_editable.rb +10 -4
  43. data/lib/watir-webdriver/version.rb +2 -2
  44. data/lib/watir-webdriver/wait.rb +32 -11
  45. data/lib/watir-webdriver/window.rb +104 -1
  46. data/lib/watir-webdriver/xpath_support.rb +4 -0
  47. data/lib/yard/handlers/watir.rb +1 -1
  48. data/spec/element_locator_spec.rb +14 -1
  49. data/spec/html/clicks.html +1 -1
  50. data/spec/implementation.rb +29 -6
  51. data/spec/wait_spec.rb +2 -2
  52. data/support/travis.sh +5 -3
  53. data/support/version_differ.rb +59 -0
  54. data/watir-webdriver.gemspec +4 -3
  55. metadata +146 -149
  56. data/spec/alert_spec.rb +0 -91
  57. data/spec/html/alerts.html +0 -12
  58. data/spec/screenshot_spec.rb +0 -25
  59. data/support/html5.html +0 -102577
@@ -1,6 +1,12 @@
1
1
  module Watir
2
2
  module CellContainer
3
3
 
4
+ #
5
+ # Returns table cell.
6
+ #
7
+ # @return [TableCell]
8
+ #
9
+
4
10
  def cell(*args)
5
11
  cell = TableCell.new(self, extract_selector(args).merge(:tag_name => /^(th|td)$/))
6
12
  cell.locator_class = ChildCellLocator
@@ -8,6 +14,12 @@ module Watir
8
14
  cell
9
15
  end
10
16
 
17
+ #
18
+ # Returns table cells collection.
19
+ #
20
+ # @return [TableCell]
21
+ #
22
+
11
23
  def cells(*args)
12
24
  cells = TableCellCollection.new(self, extract_selector(args).merge(:tag_name => /^(th|td)$/))
13
25
  cells.locator_class = ChildCellLocator
@@ -15,5 +27,5 @@ module Watir
15
27
  cells
16
28
  end
17
29
 
18
- end
19
- end
30
+ end # CellContainer
31
+ end # Watir
@@ -4,14 +4,36 @@ module Watir
4
4
  include XpathSupport
5
5
  include Atoms
6
6
 
7
+ #
8
+ # Returns element.
9
+ #
10
+ # @example
11
+ # browser.element(:data_bind => 'func')
12
+ #
13
+ # @return [HTMLElement]
14
+ #
15
+
7
16
  def element(*args)
8
17
  HTMLElement.new(self, extract_selector(args))
9
18
  end
10
19
 
20
+ #
21
+ # Returns element collection.
22
+ #
23
+ # @example
24
+ # browser.elements(:data_bind => 'func')
25
+ #
26
+ # @return [HTMLElementCollection]
27
+ #
28
+
11
29
  def elements(*args)
12
30
  HTMLElementCollection.new(self, extract_selector(args))
13
31
  end
14
32
 
33
+ #
34
+ # @api private
35
+ #
36
+
15
37
  def extract_selector(selectors)
16
38
  case selectors.size
17
39
  when 2
@@ -4,12 +4,37 @@ module Watir
4
4
  @control = control
5
5
  end
6
6
 
7
+ #
8
+ # Returns array of cookies.
9
+ #
10
+ # @example
11
+ # browser.cookies.to_a
12
+ # #=> {:name=>"my_session", :value=>"BAh7B0kiD3Nlc3Npb25faWQGOgZFRkk", :domain=>"mysite.com"}
13
+ #
14
+ # @return [Array<Hash>]
15
+ #
16
+
7
17
  def to_a
8
18
  @control.all_cookies.each do |e|
9
19
  e[:expires] = to_time(e[:expires]) if e[:expires]
10
20
  end
11
21
  end
12
22
 
23
+ #
24
+ # Adds new cookie.
25
+ #
26
+ # @example
27
+ # browser.cookies.add 'my_session', 'BAh7B0kiD3Nlc3Npb25faWQGOgZFRkk', :secure => true
28
+ #
29
+ # @param [String] name
30
+ # @param [String] value
31
+ # @param [Hash] opts
32
+ # @option opts [Boolean] :secure
33
+ # @option opts [String] :path
34
+ # @option opts [] :expires TODO what type
35
+ # @option opts [String] :domain
36
+ #
37
+
13
38
  def add(name, value, opts = {})
14
39
  cookie = {
15
40
  :name => name,
@@ -26,10 +51,26 @@ module Watir
26
51
  @control.add_cookie cookie
27
52
  end
28
53
 
54
+ #
55
+ # Deletes cookie by given name.
56
+ #
57
+ # @example
58
+ # browser.cookies.delete 'my_session'
59
+ #
60
+ # @param [String] name
61
+ #
62
+
29
63
  def delete(name)
30
64
  @control.delete_cookie(name)
31
65
  end
32
66
 
67
+ #
68
+ # Deletes all cookies.
69
+ #
70
+ # @example
71
+ # browser.cookies.clear
72
+ #
73
+
33
74
  def clear
34
75
  @control.delete_all_cookies
35
76
  end
@@ -13,6 +13,14 @@ module Watir
13
13
  @selector = selector
14
14
  end
15
15
 
16
+ #
17
+ # Yields each element in collection.
18
+ #
19
+ # @example
20
+ # divs = browser.divs(:class => 'kls')
21
+ # divs.each do |div|
22
+ # puts div.text
23
+ # end
16
24
  #
17
25
  # @yieldparam [Watir::Element] element Iterate through the elements in this collection.
18
26
  #
@@ -22,7 +30,9 @@ module Watir
22
30
  end
23
31
 
24
32
  #
25
- # @return [Fixnum] The number of elements in this collection.
33
+ # Returns number of elements in collection.
34
+ #
35
+ # @return [Fixnum]
26
36
  #
27
37
 
28
38
  def length
@@ -37,7 +47,7 @@ module Watir
37
47
  # Also note that because of Watir's lazy loading, this will return an Element
38
48
  # instance even if the index is out of bounds.
39
49
  #
40
- # @param [Fixnum] n Index of wanted element, 0-indexed
50
+ # @param [Fixnum] idx Index of wanted element, 0-indexed
41
51
  # @return [Watir::Element] Returns an instance of a Watir::Element subclass
42
52
  #
43
53
 
@@ -66,7 +76,7 @@ module Watir
66
76
  end
67
77
 
68
78
  #
69
- # This collection as an Array
79
+ # This collection as an Array.
70
80
  #
71
81
  # @return [Array<Watir::Element>]
72
82
  #
@@ -20,6 +20,8 @@ module Watir
20
20
  # For input elements, returns the "value" attribute.
21
21
  # For button elements, returns the inner text.
22
22
  #
23
+ # @return [String]
24
+ #
23
25
 
24
26
  def text
25
27
  assert_exists
@@ -37,7 +39,7 @@ module Watir
37
39
  end
38
40
 
39
41
  #
40
- # Returns true if this element is enabled
42
+ # Returns true if this element is enabled.
41
43
  #
42
44
  # @return [Boolean]
43
45
  #
@@ -4,16 +4,17 @@ module Watir
4
4
  class CheckBox < Input
5
5
 
6
6
  #
7
- # Set this checkbox to the given value
8
- #
9
- # Example:
7
+ # Sets checkbox to the given value.
10
8
  #
9
+ # @example
11
10
  # checkbox.set? #=> false
12
11
  # checkbox.set
13
12
  # checkbox.set? #=> true
14
13
  # checkbox.set(false)
15
14
  # checkbox.set? #=> false
16
15
  #
16
+ # @param [Boolean] bool
17
+ #
17
18
 
18
19
  def set(bool = true)
19
20
  assert_exists
@@ -27,7 +28,7 @@ module Watir
27
28
  end
28
29
 
29
30
  #
30
- # returns true if the element is checked
31
+ # Returns true if the element is checked
31
32
  # @return [Boolean]
32
33
  #
33
34
 
@@ -37,7 +38,7 @@ module Watir
37
38
  end
38
39
 
39
40
  #
40
- # Unset this checkbox.
41
+ # Unsets checkbox.
41
42
  #
42
43
  # Same as +set(false)+
43
44
  #
@@ -45,6 +46,7 @@ module Watir
45
46
  def clear
46
47
  set false
47
48
  end
49
+
48
50
  end # CheckBox
49
51
 
50
52
  module Container
@@ -62,4 +64,4 @@ module Watir
62
64
  CheckBox
63
65
  end
64
66
  end # CheckBoxCollection
65
- end
67
+ end # Watir
@@ -1,12 +1,12 @@
1
1
  module Watir
2
2
  class DList < HTMLElement
3
-
3
+
4
4
  def to_hash
5
5
  keys = dts.map { |e| e.text }
6
6
  values = dds.map { |e| e.text }
7
7
 
8
8
  Hash[keys.zip(values)]
9
9
  end
10
-
11
- end
12
- end
10
+
11
+ end # DList
12
+ end # Watir
@@ -14,14 +14,14 @@ module Watir
14
14
  include EventuallyPresent
15
15
 
16
16
  #
17
- # need to add :id manually since it's not specified in the HTML spec.
17
+ # temporarily add :id and :class_name manually since they're no longer specified in the HTML spec.
18
18
  #
19
19
  # @see http://html5.org/r/6605
20
- # @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=13610
20
+ # @see http://html5.org/r/7174
21
21
  #
22
- # TODO: use IDL from DOM core?
22
+ # TODO: use IDL from DOM core - http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html
23
23
  #
24
- attributes :string => [:id]
24
+ attributes :string => [:id, :class_name]
25
25
 
26
26
  def initialize(parent, selector)
27
27
  @parent = parent
@@ -33,6 +33,12 @@ module Watir
33
33
  end
34
34
  end
35
35
 
36
+ #
37
+ # Returns true if element exists.
38
+ #
39
+ # @return [Boolean]
40
+ #
41
+
36
42
  def exists?
37
43
  assert_exists
38
44
  true
@@ -49,6 +55,14 @@ module Watir
49
55
  end
50
56
  end
51
57
 
58
+ #
59
+ # Returns true if two elements are equal.
60
+ #
61
+ # @example
62
+ # browser.a(:id => "foo") == browser.a(:id => "foo")
63
+ # #=> true
64
+ #
65
+
52
66
  def ==(other)
53
67
  return false unless other.kind_of? self.class
54
68
 
@@ -61,31 +75,40 @@ module Watir
61
75
  @element ? @element.hash : super
62
76
  end
63
77
 
78
+ #
79
+ # Returns the text of the element.
80
+ #
81
+ # @return [String]
82
+ #
83
+
64
84
  def text
65
85
  assert_exists
66
86
  @element.text
67
87
  end
68
88
 
89
+ #
90
+ # Returns tag name of the element.
91
+ #
92
+ # @return [String]
93
+ #
94
+
69
95
  def tag_name
70
96
  assert_exists
71
97
  @element.tag_name.downcase
72
98
  end
73
99
 
74
100
  #
75
- # Clicks the element, optionally while pressing the given mofifier keys.
101
+ # Clicks the element, optionally while pressing the given modifier keys.
76
102
  # Note that support for holding a modifier key is currently experimental,
77
103
  # and may not work at all.
78
104
  #
79
105
  # @example Click an element
80
- #
81
106
  # element.click
82
107
  #
83
108
  # @example Click an element with shift key pressed
84
- #
85
109
  # element.click(:shift)
86
110
  #
87
111
  # @example Click an element with several modifier keys pressed
88
- #
89
112
  # element.click(:shift, :control)
90
113
  #
91
114
  # @param [:shift, :alt, :control, :command, :meta] Modifier key(s) to press while clicking.
@@ -113,10 +136,11 @@ module Watir
113
136
 
114
137
  #
115
138
  # Double clicks the element.
116
- #
117
139
  # Note that browser support may vary.
118
140
  #
119
-
141
+ # @example
142
+ # browser.a(:id => "foo").double_click
143
+ #
120
144
 
121
145
  def double_click
122
146
  assert_exists
@@ -128,9 +152,11 @@ module Watir
128
152
 
129
153
  #
130
154
  # Right clicks the element.
131
- #
132
155
  # Note that browser support may vary.
133
156
  #
157
+ # @example
158
+ # browser.a(:id => "foo").right_click
159
+ #
134
160
 
135
161
  def right_click
136
162
  assert_exists
@@ -142,8 +168,10 @@ module Watir
142
168
 
143
169
  #
144
170
  # Moves the mouse to the middle of this element.
171
+ # Note that browser support may vary.
145
172
  #
146
- # Note that browser/platform support may vary.
173
+ # @example
174
+ # browser.a(:id => "foo").hover
147
175
  #
148
176
 
149
177
  def hover
@@ -155,12 +183,11 @@ module Watir
155
183
 
156
184
  #
157
185
  # Drag and drop this element on to another element instance.
186
+ # Note that browser support may vary.
158
187
  #
159
- # Example:
160
- #
188
+ # @example
161
189
  # a = browser.div(:id => "draggable")
162
190
  # b = browser.div(:id => "droppable")
163
- #
164
191
  # a.drag_and_drop_on b
165
192
  #
166
193
 
@@ -176,12 +203,13 @@ module Watir
176
203
 
177
204
  #
178
205
  # Drag and drop this element by the given offsets.
206
+ # Note that browser support may vary.
179
207
  #
180
- # Example:
181
- #
182
- # a = browser.div(:id => "draggable")
208
+ # @example
209
+ # browser.div(:id => "draggable").drag_and_drop_by 100, -200
183
210
  #
184
- # a.drag_and_drop_by 100, -200
211
+ # @param [Fixnum] right_by
212
+ # @param [Fixnum] down_by
185
213
  #
186
214
 
187
215
  def drag_and_drop_by(right_by, down_by)
@@ -193,15 +221,33 @@ module Watir
193
221
  perform
194
222
  end
195
223
 
224
+ #
225
+ # Flashes (change background color far a moment) element.
226
+ #
227
+ # @example
228
+ # browser.div(:id => "draggable").flash
229
+ #
230
+
196
231
  def flash
197
- original_color = style("backgroundColor")
232
+ background_color = style("backgroundColor")
233
+ element_color = driver.execute_script("arguments[0].style.backgroundColor", @element)
198
234
 
199
235
  10.times do |n|
200
- color = (n % 2 == 0) ? "red" : original_color
236
+ color = (n % 2 == 0) ? "red" : background_color
201
237
  driver.execute_script("arguments[0].style.backgroundColor = '#{color}'", @element)
202
238
  end
239
+
240
+ driver.execute_script("arguments[0].style.backgroundColor = arguments[1]", @element, element_color)
241
+
242
+ self
203
243
  end
204
244
 
245
+ #
246
+ # Returns value of the element.
247
+ #
248
+ # @return [String]
249
+ #
250
+
205
251
  def value
206
252
  assert_exists
207
253
 
@@ -212,25 +258,56 @@ module Watir
212
258
  end
213
259
  end
214
260
 
261
+ #
262
+ # Returns given attribute value of element.
263
+ #
264
+ # @example
265
+ # browser.a(:id => "foo").attribute_value "href"
266
+ # #=> "http://watir.com"
267
+ #
268
+ # @param [String] attribute_name
269
+ # @return [String]
270
+ #
271
+
215
272
  def attribute_value(attribute_name)
216
273
  assert_exists
217
274
  @element.attribute attribute_name
218
275
  end
219
276
 
277
+ #
278
+ # Returns inner HTML code of element.
279
+ #
280
+ # @example
281
+ # browser.div(:id => "foo").html
282
+ # #=> "<a>Click</a>"
283
+ #
284
+ # @return [String]
285
+ #
286
+
220
287
  def html
221
288
  assert_exists
222
289
  execute_atom(:getOuterHtml, @element).strip
223
290
  end
224
291
 
292
+ #
293
+ # Sends sequence of keystrokes to element.
294
+ #
295
+ # @example
296
+ # browser.div(:id => "foo").send_keys "Watir", :return
297
+ #
298
+ # @param [String, Symbol] *args
299
+ #
300
+
225
301
  def send_keys(*args)
226
302
  assert_exists
227
303
  @element.send_keys(*args)
228
304
  end
229
305
 
230
306
  #
231
- # Note: Firefox queues focus events until the window actually has focus.
307
+ # Focuses element.
308
+ # Note that Firefox queues focus events until the window actually has focus.
232
309
  #
233
- # See http://code.google.com/p/selenium/issues/detail?id=157
310
+ # @see http://code.google.com/p/selenium/issues/detail?id=157
234
311
  #
235
312
 
236
313
  def focus
@@ -238,11 +315,29 @@ module Watir
238
315
  driver.execute_script "return arguments[0].focus()", @element
239
316
  end
240
317
 
318
+ #
319
+ # Returns true if this element is focused.
320
+ #
321
+ # @return [Boolean]
322
+ #
323
+
241
324
  def focused?
242
325
  assert_exists
243
326
  @element == driver.switch_to.active_element
244
327
  end
245
328
 
329
+ #
330
+ # Simulates JavaScript events on element.
331
+ # Note that you may omit "on" from event name.
332
+ #
333
+ # @example
334
+ # browser.a(:id => "foo").fire_event :click
335
+ # browser.a(:id => "foo").fire_event "mousemove"
336
+ # browser.a(:id => "foo").fire_event "onmouseover"
337
+ #
338
+ # @param [String, Symbol] event_name
339
+ #
340
+
246
341
  def fire_event(event_name)
247
342
  assert_exists
248
343
  event_name = event_name.to_s.sub(/^on/, '').downcase
@@ -250,6 +345,10 @@ module Watir
250
345
  execute_atom :fireEvent, @element, event_name
251
346
  end
252
347
 
348
+ #
349
+ # Returns parent element of current element.
350
+ #
351
+
253
352
  def parent
254
353
  assert_exists
255
354
 
@@ -278,7 +377,9 @@ module Watir
278
377
  end
279
378
 
280
379
  #
281
- # Returns true if this element is visible on the page
380
+ # Returns true if this element is visible on the page.
381
+ #
382
+ # @return [Boolean]
282
383
  #
283
384
 
284
385
  def visible?
@@ -287,8 +388,9 @@ module Watir
287
388
  end
288
389
 
289
390
  #
290
- # Returns true if the element exists and is visible on the page
391
+ # Returns true if the element exists and is visible on the page.
291
392
  #
393
+ # @return [Boolean]
292
394
  # @see Watir::Wait
293
395
  #
294
396
 
@@ -300,6 +402,19 @@ module Watir
300
402
  false
301
403
  end
302
404
 
405
+ #
406
+ # Returns given style property of this element.
407
+ #
408
+ # @example
409
+ # browser.a(:id => "foo").style
410
+ # #=> "display: block"
411
+ # browser.a(:id => "foo").style "display"
412
+ # #=> "block"
413
+ #
414
+ # @param [String] property
415
+ # @return [String]
416
+ #
417
+
303
418
  def style(property = nil)
304
419
  if property
305
420
  assert_exists
@@ -309,6 +424,10 @@ module Watir
309
424
  end
310
425
  end
311
426
 
427
+ #
428
+ # Runs checkers.
429
+ #
430
+
312
431
  def run_checkers
313
432
  @parent.run_checkers
314
433
  end
@@ -316,9 +435,9 @@ module Watir
316
435
  #
317
436
  # Cast this Element instance to a more specific subtype.
318
437
  #
319
- # Example:
320
- #
321
- # browser.element(:xpath => "//input[@type='submit']").to_subtype #=> #<Watir::Button>
438
+ # @example
439
+ # browser.element(:xpath => "//input[@type='submit']").to_subtype
440
+ # #=> #<Watir::Button>
322
441
  #
323
442
 
324
443
  def to_subtype
@@ -347,6 +466,12 @@ module Watir
347
466
  klass.new(@parent, :element => elem)
348
467
  end
349
468
 
469
+ #
470
+ # Returns browser.
471
+ #
472
+ # @return [Watir::Browser]
473
+ #
474
+
350
475
  def browser
351
476
  @parent.browser
352
477
  end