firewatir 1.1.1

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 (95) hide show
  1. data/MozillaBaseElement.rb +1778 -0
  2. data/container.rb +889 -0
  3. data/firewatir/exceptions.rb +44 -0
  4. data/firewatir/testUnitAddons.rb +8 -0
  5. data/firewatir.rb +1130 -0
  6. data/htmlelements.rb +2277 -0
  7. data/unittests/attach_to_new_window_test.rb +34 -0
  8. data/unittests/bug_fixes_test.rb +188 -0
  9. data/unittests/buttons_test.rb +215 -0
  10. data/unittests/buttons_xpath_test.rb +87 -0
  11. data/unittests/checkbox_test.rb +154 -0
  12. data/unittests/checkbox_xpath_test.rb +107 -0
  13. data/unittests/div_test.rb +274 -0
  14. data/unittests/filefield_test.rb +45 -0
  15. data/unittests/filefield_xpath_test.rb +35 -0
  16. data/unittests/form_test.rb +307 -0
  17. data/unittests/frame_test.rb +151 -0
  18. data/unittests/hidden_test.rb +85 -0
  19. data/unittests/hidden_xpath_test.rb +72 -0
  20. data/unittests/html/JavascriptClick.html +42 -0
  21. data/unittests/html/blankpage.html +12 -0
  22. data/unittests/html/buttons1.html +61 -0
  23. data/unittests/html/checkboxes1.html +71 -0
  24. data/unittests/html/complex_table.html +36 -0
  25. data/unittests/html/cssTest.html +42 -0
  26. data/unittests/html/div.html +72 -0
  27. data/unittests/html/div_xml.html +21 -0
  28. data/unittests/html/fileupload.html +45 -0
  29. data/unittests/html/formTest1.html +39 -0
  30. data/unittests/html/forms2.html +45 -0
  31. data/unittests/html/forms3.html +132 -0
  32. data/unittests/html/forms4.html +27 -0
  33. data/unittests/html/frame_buttons.html +4 -0
  34. data/unittests/html/frame_links.html +4 -0
  35. data/unittests/html/frame_multi.html +5 -0
  36. data/unittests/html/iframeTest.html +15 -0
  37. data/unittests/html/iframeTest1.html +14 -0
  38. data/unittests/html/iframeTest2.html +6 -0
  39. data/unittests/html/images/1.gif +0 -0
  40. data/unittests/html/images/2.GIF +0 -0
  41. data/unittests/html/images/3.GIF +0 -0
  42. data/unittests/html/images/button.jpg +0 -0
  43. data/unittests/html/images/circle.jpg +0 -0
  44. data/unittests/html/images/minus.GIF +0 -0
  45. data/unittests/html/images/originaltriangle.jpg +0 -0
  46. data/unittests/html/images/plus.gif +0 -0
  47. data/unittests/html/images/square.jpg +0 -0
  48. data/unittests/html/images/triangle.jpg +0 -0
  49. data/unittests/html/images1.html +67 -0
  50. data/unittests/html/javascriptevents.html +35 -0
  51. data/unittests/html/link_pass.html +11 -0
  52. data/unittests/html/links1.html +42 -0
  53. data/unittests/html/links2.html +11 -0
  54. data/unittests/html/modal_dialog.html +8 -0
  55. data/unittests/html/modal_dialog_launcher.html +12 -0
  56. data/unittests/html/nestedFrames.html +6 -0
  57. data/unittests/html/new_browser.html +17 -0
  58. data/unittests/html/pass.html +10 -0
  59. data/unittests/html/popups1.html +60 -0
  60. data/unittests/html/pre.html +28 -0
  61. data/unittests/html/radioButtons1.html +71 -0
  62. data/unittests/html/redirect.html +10 -0
  63. data/unittests/html/redirect1.html +9 -0
  64. data/unittests/html/redirect2.html +9 -0
  65. data/unittests/html/redirect3.html +9 -0
  66. data/unittests/html/select_tealeaf.html +54 -0
  67. data/unittests/html/selectboxes1.html +55 -0
  68. data/unittests/html/simple_table.html +26 -0
  69. data/unittests/html/simple_table_buttons.html +104 -0
  70. data/unittests/html/simple_table_columns.html +74 -0
  71. data/unittests/html/table1.html +165 -0
  72. data/unittests/html/tableCell_using_xpath.html +19 -0
  73. data/unittests/html/textarea.html +30 -0
  74. data/unittests/html/textfields1.html +62 -0
  75. data/unittests/html/textsearch.html +44 -0
  76. data/unittests/images_test.rb +204 -0
  77. data/unittests/images_xpath_test.rb +118 -0
  78. data/unittests/iostring.rb +30 -0
  79. data/unittests/iostring_test.rb +48 -0
  80. data/unittests/javascript_test.rb +71 -0
  81. data/unittests/links_test.rb +230 -0
  82. data/unittests/links_xpath_test.rb +79 -0
  83. data/unittests/mozilla_all_tests.rb +18 -0
  84. data/unittests/pre_test.rb +74 -0
  85. data/unittests/radios_test.rb +166 -0
  86. data/unittests/radios_xpath_test.rb +101 -0
  87. data/unittests/redirect_test.rb +40 -0
  88. data/unittests/selectbox_test.rb +141 -0
  89. data/unittests/selectbox_xpath_test.rb +127 -0
  90. data/unittests/setup.rb +35 -0
  91. data/unittests/table_test.rb +372 -0
  92. data/unittests/table_xpath_test.rb +184 -0
  93. data/unittests/textfields_test.rb +230 -0
  94. data/unittests/textfields_xpath_test.rb +112 -0
  95. metadata +144 -0
@@ -0,0 +1,372 @@
1
+ # feature tests for Tables
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_Tables < Test::Unit::TestCase
8
+ include FireWatir
9
+
10
+ def setup
11
+ $ff.goto($htmlRoot + "table1.html")
12
+ end
13
+
14
+ def test_Table_Exists
15
+ assert(!$ff.table(:id, 'missingTable').exists?)
16
+ assert(!$ff.table(:index, 33).exists?)
17
+
18
+ assert($ff.table(:id, 't1').exists?)
19
+ assert($ff.table(:id, /t/).exists?)
20
+ assert(!$ff.table(:id, /missing_table/).exists?)
21
+
22
+ assert($ff.table(:index, 1).exists?)
23
+ assert($ff.table(:index, 2).exists?)
24
+ end
25
+
26
+ def test_rows
27
+ assert_raises(UnknownObjectException ){ $ff.table(:id, 'missingTable').row_count }
28
+ assert_raises(UnknownObjectException ){ $ff.table(:index, 66).row_count }
29
+ assert_raises(UnknownObjectException){ $ff.table(:bad_attribute, 99).row_count }
30
+
31
+ assert_equal(2, $ff.table(:index, 1).row_count)
32
+ assert_equal(2, $ff.table(:index, 1).rows.length)
33
+
34
+ assert_equal(5, $ff.table(:id, 't1').row_count) # 4 rows and a header
35
+ assert_equal(5, $ff.table(:index, 2).row_count) # same table as above, just accessed by index
36
+ assert_equal(5, $ff.table(:id, 't1').rows.length)
37
+
38
+ # test the each iterator on rows - ie, go through each cell
39
+ row = $ff.table(:index, 2)[2]
40
+ count = 1
41
+ row.each do |cell|
42
+ if count == 1
43
+ assert_equal('Row 1 Col1', cell.to_s.strip)
44
+ elsif count==2
45
+ assert_equal('Row 1 Col2', cell.to_s.strip)
46
+ end
47
+ count += 1
48
+ end
49
+ assert_equal(2, count -1)
50
+ assert_equal(2, $ff.table(:index, 2)[2].column_count)
51
+ end
52
+
53
+ def test_dynamic_tables
54
+ t = $ff.table(:id, 't1')
55
+ assert_equal(5, t.row_count)
56
+
57
+ $ff.button(:value, 'add row').click
58
+ assert_equal(6, t.row_count)
59
+ end
60
+
61
+ def test_columns
62
+ assert_raises(UnknownObjectException ){ $ff.table(:id, 'missingTable').column_count }
63
+ assert_raises(UnknownObjectException ){ $ff.table(:index, 77).column_count }
64
+ assert_equal(2, $ff.table(:index, 1).column_count)
65
+ assert_equal(1, $ff.table(:id, 't1').column_count) # row one has 1 cell with a colspan of 2
66
+ end
67
+
68
+ def test_to_a
69
+ table1Expected = [ ["Row 1 Col1" , "Row 1 Col2"] ,[ "Row 2 Col1" , "Row 2 Col2"] ]
70
+ assert_equal(table1Expected, $ff.table(:index , 1).to_a )
71
+ end
72
+
73
+ def test_links_and_images_in_table
74
+ table = $ff.table(:id, 'pic_table')
75
+ image = table[1][2].image(:index,1)
76
+ assert_equal("106", image.width)
77
+
78
+ link = table[2][2].link(:index,1)
79
+ assert_equal("Google", link.innerText)
80
+ end
81
+
82
+ def test_cell_directly
83
+ assert( $ff.cell(:id, 'cell1').exists? )
84
+ assert(! $ff.cell(:id, 'no_exist').exists? )
85
+ assert_equal( "Row 1 Col1", $ff.cell(:id, 'cell1').to_s.strip )
86
+
87
+ # not really cell directly, but just to show another way of geting the cell
88
+ assert_equal( "Row 1 Col1", $ff.table(:index,1)[1][1].to_s.strip )
89
+ assert_equal(2, $ff.cell(:id, "cell_with_colspan").colspan)
90
+ end
91
+
92
+ def test_row_directly
93
+ assert( $ff.row(:id, 'row1').exists? )
94
+ assert(! $ff.row(:id, 'no_exist').exists? )
95
+
96
+ assert_equal('Row 2 Col1' , $ff.row(:id, 'row1')[1].to_s.strip )
97
+ end
98
+
99
+ def test_row_iterator
100
+ t = $ff.table(:index, 1)
101
+ count = 1
102
+ t.each do |row|
103
+ if count == 1
104
+ assert("Row 1 Col1", row[1].text)
105
+ assert("Row 1 Col2", row[2].text)
106
+ elsif count == 2
107
+ assert("Row 2 Col1", row[1].text)
108
+ assert("Row 2 Col2", row[2].text)
109
+ end
110
+ count += 1
111
+ end
112
+ end
113
+
114
+ def test_row_collection
115
+ t = $ff.table(:index,1)
116
+ count = 1
117
+ t.rows.each do |row|
118
+ if count == 1
119
+ assert("Row 1 Col1", row[1].text)
120
+ assert("Row 1 Col2", row[2].text)
121
+ elsif count == 2
122
+ assert("Row 2 Col1", row[1].text)
123
+ assert("Row 2 Col2", row[2].text)
124
+ end
125
+ count += 1
126
+ end
127
+ end
128
+
129
+ #def test_table_body
130
+ # assert_equal( 1, $ff.table(:index,1).bodies.length )
131
+ # assert_equal( 3, $ff.table(:id, 'body_test' ).bodies.length )
132
+ #
133
+ # count = 1
134
+ # $ff.table(:id, 'body_test').bodies.each do |n|
135
+ #
136
+ # # do something better here!
137
+ # n.flash # this line commented out to speed up the test
138
+
139
+ # case count
140
+ # when 1
141
+ # compare_text = "This text is in the FRST TBODY."
142
+ # when 2
143
+ # compare_text = "This text is in the SECOND TBODY."
144
+ # when 3
145
+ # compare_text = "This text is in the THIRD TBODY."
146
+ # end
147
+ #
148
+ # assert_equal(compare_text, n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
149
+ #
150
+ # count += 1
151
+ # end
152
+ # assert_equal( count - 1, $ff.table(:id, 'body_test').bodies.length )
153
+ #
154
+ # assert_equal( "This text is in the THIRD TBODY." ,$ff.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
155
+ #
156
+ # # iterate through all the rows in a table body
157
+ # count = 1
158
+ # $ff.table(:id, 'body_test').body(:index, 2).each do | row |
159
+ # # row.flash # this line commented out, to speed up the tests
160
+ # if count == 1
161
+ # assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
162
+ # elsif count == 1 # BUG: Huh?
163
+ # assert_equal('This text is also in the SECOND TBODY.', row[1].text.strip )
164
+ # end
165
+ # count+=1
166
+ # end
167
+ #end
168
+
169
+ def test_table_container
170
+ assert_nothing_raised { $ff.table(:id, 't1').html }
171
+ end
172
+ end
173
+
174
+ class TC_Tables_Simple < Test::Unit::TestCase
175
+ include FireWatir
176
+
177
+ def setup
178
+ $ff.goto($htmlRoot + "simple_table.html")
179
+ end
180
+
181
+ def test_simple_table_access
182
+ table = $ff.table(:index,1)
183
+
184
+ assert_equal("Row 3 Col1",table[3][1].text.strip)
185
+ assert_equal("Row 1 Col1",table[1][1].text.strip)
186
+ assert_equal("Row 3 Col2",table[3][2].text.strip)
187
+ assert_equal(2,table.column_count)
188
+ end
189
+ end
190
+
191
+ class TC_Tables_Buttons < Test::Unit::TestCase
192
+ include FireWatir
193
+
194
+ def setup
195
+ $ff.goto($htmlRoot + "simple_table_buttons.html")
196
+ end
197
+
198
+ def test_simple_table_buttons
199
+ table = $ff.table(:index,1)
200
+
201
+ table[1][1].button(:index,1).click
202
+ assert($ff.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
203
+ table[2][1].button(:index,1).click
204
+ assert($ff.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
205
+
206
+ table[1][1].button(:id,'b1').click
207
+ assert($ff.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
208
+
209
+ assert_raises(UnknownObjectException ) { table[1][1].button(:id,'b_missing').click }
210
+
211
+ table[3][1].button(:index,2).click
212
+ assert($ff.text_field(:name,"confirmtext").verify_contains(/TOO/i))
213
+
214
+ table[3][1].button(:value ,"Click too").click
215
+ assert($ff.text_field(:name,"confirmtext").verify_contains(/TOO/i))
216
+
217
+ $ff.table(:index,1)[4][1].text_field(:index,1).set("123")
218
+ assert($ff.text_field(:index,2).verify_contains("123"))
219
+
220
+ # check when a cell contains 2 objects
221
+
222
+ # if there were 2 different html objects in the same cell, some weird things happened ( button caption could change for example)
223
+ assert_equal( 'Click ->' , $ff.table(:index,1)[5][1].text_field(:index,1).value )
224
+ $ff.table(:index,1)[5][1].text_field(:index,1).click
225
+ assert_equal( 'Click ->' , $ff.table(:index,1)[5][1].text_field(:index,1).value )
226
+
227
+ $ff.table(:index,1)[5][1].button(:index,1).click
228
+ assert_equal( '' , $ff.table(:index,1)[5][1].text_field(:index,1).value )
229
+ end
230
+
231
+ def test_simple_table_gif
232
+ table = $ff.table(:index,2)
233
+
234
+ assert_match( /1\.gif/ , table[1][1].image( :index,1).src )
235
+ assert_match( /2\.gif/ , table[1][2].image( :index ,1).src )
236
+ assert_match( /3\.gif/ , table[1][3].image( :index ,1).src )
237
+
238
+ assert_match( /1\.gif/ , table[3][1].image( :index ,1).src )
239
+ assert_match( /2\.gif/ , table[3][2].image( :index ,1).src )
240
+ assert_match( /3\.gif/ , table[3][3].image( :index ,1).src )
241
+
242
+ table = $ff.table(:index,3)
243
+ assert_match( /1\.gif/ , table[1][1].image( :index ,1).src )
244
+ assert_match( /2\.gif/ , table[1][1].image( :index ,2).src )
245
+ assert_match( /3\.gif/ , table[1][1].image( :index ,3).src )
246
+
247
+ assert_match( /1\.gif/ , table[3][1].image( :index ,1).src )
248
+ assert_match( /2\.gif/ , table[3][1].image( :index ,2).src )
249
+ assert_match( /3\.gif/ , table[3][1].image( :index ,3).src )
250
+ end
251
+
252
+ def test_table_with_hidden_or_visible_rows
253
+ t = $ff.table(:id , 'show_hide')
254
+
255
+ # expand the table
256
+ t.each do |r|
257
+ r[1].image(:src, /plus/).click if r[1].image(:src, /plus/).exists?
258
+ end
259
+
260
+ # shrink rows 1,2,3
261
+ count=1
262
+ t.each do |r|
263
+ r[1].image(:src, /minus/).click if r[1].image(:src, /minus/).exists? and (1..3) === count
264
+ count=2
265
+ end
266
+ end
267
+
268
+ # def test_table_from_element
269
+ # button = $ff.button(:id, "b1")
270
+ # table = Table.create_from_element($ff, button)
271
+
272
+ # table[2][1].button(:index, 1).click
273
+ # assert($ff.textField(:name, "confirmtext").verify_contains(/CLICK2/i))
274
+ # end
275
+ end
276
+
277
+ class TC_Table_Columns < Test::Unit::TestCase
278
+ include FireWatir
279
+ def setup
280
+ $ff.goto($htmlRoot + "simple_table_columns.html")
281
+ end
282
+
283
+ # def test_get_columnvalues_single_column
284
+ # assert_equal(["R1C1", "R2C1", "R3C1"], $ff.table(:index, 1).column_values(1))
285
+ # end
286
+
287
+ def test_colspan
288
+ assert_equal(2, $ff.table(:index, 3)[2][1].colspan)
289
+ assert_equal(1, $ff.table(:index, 3)[1][1].colspan)
290
+ assert_equal(3, $ff.table(:index, 3)[4][1].colspan)
291
+ end
292
+
293
+ def test_get_columnvalues_multiple_column
294
+ assert_equal(["R1C1", "R2C1", "R3C1"], $ff.table(:index, 2).column_values(1))
295
+ assert_equal(["R1C3", "R2C3", "R3C3"], $ff.table(:index, 2).column_values(3))
296
+ end
297
+
298
+ def test_get_columnvalues_with_colspan
299
+ assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], $ff.table(:index, 3).column_values(1))
300
+ end
301
+
302
+ def test_get_rowvalues_full_row
303
+ assert_equal(["R1C1", "R1C2", "R1C3"], $ff.table(:index, 3).row_values(1))
304
+ end
305
+
306
+ def test_get_rowvalues_with_colspan
307
+ assert_equal(["R2C1", "R2C2"], $ff.table(:index, 3).row_values(2))
308
+ end
309
+
310
+ def test_getrowvalues_with_rowspan
311
+ assert_equal(["R5C1", "R5C2", "R5C3"], $ff.table(:index, 3).row_values(5))
312
+ assert_equal(["R6C2", "R6C3"], $ff.table(:index, 3).row_values(6))
313
+ end
314
+ end
315
+
316
+ class TC_Tables_Complex < Test::Unit::TestCase
317
+ include FireWatir
318
+ def setup
319
+ $ff.goto($htmlRoot + "complex_table.html")
320
+ end
321
+
322
+ def test_complex_table_access
323
+ table = $ff.table(:index,1)
324
+
325
+ assert_equal("subtable1 Row 1 Col1",table[1][1].table(:index,1)[1][1].text.strip)
326
+ assert_equal("subtable1 Row 1 Col2",table[1][1].table(:index,1)[1][2].text.strip)
327
+ assert_equal("subtable2 Row 1 Col2",table[2][1].table(:index,1)[1][2].text.strip)
328
+ assert_equal("subtable2 Row 1 Col1",table[2][1].table(:index,1)[1][1].text.strip)
329
+ end
330
+ end
331
+
332
+ class TC_Tables_Display < Test::Unit::TestCase
333
+ include FireWatir
334
+ include MockStdoutTestCase
335
+
336
+ def test_showTables
337
+ $ff.goto($htmlRoot + "table1.html")
338
+ $stdout = @mockout
339
+ $ff.showTables
340
+ assert_equal(<<END_OF_MESSAGE, @mockout)
341
+ There are 7 tables
342
+ table: id: tblTest
343
+ rows: 2
344
+ columns: 2
345
+ index: 1
346
+ table: id: t1
347
+ rows: 5
348
+ columns: 1
349
+ index: 2
350
+ table: id: t2
351
+ rows: 2
352
+ columns: 2
353
+ index: 3
354
+ table: id:
355
+ rows: 1
356
+ columns: 2
357
+ index: 4
358
+ table: id: body_test
359
+ rows: 5
360
+ columns: 1
361
+ index: 5
362
+ table: id: pic_table
363
+ rows: 2
364
+ columns: 2
365
+ index: 6
366
+ table: id: tblTest1
367
+ rows: 5
368
+ columns: 1
369
+ index: 7
370
+ END_OF_MESSAGE
371
+ end
372
+ end
@@ -0,0 +1,184 @@
1
+ # feature tests for Tables
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_Tables_XPath < Test::Unit::TestCase
8
+ include FireWatir
9
+
10
+ def setup
11
+ $ff.goto($htmlRoot + "table1.html")
12
+ end
13
+
14
+ def test_Table_Exists
15
+ assert(!$ff.table(:xpath , "//table[@id = 'missingTable']").exists?)
16
+ assert($ff.table(:xpath, "//table[@id = 't1']").exists?)
17
+ end
18
+
19
+ def test_element_by_xpath_class
20
+ element = $ff.element_by_xpath("//table[@id = 't1']")
21
+ assert(element.instance_of?(Table),"element class should be #{Table}; got #{element.class}")
22
+ # FIXME really bizarre: this one should be a Table, but
23
+ # Firefox.element_factory gets HTMLAnchorElement as input
24
+ # TODO: If element is not present, this should return null or raises exception
25
+ #element = $ff.element_by_xpath("//table[@id = 'missingTable']")
26
+ #assert(element.instance_of?(Table),"element class should be #{Table}; got #{element.class}")
27
+ end
28
+
29
+ def test_rows
30
+ assert_raises(UnknownObjectException ){ $ff.table(:xpath, "//table[@id = 'missingTable']").row_count }
31
+ assert_raises(UnknownObjectException){ $ff.table(:xpath, "//table[@bad_attribute = 99]").row_count }
32
+
33
+ assert_equal(5, $ff.table(:xpath, "//table[@id = 't1']").row_count) # 4 rows and a header
34
+ assert_equal(5, $ff.table(:xpath, "//table[@id = 't1']").rows.length)
35
+
36
+ # test the each iterator on rows - ie, go through each cell
37
+ row = $ff.table(:xpath, "//table[@id = 't1']")[2]
38
+ count = 1
39
+ row.each do |cell|
40
+ if count == 1
41
+ assert_equal('Row 1 Col1', cell.to_s.strip)
42
+ elsif count==2
43
+ assert_equal('Row 1 Col2', cell.to_s.strip)
44
+ end
45
+ count += 1
46
+ end
47
+ assert_equal(2, count -1)
48
+ assert_equal(2, $ff.table(:xpath, "//table[@id = 't1']")[2].column_count)
49
+ end
50
+
51
+ def test_dynamic_tables
52
+ t = $ff.table(:xpath, "//table[@id = 't1']")
53
+ assert_equal(5, t.row_count)
54
+
55
+ $ff.button(:xpath, "//input[@value = 'add row']").click
56
+ assert_equal(6, t.row_count)
57
+ end
58
+
59
+ def test_columns
60
+ assert_raises(UnknownObjectException ){ $ff.table(:xpath, "//table[@id = 'missingTable']").column_count }
61
+ assert_equal(1, $ff.table(:xpath, "//table[@id = 't1']").column_count) # row one has 1 cell with a colspan of 2
62
+ end
63
+
64
+ def test_to_a
65
+ table1Expected = [["Table 2"], ["Row 1 Col1" , "Row 1 Col2"] ,[ "Row 2 Col1" , "Row 2 Col2"],[ "Row 3 Col1" , "Row 3 Col2"],[ "Row 4 Col1" , "Row 4 Col2"] ]
66
+ assert_equal(table1Expected, $ff.table(:xpath, "//table[@id = 't1']").to_a )
67
+ end
68
+
69
+ def test_links_and_images_in_table
70
+ table = $ff.table(:xpath, "//table[@id = 'pic_table']")
71
+ image = table[1][2].image(:index,1)
72
+ assert_equal("106", image.width)
73
+
74
+ link = table[2][2].link(:index,1)
75
+ assert_equal("Google", link.innerText)
76
+ end
77
+
78
+ #def test_cell_directly
79
+ # assert( $ff.cell(:id, 'cell1').exists? )
80
+ # assert(! $ff.cell(:id, 'no_exist').exists? )
81
+ # assert_equal( "Row 1 Col1", $ff.cell(:id, 'cell1').to_s.strip )
82
+ #
83
+ # # not really cell directly, but just to show another way of geting the cell
84
+ # assert_equal( "Row 1 Col1", $ff.table(:index,1)[1][1].to_s.strip )
85
+ #end
86
+
87
+ #def test_row_directly
88
+ # assert( $ff.row(:id, 'row1').exists? )
89
+ # assert(! $ff.row(:id, 'no_exist').exists? )
90
+ #
91
+ # assert_equal('Row 2 Col1' , $ff.row(:id, 'row1')[1].to_s.strip )
92
+ #end
93
+
94
+ def test_row_iterator
95
+ t = $ff.table(:xpath, "//table[@id = 't1']")
96
+ count = 1
97
+ t.each do |row|
98
+ if count == 1
99
+ assert("Table 2", row[1].text)
100
+ elsif count == 2
101
+ assert("Row 1 Col1", row[1].text)
102
+ assert("Row 1 Col2", row[2].text)
103
+ elsif count == 3
104
+ assert("Row 2 Col1", row[1].text)
105
+ assert("Row 2 Col2", row[2].text)
106
+ elsif count == 4
107
+ assert("Row 3 Col1", row[1].text)
108
+ assert("Row 4 Col2", row[2].text)
109
+ elsif count == 5
110
+ assert("Row 4 Col1", row[1].text)
111
+ assert("Row 4 Col2", row[2].text)
112
+ end
113
+ count += 1
114
+ end
115
+ end
116
+
117
+ def test_row_collection
118
+ t = $ff.table(:xpath, "//table[@id = 't1']")
119
+ count = 1
120
+ t.rows.each do |row|
121
+ if count == 1
122
+ assert("Table 2", row[1].text)
123
+ elsif count == 2
124
+ assert("Row 1 Col1", row[1].text)
125
+ assert("Row 1 Col2", row[2].text)
126
+ elsif count == 3
127
+ assert("Row 2 Col1", row[1].text)
128
+ assert("Row 2 Col2", row[2].text)
129
+ elsif count == 4
130
+ assert("Row 3 Col1", row[1].text)
131
+ assert("Row 4 Col2", row[2].text)
132
+ elsif count == 5
133
+ assert("Row 4 Col1", row[1].text)
134
+ assert("Row 4 Col2", row[2].text)
135
+ end
136
+ count += 1
137
+ end
138
+ end
139
+
140
+ #def test_table_body
141
+ # assert_equal( 1, $ff.table(:index,1).bodies.length )
142
+ # assert_equal( 3, $ff.table(:id, 'body_test' ).bodies.length )
143
+ #
144
+ # count = 1
145
+ # $ff.table(:id, 'body_test').bodies.each do |n|
146
+ #
147
+ # # do something better here!
148
+ # # n.flash # this line commented out to speed up the test
149
+ #
150
+ # case count
151
+ # when 1
152
+ # compare_text = "This text is in the FRST TBODY."
153
+ # when 2
154
+ # compare_text = "This text is in the SECOND TBODY."
155
+ # when 3
156
+ # compare_text = "This text is in the THIRD TBODY."
157
+ # end
158
+ #
159
+ # assert_equal(compare_text, n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
160
+ #
161
+ # count += 1
162
+ # end
163
+ # assert_equal( count - 1, $ff.table(:id, 'body_test').bodies.length )
164
+ #
165
+ # assert_equal( "This text is in the THIRD TBODY." ,$ff.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
166
+ #
167
+ # # iterate through all the rows in a table body
168
+ # count = 1
169
+ # $ff.table(:id, 'body_test').body(:index, 2).each do | row |
170
+ # # row.flash # this line commented out, to speed up the tests
171
+ # if count == 1
172
+ # assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
173
+ # elsif count == 1 # BUG: Huh?
174
+ # assert_equal('This text is also in the SECOND TBODY.', row[1].text.strip )
175
+ # end
176
+ # count+=1
177
+ # end
178
+ # end
179
+
180
+ def test_table_container
181
+ assert_nothing_raised { $ff.table(:id, 't1').html }
182
+ end
183
+ end
184
+