firewatir 1.2.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/lib/firewatir.rb +50 -0
  2. data/lib/firewatir/MozillaBaseElement.rb +1863 -0
  3. data/lib/firewatir/container.rb +534 -0
  4. data/lib/firewatir/exceptions.rb +10 -0
  5. data/lib/firewatir/firefox.rb +1127 -0
  6. data/lib/firewatir/htmlelements.rb +1911 -0
  7. data/lib/firewatir/version.rb +5 -0
  8. data/{firewatir → lib/firewatir}/winClicker.rb +0 -0
  9. data/{firewatir → lib/firewatir}/x11.rb +0 -0
  10. data/unittests/attach_to_new_window_test.rb +20 -12
  11. data/unittests/bug_fixes_test.rb +79 -69
  12. data/unittests/buttons_xpath_test.rb +45 -44
  13. data/unittests/checkbox_test.rb +86 -85
  14. data/unittests/checkbox_xpath_test.rb +58 -58
  15. data/unittests/div_test.rb +117 -115
  16. data/unittests/filefield_test.rb +12 -12
  17. data/unittests/filefield_xpath_test.rb +11 -11
  18. data/unittests/form_test.rb +134 -133
  19. data/unittests/frame_test.rb +42 -41
  20. data/unittests/hidden_test.rb +40 -40
  21. data/unittests/hidden_xpath_test.rb +32 -32
  22. data/unittests/images_test.rb +85 -84
  23. data/unittests/images_xpath_test.rb +57 -56
  24. data/unittests/iostring_test.rb +1 -1
  25. data/unittests/javascript_test.rb +42 -38
  26. data/unittests/links_test.rb +88 -86
  27. data/unittests/links_xpath_test.rb +38 -38
  28. data/unittests/mozilla_all_tests.rb +2 -14
  29. data/unittests/pre_test.rb +27 -25
  30. data/unittests/radios_test.rb +86 -86
  31. data/unittests/radios_xpath_test.rb +48 -48
  32. data/unittests/redirect_test.rb +20 -19
  33. data/unittests/selectbox_test.rb +72 -71
  34. data/unittests/selectbox_xpath_test.rb +58 -56
  35. data/unittests/setup.rb +22 -27
  36. data/unittests/table_test.rb +89 -88
  37. data/unittests/table_xpath_test.rb +37 -36
  38. data/unittests/textfields_test.rb +105 -102
  39. data/unittests/textfields_xpath_test.rb +53 -52
  40. metadata +37 -18
  41. data/MozillaBaseElement.rb +0 -1780
  42. data/container.rb +0 -900
  43. data/firewatir.rb +0 -1195
  44. data/firewatir/exceptions.rb +0 -44
  45. data/firewatir/testUnitAddons.rb +0 -8
  46. data/htmlelements.rb +0 -2281
  47. data/unittests/buttons_test.rb +0 -215
data/unittests/setup.rb CHANGED
@@ -1,35 +1,30 @@
1
- END {$ff.close if $ff} # close ff at completion of the tests
1
+ $SETUP_LOADED = true
2
2
 
3
- # libraries used by feature tests
4
- require 'firewatir'
5
- require 'test/unit'
6
- require 'test/unit/ui/console/testrunner'
7
- require 'firewatir/testUnitAddons'
8
- require 'unittests/iostring'
3
+ $myDir = File.expand_path(File.dirname(__FILE__))
9
4
 
10
5
  topdir = File.join(File.dirname(__FILE__), '..')
11
- Dir.chdir topdir do
12
- $all_tests = Dir["unittests/*_test.rb"]
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
13
18
  end
14
- $non_core_tests = [ ].collect {|x| "unittests/#{x}_test.rb"}
15
19
 
16
- $core_tests = $all_tests - $non_core_tests
20
+ require 'unittests/setup/testUnitAddons'
21
+ require 'unittests/iostring'
17
22
 
18
- def start_ff_with_logger
19
- $ff = FireWatir::Firefox.new()
20
- # $ff.logger = Watir::WatirLogger.new( 'debug.txt', 4, 10000 )
21
- #$ff.set_fast_speed
23
+ commondir = File.join(topdir, '..', 'watir-common')
24
+ $all_tests = []
25
+ Dir.chdir topdir do
26
+ $all_tests += Dir["unittests/*_test.rb"]
22
27
  end
23
-
24
- def set_local_dir
25
- $myDir = File.expand_path(File.dirname(__FILE__))
26
- $myDir.sub!( %r{/cygdrive/(\w)/}, '\1:/' ) # convert from cygwin to dos
27
- # if you run the unit tests form a local file system use this line
28
- $htmlRoot = "file://#{$myDir}/html/"
29
- # if you run the unit tests from a web server use this line
30
- # $htmlRoot = "http://localhost:8080/watir/html/"
28
+ Dir.chdir commondir do
29
+ $all_tests += Dir["unittests/*_test.rb"]
31
30
  end
32
-
33
- start_ff_with_logger
34
- set_local_dir
35
-
@@ -1,42 +1,43 @@
1
1
  # feature tests for Tables
2
2
  # revision: $Revision: 1.0 $
3
3
 
4
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_Tables < Test::Unit::TestCase
8
- include FireWatir
8
+
9
9
 
10
10
  def setup
11
- $ff.goto($htmlRoot + "table1.html")
11
+ goto_page("table1.html")
12
12
  end
13
13
 
14
14
  def test_Table_Exists
15
- assert(!$ff.table(:id, 'missingTable').exists?)
16
- assert(!$ff.table(:index, 33).exists?)
15
+ assert_false(browser.table(:id, 'missingTable').exists?)
16
+ assert_false(browser.table(:index, 33).exists?)
17
17
 
18
- assert($ff.table(:id, 't1').exists?)
19
- assert($ff.table(:id, /t/).exists?)
20
- assert(!$ff.table(:id, /missing_table/).exists?)
18
+ assert(browser.table(:id, 't1').exists?)
19
+ assert(browser.table(:id, /t/).exists?)
20
+ assert_false(browser.table(:id, /missing_table/).exists?)
21
21
 
22
- assert($ff.table(:index, 1).exists?)
23
- assert($ff.table(:index, 2).exists?)
22
+ assert(browser.table(:index, 1).exists?)
23
+ assert(browser.table(:index, 2).exists?)
24
24
  end
25
25
 
26
+ tag_method :test_rows, :fails_on_ie
26
27
  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 }
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 }
30
31
 
31
- assert_equal(2, $ff.table(:index, 1).row_count)
32
- assert_equal(2, $ff.table(:index, 1).rows.length)
32
+ assert_equal(2, browser.table(:index, 1).row_count)
33
+ assert_equal(2, browser.table(:index, 1).rows.length)
33
34
 
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)
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)
37
38
 
38
39
  # test the each iterator on rows - ie, go through each cell
39
- row = $ff.table(:index, 2)[2]
40
+ row = browser.table(:index, 2)[2]
40
41
  count = 1
41
42
  row.each do |cell|
42
43
  if count == 1
@@ -47,31 +48,31 @@ class TC_Tables < Test::Unit::TestCase
47
48
  count += 1
48
49
  end
49
50
  assert_equal(2, count -1)
50
- assert_equal(2, $ff.table(:index, 2)[2].column_count)
51
+ assert_equal(2, browser.table(:index, 2)[2].column_count)
51
52
  end
52
53
 
53
54
  def test_dynamic_tables
54
- t = $ff.table(:id, 't1')
55
+ t = browser.table(:id, 't1')
55
56
  assert_equal(5, t.row_count)
56
57
 
57
- $ff.button(:value, 'add row').click
58
+ browser.button(:value, 'add row').click
58
59
  assert_equal(6, t.row_count)
59
60
  end
60
61
 
61
62
  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
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
66
67
  end
67
68
 
68
69
  def test_to_a
69
70
  table1Expected = [ ["Row 1 Col1" , "Row 1 Col2"] ,[ "Row 2 Col1" , "Row 2 Col2"] ]
70
- assert_equal(table1Expected, $ff.table(:index , 1).to_a )
71
+ assert_equal(table1Expected, browser.table(:index , 1).to_a )
71
72
  end
72
73
 
73
74
  def test_links_and_images_in_table
74
- table = $ff.table(:id, 'pic_table')
75
+ table = browser.table(:id, 'pic_table')
75
76
  image = table[1][2].image(:index,1)
76
77
  assert_equal("106", image.width)
77
78
 
@@ -80,24 +81,24 @@ class TC_Tables < Test::Unit::TestCase
80
81
  end
81
82
 
82
83
  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 )
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 )
86
87
 
87
88
  # 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)
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)
90
91
  end
91
92
 
92
93
  def test_row_directly
93
- assert( $ff.row(:id, 'row1').exists? )
94
- assert(! $ff.row(:id, 'no_exist').exists? )
94
+ assert( browser.row(:id, 'row1').exists? )
95
+ assert_false( browser.row(:id, 'no_exist').exists? )
95
96
 
96
- assert_equal('Row 2 Col1' , $ff.row(:id, 'row1')[1].to_s.strip )
97
+ assert_equal('Row 2 Col1' , browser.row(:id, 'row1')[1].to_s.strip )
97
98
  end
98
99
 
99
100
  def test_row_iterator
100
- t = $ff.table(:index, 1)
101
+ t = browser.table(:index, 1)
101
102
  count = 1
102
103
  t.each do |row|
103
104
  if count == 1
@@ -112,7 +113,7 @@ class TC_Tables < Test::Unit::TestCase
112
113
  end
113
114
 
114
115
  def test_row_collection
115
- t = $ff.table(:index,1)
116
+ t = browser.table(:index,1)
116
117
  count = 1
117
118
  t.rows.each do |row|
118
119
  if count == 1
@@ -127,11 +128,11 @@ class TC_Tables < Test::Unit::TestCase
127
128
  end
128
129
 
129
130
  #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 )
131
+ # assert_equal( 1, browser.table(:index,1).bodies.length )
132
+ # assert_equal( 3, browser.table(:id, 'body_test' ).bodies.length )
132
133
  #
133
134
  # count = 1
134
- # $ff.table(:id, 'body_test').bodies.each do |n|
135
+ # browser.table(:id, 'body_test').bodies.each do |n|
135
136
  #
136
137
  # # do something better here!
137
138
  # n.flash # this line commented out to speed up the test
@@ -149,13 +150,13 @@ class TC_Tables < Test::Unit::TestCase
149
150
  #
150
151
  # count += 1
151
152
  # end
152
- # assert_equal( count - 1, $ff.table(:id, 'body_test').bodies.length )
153
+ # assert_equal( count - 1, browser.table(:id, 'body_test').bodies.length )
153
154
  #
154
- # assert_equal( "This text is in the THIRD TBODY." ,$ff.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
155
+ # assert_equal( "This text is in the THIRD TBODY." ,browser.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
155
156
  #
156
157
  # # iterate through all the rows in a table body
157
158
  # count = 1
158
- # $ff.table(:id, 'body_test').body(:index, 2).each do | row |
159
+ # browser.table(:id, 'body_test').body(:index, 2).each do | row |
159
160
  # # row.flash # this line commented out, to speed up the tests
160
161
  # if count == 1
161
162
  # assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
@@ -167,19 +168,19 @@ class TC_Tables < Test::Unit::TestCase
167
168
  #end
168
169
 
169
170
  def test_table_container
170
- assert_nothing_raised { $ff.table(:id, 't1').html }
171
+ assert_nothing_raised { browser.table(:id, 't1').html }
171
172
  end
172
173
  end
173
174
 
174
175
  class TC_Tables_Simple < Test::Unit::TestCase
175
- include FireWatir
176
+
176
177
 
177
178
  def setup
178
- $ff.goto($htmlRoot + "simple_table.html")
179
+ goto_page("simple_table.html")
179
180
  end
180
181
 
181
182
  def test_simple_table_access
182
- table = $ff.table(:index,1)
183
+ table = browser.table(:index,1)
183
184
 
184
185
  assert_equal("Row 3 Col1",table[3][1].text.strip)
185
186
  assert_equal("Row 1 Col1",table[1][1].text.strip)
@@ -189,47 +190,47 @@ class TC_Tables_Simple < Test::Unit::TestCase
189
190
  end
190
191
 
191
192
  class TC_Tables_Buttons < Test::Unit::TestCase
192
- include FireWatir
193
+
193
194
 
194
195
  def setup
195
- $ff.goto($htmlRoot + "simple_table_buttons.html")
196
+ goto_page("simple_table_buttons.html")
196
197
  end
197
198
 
198
199
  def test_simple_table_buttons
199
- table = $ff.table(:index,1)
200
+ table = browser.table(:index,1)
200
201
 
201
202
  table[1][1].button(:index,1).click
202
- assert($ff.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
203
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
203
204
  table[2][1].button(:index,1).click
204
- assert($ff.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
205
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
205
206
 
206
207
  table[1][1].button(:id,'b1').click
207
- assert($ff.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
208
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
208
209
 
209
210
  assert_raises(UnknownObjectException ) { table[1][1].button(:id,'b_missing').click }
210
211
 
211
212
  table[3][1].button(:index,2).click
212
- assert($ff.text_field(:name,"confirmtext").verify_contains(/TOO/i))
213
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
213
214
 
214
215
  table[3][1].button(:value ,"Click too").click
215
- assert($ff.text_field(:name,"confirmtext").verify_contains(/TOO/i))
216
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
216
217
 
217
- $ff.table(:index,1)[4][1].text_field(:index,1).set("123")
218
- assert($ff.text_field(:index,2).verify_contains("123"))
218
+ browser.table(:index,1)[4][1].text_field(:index,1).set("123")
219
+ assert(browser.text_field(:index,2).verify_contains("123"))
219
220
 
220
221
  # check when a cell contains 2 objects
221
222
 
222
223
  # 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 )
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 )
226
227
 
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 )
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 )
229
230
  end
230
231
 
231
232
  def test_simple_table_gif
232
- table = $ff.table(:index,2)
233
+ table = browser.table(:index,2)
233
234
 
234
235
  assert_match( /1\.gif/ , table[1][1].image( :index,1).src )
235
236
  assert_match( /2\.gif/ , table[1][2].image( :index ,1).src )
@@ -239,7 +240,7 @@ class TC_Tables_Buttons < Test::Unit::TestCase
239
240
  assert_match( /2\.gif/ , table[3][2].image( :index ,1).src )
240
241
  assert_match( /3\.gif/ , table[3][3].image( :index ,1).src )
241
242
 
242
- table = $ff.table(:index,3)
243
+ table = browser.table(:index,3)
243
244
  assert_match( /1\.gif/ , table[1][1].image( :index ,1).src )
244
245
  assert_match( /2\.gif/ , table[1][1].image( :index ,2).src )
245
246
  assert_match( /3\.gif/ , table[1][1].image( :index ,3).src )
@@ -250,7 +251,7 @@ class TC_Tables_Buttons < Test::Unit::TestCase
250
251
  end
251
252
 
252
253
  def test_table_with_hidden_or_visible_rows
253
- t = $ff.table(:id , 'show_hide')
254
+ t = browser.table(:id , 'show_hide')
254
255
 
255
256
  # expand the table
256
257
  t.each do |r|
@@ -266,61 +267,61 @@ class TC_Tables_Buttons < Test::Unit::TestCase
266
267
  end
267
268
 
268
269
  # def test_table_from_element
269
- # button = $ff.button(:id, "b1")
270
- # table = Table.create_from_element($ff, button)
270
+ # button = browser.button(:id, "b1")
271
+ # table = Table.create_from_element(browser, button)
271
272
 
272
273
  # table[2][1].button(:index, 1).click
273
- # assert($ff.textField(:name, "confirmtext").verify_contains(/CLICK2/i))
274
+ # assert(browser.textField(:name, "confirmtext").verify_contains(/CLICK2/i))
274
275
  # end
275
276
  end
276
277
 
277
278
  class TC_Table_Columns < Test::Unit::TestCase
278
- include FireWatir
279
+
279
280
  def setup
280
- $ff.goto($htmlRoot + "simple_table_columns.html")
281
+ goto_page("simple_table_columns.html")
281
282
  end
282
283
 
283
284
  # def test_get_columnvalues_single_column
284
- # assert_equal(["R1C1", "R2C1", "R3C1"], $ff.table(:index, 1).column_values(1))
285
+ # assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 1).column_values(1))
285
286
  # end
286
287
 
287
288
  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)
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)
291
292
  end
292
293
 
293
294
  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))
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))
296
297
  end
297
298
 
298
299
  def test_get_columnvalues_with_colspan
299
- assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], $ff.table(:index, 3).column_values(1))
300
+ assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], browser.table(:index, 3).column_values(1))
300
301
  end
301
302
 
302
303
  def test_get_rowvalues_full_row
303
- assert_equal(["R1C1", "R1C2", "R1C3"], $ff.table(:index, 3).row_values(1))
304
+ assert_equal(["R1C1", "R1C2", "R1C3"], browser.table(:index, 3).row_values(1))
304
305
  end
305
306
 
306
307
  def test_get_rowvalues_with_colspan
307
- assert_equal(["R2C1", "R2C2"], $ff.table(:index, 3).row_values(2))
308
+ assert_equal(["R2C1", "R2C2"], browser.table(:index, 3).row_values(2))
308
309
  end
309
310
 
310
311
  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))
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))
313
314
  end
314
315
  end
315
316
 
316
317
  class TC_Tables_Complex < Test::Unit::TestCase
317
- include FireWatir
318
+
318
319
  def setup
319
- $ff.goto($htmlRoot + "complex_table.html")
320
+ goto_page("complex_table.html")
320
321
  end
321
322
 
322
323
  def test_complex_table_access
323
- table = $ff.table(:index,1)
324
+ table = browser.table(:index,1)
324
325
 
325
326
  assert_equal("subtable1 Row 1 Col1",table[1][1].table(:index,1)[1][1].text.strip)
326
327
  assert_equal("subtable1 Row 1 Col2",table[1][1].table(:index,1)[1][2].text.strip)
@@ -330,13 +331,13 @@ class TC_Tables_Complex < Test::Unit::TestCase
330
331
  end
331
332
 
332
333
  class TC_Tables_Display < Test::Unit::TestCase
333
- include FireWatir
334
334
  include MockStdoutTestCase
335
335
 
336
+ tag_method :test_showTables, :fails_on_ie
336
337
  def test_showTables
337
- $ff.goto($htmlRoot + "table1.html")
338
+ goto_page("table1.html")
338
339
  $stdout = @mockout
339
- $ff.showTables
340
+ browser.showTables
340
341
  assert_equal(<<END_OF_MESSAGE, @mockout)
341
342
  There are 7 tables
342
343
  table: id: tblTest
@@ -1,40 +1,41 @@
1
1
  # feature tests for Tables
2
2
  # revision: $Revision: 1.0 $
3
3
 
4
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_Tables_XPath < Test::Unit::TestCase
8
- include FireWatir
8
+
9
9
 
10
10
  def setup
11
- $ff.goto($htmlRoot + "table1.html")
11
+ goto_page("table1.html")
12
12
  end
13
13
 
14
14
  def test_Table_Exists
15
- assert(!$ff.table(:xpath , "//table[@id = 'missingTable']").exists?)
16
- assert($ff.table(:xpath, "//table[@id = 't1']").exists?)
15
+ assert_false(browser.table(:xpath , "//table[@id = 'missingTable']").exists?)
16
+ assert(browser.table(:xpath, "//table[@id = 't1']").exists?)
17
17
  end
18
18
 
19
+ tag_method :test_element_by_xpath_class, :fails_on_ie
19
20
  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}")
21
+ element = browser.element_by_xpath("//table[@id = 't1']")
22
+ assert_class(element, 'Table')
22
23
  # FIXME really bizarre: this one should be a Table, but
23
24
  # Firefox.element_factory gets HTMLAnchorElement as input
24
25
  # TODO: If element is not present, this should return null or raises exception
25
- #element = $ff.element_by_xpath("//table[@id = 'missingTable']")
26
+ #element = browser.element_by_xpath("//table[@id = 'missingTable']")
26
27
  #assert(element.instance_of?(Table),"element class should be #{Table}; got #{element.class}")
27
28
  end
28
29
 
29
30
  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 }
31
+ assert_raises(UnknownObjectException ){ browser.table(:xpath, "//table[@id = 'missingTable']").row_count }
32
+ assert_raises(UnknownObjectException){ browser.table(:xpath, "//table[@bad_attribute = 99]").row_count }
32
33
 
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)
34
+ assert_equal(5, browser.table(:xpath, "//table[@id = 't1']").row_count) # 4 rows and a header
35
+ assert_equal(5, browser.table(:xpath, "//table[@id = 't1']").rows.length)
35
36
 
36
37
  # test the each iterator on rows - ie, go through each cell
37
- row = $ff.table(:xpath, "//table[@id = 't1']")[2]
38
+ row = browser.table(:xpath, "//table[@id = 't1']")[2]
38
39
  count = 1
39
40
  row.each do |cell|
40
41
  if count == 1
@@ -45,29 +46,29 @@ class TC_Tables_XPath < Test::Unit::TestCase
45
46
  count += 1
46
47
  end
47
48
  assert_equal(2, count -1)
48
- assert_equal(2, $ff.table(:xpath, "//table[@id = 't1']")[2].column_count)
49
+ assert_equal(2, browser.table(:xpath, "//table[@id = 't1']")[2].column_count)
49
50
  end
50
51
 
51
52
  def test_dynamic_tables
52
- t = $ff.table(:xpath, "//table[@id = 't1']")
53
+ t = browser.table(:xpath, "//table[@id = 't1']")
53
54
  assert_equal(5, t.row_count)
54
55
 
55
- $ff.button(:xpath, "//input[@value = 'add row']").click
56
+ browser.button(:xpath, "//input[@value = 'add row']").click
56
57
  assert_equal(6, t.row_count)
57
58
  end
58
59
 
59
60
  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
61
+ assert_raises(UnknownObjectException ){ browser.table(:xpath, "//table[@id = 'missingTable']").column_count }
62
+ assert_equal(1, browser.table(:xpath, "//table[@id = 't1']").column_count) # row one has 1 cell with a colspan of 2
62
63
  end
63
64
 
64
65
  def test_to_a
65
66
  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
+ assert_equal(table1Expected, browser.table(:xpath, "//table[@id = 't1']").to_a )
67
68
  end
68
69
 
69
70
  def test_links_and_images_in_table
70
- table = $ff.table(:xpath, "//table[@id = 'pic_table']")
71
+ table = browser.table(:xpath, "//table[@id = 'pic_table']")
71
72
  image = table[1][2].image(:index,1)
72
73
  assert_equal("106", image.width)
73
74
 
@@ -76,23 +77,23 @@ class TC_Tables_XPath < Test::Unit::TestCase
76
77
  end
77
78
 
78
79
  #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 )
80
+ # assert( browser.cell(:id, 'cell1').exists? )
81
+ # assert_false( browser.cell(:id, 'no_exist').exists? )
82
+ # assert_equal( "Row 1 Col1", browser.cell(:id, 'cell1').to_s.strip )
82
83
  #
83
84
  # # 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
+ # assert_equal( "Row 1 Col1", browser.table(:index,1)[1][1].to_s.strip )
85
86
  #end
86
87
 
87
88
  #def test_row_directly
88
- # assert( $ff.row(:id, 'row1').exists? )
89
- # assert(! $ff.row(:id, 'no_exist').exists? )
89
+ # assert( browser.row(:id, 'row1').exists? )
90
+ # assert_false( browser.row(:id, 'no_exist').exists? )
90
91
  #
91
- # assert_equal('Row 2 Col1' , $ff.row(:id, 'row1')[1].to_s.strip )
92
+ # assert_equal('Row 2 Col1' , browser.row(:id, 'row1')[1].to_s.strip )
92
93
  #end
93
94
 
94
95
  def test_row_iterator
95
- t = $ff.table(:xpath, "//table[@id = 't1']")
96
+ t = browser.table(:xpath, "//table[@id = 't1']")
96
97
  count = 1
97
98
  t.each do |row|
98
99
  if count == 1
@@ -115,7 +116,7 @@ class TC_Tables_XPath < Test::Unit::TestCase
115
116
  end
116
117
 
117
118
  def test_row_collection
118
- t = $ff.table(:xpath, "//table[@id = 't1']")
119
+ t = browser.table(:xpath, "//table[@id = 't1']")
119
120
  count = 1
120
121
  t.rows.each do |row|
121
122
  if count == 1
@@ -138,11 +139,11 @@ class TC_Tables_XPath < Test::Unit::TestCase
138
139
  end
139
140
 
140
141
  #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 )
142
+ # assert_equal( 1, browser.table(:index,1).bodies.length )
143
+ # assert_equal( 3, browser.table(:id, 'body_test' ).bodies.length )
143
144
  #
144
145
  # count = 1
145
- # $ff.table(:id, 'body_test').bodies.each do |n|
146
+ # browser.table(:id, 'body_test').bodies.each do |n|
146
147
  #
147
148
  # # do something better here!
148
149
  # # n.flash # this line commented out to speed up the test
@@ -160,13 +161,13 @@ class TC_Tables_XPath < Test::Unit::TestCase
160
161
  #
161
162
  # count += 1
162
163
  # end
163
- # assert_equal( count - 1, $ff.table(:id, 'body_test').bodies.length )
164
+ # assert_equal( count - 1, browser.table(:id, 'body_test').bodies.length )
164
165
  #
165
- # assert_equal( "This text is in the THIRD TBODY." ,$ff.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
166
+ # assert_equal( "This text is in the THIRD TBODY." ,browser.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
166
167
  #
167
168
  # # iterate through all the rows in a table body
168
169
  # count = 1
169
- # $ff.table(:id, 'body_test').body(:index, 2).each do | row |
170
+ # browser.table(:id, 'body_test').body(:index, 2).each do | row |
170
171
  # # row.flash # this line commented out, to speed up the tests
171
172
  # if count == 1
172
173
  # assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
@@ -178,7 +179,7 @@ class TC_Tables_XPath < Test::Unit::TestCase
178
179
  # end
179
180
 
180
181
  def test_table_container
181
- assert_nothing_raised { $ff.table(:id, 't1').html }
182
+ assert_nothing_raised { browser.table(:id, 't1').html }
182
183
  end
183
184
  end
184
185