firewatir 1.6.2 → 1.6.5

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