firewatir 1.6.2 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,45 +1,49 @@
1
- # feature tests for file Fields
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_FileField < Test::Unit::TestCase
8
-
9
-
10
- def gotoPage()
11
- goto_page("fileupload.html")
12
- end
13
-
14
- def test_fileField_Exists
15
- gotoPage()
16
- #test for existance of 4 file area
17
- assert(browser.file_field(:name,"file1").exists?)
18
- assert(browser.file_field(:id,"file2").exists?)
19
- #test for missing
20
- assert_false(browser.file_field(:name, "missing").exists?)
21
- assert_false(browser.file_field(:name,"totallybogus").exists?)
22
- #pop one open and put something in it.
23
- browser.file_field(:name,"file3").set($htmlRoot + "fileupload.html")
24
- #click the upload button
25
- browser.button(:name,"upload").click
26
-
27
- assert(browser.text.include?("PASS"))
28
- end
29
-
30
- def test_iterator
31
- gotoPage()
32
- assert_equal(6, browser.file_fields.length)
33
- arrFileFields = browser.file_fields
34
- assert_equal("file1", arrFileFields[1].name)
35
- assert_equal("file2", arrFileFields[2].id)
36
- assert_equal("disabled", arrFileFields[3].name)
37
- assert_equal("file3", arrFileFields[4].name)
38
- assert_equal("beforetest", arrFileFields[5].name)
39
- assert_equal("aftertest", arrFileFields[6].name)
40
- arrFileFields.each do |fileField|
41
- assert_equal("file", fileField.type)
42
- end
43
- end
44
-
45
- end
1
+ # feature tests for file Fields
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_FileField < Test::Unit::TestCase
8
+
9
+
10
+ def setup
11
+ goto_page("fileupload.html")
12
+ end
13
+
14
+ def test_fileField_Exists
15
+ #test for existance of 4 file area
16
+ assert(browser.file_field(:name,"file1").exists?)
17
+ assert(browser.file_field(:id,"file2").exists?)
18
+ #test for missing
19
+ assert_false(browser.file_field(:name, "missing").exists?)
20
+ assert_false(browser.file_field(:name,"totallybogus").exists?)
21
+ #pop one open and put something in it.
22
+ browser.file_field(:name,"file3").set($htmlRoot + "fileupload.html")
23
+ #click the upload button
24
+ browser.button(:name,"upload").click
25
+
26
+ assert(browser.text.include?("PASS"))
27
+ end
28
+
29
+ def test_iterator
30
+ assert_equal(6, browser.file_fields.length)
31
+ arrFileFields = browser.file_fields
32
+ assert_equal("file1", arrFileFields[1].name)
33
+ assert_equal("file2", arrFileFields[2].id)
34
+ assert_equal("disabled", arrFileFields[3].name)
35
+ assert_equal("file3", arrFileFields[4].name)
36
+ assert_equal("beforetest", arrFileFields[5].name)
37
+ assert_equal("aftertest", arrFileFields[6].name)
38
+ arrFileFields.each do |fileField|
39
+ assert_equal("file", fileField.type)
40
+ end
41
+ end
42
+
43
+ def test_file_field_onchange
44
+ assert_equal("", browser.file_field(:name, 'file3').alt)
45
+ browser.file_field(:name,"file3").set($htmlRoot + "fileupload.html")
46
+ assert_equal("changed", browser.file_field(:name, 'file3').alt)
47
+ end
48
+
49
+ end
@@ -1,35 +1,35 @@
1
- # feature tests for TextArea Fields
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_FileField_XPath < Test::Unit::TestCase
8
-
9
-
10
- def gotoPage
11
- goto_page("fileupload.html")
12
- end
13
-
14
- def test_file_field_Exists
15
- gotoPage()
16
- #test for existance of 4 file area
17
- assert(browser.file_field(:xpath, "//input[@name='file1']").exists?)
18
- assert(browser.file_field(:xpath, "//input[@id='file2']").exists?)
19
- #test for missing
20
- assert_false(browser.file_field(:xpath, "//input[@name='missing']").exists?)
21
- assert_false(browser.file_field(:xpath, "//input[@name='totallybogus']").exists?)
22
- #pop one open and put something in it.
23
- browser.file_field(:xpath, "//input[@name='file3']").set($htmlRoot + "fileupload.html")
24
- #click the upload button
25
- browser.button(:xpath, "//input[@name='upload']").click
26
-
27
- assert(browser.text.include?("PASS"))
28
- end
29
-
30
- #def test_iterator
31
- # gotoPage()
32
- # assert_equal(6, browser.file_fields.length)
33
- #end
34
-
35
- end
1
+ # feature tests for TextArea Fields
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_FileField_XPath < Test::Unit::TestCase
8
+
9
+
10
+ def gotoPage
11
+ goto_page("fileupload.html")
12
+ end
13
+
14
+ def test_file_field_Exists
15
+ gotoPage()
16
+ #test for existance of 4 file area
17
+ assert(browser.file_field(:xpath, "//input[@name='file1']").exists?)
18
+ assert(browser.file_field(:xpath, "//input[@id='file2']").exists?)
19
+ #test for missing
20
+ assert_false(browser.file_field(:xpath, "//input[@name='missing']").exists?)
21
+ assert_false(browser.file_field(:xpath, "//input[@name='totallybogus']").exists?)
22
+ #pop one open and put something in it.
23
+ browser.file_field(:xpath, "//input[@name='file3']").set($htmlRoot + "fileupload.html")
24
+ #click the upload button
25
+ browser.button(:xpath, "//input[@name='upload']").click
26
+
27
+ assert(browser.text.include?("PASS"))
28
+ end
29
+
30
+ #def test_iterator
31
+ # gotoPage()
32
+ # assert_equal(6, browser.file_fields.length)
33
+ #end
34
+
35
+ end
@@ -1,308 +1,296 @@
1
- # feature tests for Forms
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_Forms2 < Test::Unit::TestCase # Note: there is no TC_Forms
8
-
9
-
10
- def setup
11
- goto_page("forms2.html")
12
- end
13
-
14
- def test_Form_Exists
15
- assert(browser.form(:name, "test2").exists?)
16
- assert_false(browser.form(:name, "missing").exists?)
17
-
18
- assert(browser.form("test2").exists?)
19
- assert_false(browser.form( "missing").exists?)
20
-
21
- assert(browser.form(:index, 1).exists?)
22
- assert_false(browser.form(:index, 88).exists?)
23
-
24
- assert(browser.form(:method, "get").exists?)
25
- assert_false(browser.form(:method, "missing").exists?)
26
-
27
- assert(browser.form(:id, 'f2').exists?)
28
- assert_false(browser.form(:id, 'missing').exists?)
29
-
30
- assert(browser.form(:action, /pass.html/).exists?)
31
- assert_false(browser.form(:action, "missing").exists?)
32
- end
33
-
34
- def test_ButtonInForm
35
- assert(browser.form(:name, "test2").button(:caption , "Submit").exists?)
36
- end
37
-
38
- # The following tests from bug 2261
39
- tag_method :test_form_html, :fails_on_ie
40
- def test_form_html
41
- assert_equal("\n<BR><INPUT value=\"Submit\" type=\"submit\">\n".downcase(),
42
- browser.form(:name, 'test2').html.downcase())
43
- end
44
- def test_form_flash
45
- assert_nothing_raised{ browser.form(:name, 'test2').flash }
46
- end
47
- def test_form_sub_element
48
- assert_equal('Click Me', browser.form(:index, 1).button(:name, 'b1').value)
49
- end
50
- end
51
-
52
- class TC_Form_Display < Test::Unit::TestCase
53
-
54
- include MockStdoutTestCase
55
-
56
- def test_showforms
57
- goto_page("forms2.html")
58
- $stdout = @mockout
59
- browser.showForms
60
- assert_equal(<<END_OF_MESSAGE, @mockout)
61
- There are 4 forms
62
- Form name:
63
- id:
64
- method: get
65
- action: pass.html
66
- Form name: test2
67
- id: f2
68
- method: get
69
- action: pass2.html
70
- Form name: test3
71
- id:
72
- method: get
73
- action: pass2.html
74
- Form name: test2
75
- id:
76
- method: get
77
- action: pass2.html
78
- END_OF_MESSAGE
79
- end
80
- end
81
-
82
- class TC_Forms3 < Test::Unit::TestCase
83
-
84
- def setup
85
- goto_page("forms3.html")
86
- end
87
-
88
- # The following tests from bug 2261
89
- def test_p_in_form
90
- browser.form(:name, 'buttonsubmit').p(:index, 1).text
91
- end
92
-
93
- def test_Form_Exists
94
- assert(browser.form(:name, "test2").exists?)
95
- assert_false(browser.form(:name, "missing").exists?)
96
-
97
- assert(browser.form("test2").exists?)
98
- assert_false(browser.form( "missing").exists?)
99
-
100
- assert(browser.form(:index, 1).exists?)
101
- assert_false(browser.form(:index, 88).exists?)
102
-
103
- assert(browser.form(:method, "get").exists?)
104
- assert_false(browser.form(:method, "missing").exists?)
105
-
106
- assert(browser.form(:action, "pass.html").exists?)
107
- assert_false(browser.form(:action, "missing").exists?)
108
- end
109
-
110
- def test_index_other_element_before_it
111
- # test for bug reported by Scott Pack, http://rubyforge.org/pipermail/wtr-general/2005-June/002223.html
112
- assert_equal("check1" , browser.checkbox(:index,1).name )
113
- end
114
-
115
- def test_reset
116
- browser.text_field(:id, "t1").set("Hello, reset test!")
117
- assert_equal(browser.text_field(:id, 't1').value, 'Hello, reset test!')
118
-
119
- browser.button(:id, "reset_button").click
120
- assert_equal("" , browser.text_field(:id, 't1').value )
121
-
122
- # also verify it works under a form
123
- browser.text_field(:id, "t1").set("reset test - using a form")
124
- assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
125
-
126
- browser.form(:index,2).button(:index,2).click
127
- assert_equal("" , browser.text_field(:id, 't1').value )
128
-
129
- # also verify it works under a form, this time using the :id attribute
130
- browser.text_field(:id, "t1").set("reset test - using a form")
131
- assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
132
-
133
- browser.form(:index,2).button(:id,'reset_button').click
134
- assert_equal("" , browser.text_field(:id, 't1').value )
135
- end
136
-
137
- ## def test_flash1
138
- ## browser.form(:name ,"test2").button(:caption , "Submit").flash
139
- ## end
140
- #
141
- def test_objects_with_same_name
142
- assert_equal('textfield' ,browser.text_field( :name , 'g1').value )
143
- assert_equal('button' ,browser.button( :name , 'g1').value )
144
- assert_equal('1' ,browser.checkbox( :name , 'g1').value )
145
- assert_equal('2' ,browser.radio( :name , 'g1').value )
146
-
147
- assert_equal('textfield' ,browser.text_field( :name , /g1/).value )
148
- assert_equal('button' ,browser.button( :name , /g1/).value )
149
- assert_equal('1' ,browser.checkbox( :name , /g1/).value )
150
- assert_equal('2' ,browser.radio( :name , /g1/).value )
151
-
152
- assert_equal('textfield_id' ,browser.text_field( :id , 'g1').value )
153
- assert_equal('button_id' ,browser.button( :id , 'g1').value )
154
- assert_equal('1_id' ,browser.checkbox( :id , 'g1').value )
155
- assert_equal('2_id' ,browser.radio( :id , 'g1').value )
156
-
157
- assert_equal('textfield_id' ,browser.text_field( :id , /g1/).value )
158
- assert_equal('button_id' ,browser.button( :id , /g1/).value )
159
- assert_equal('1_id' ,browser.checkbox( :id , /g1/).value )
160
- assert_equal('2_id' ,browser.radio( :id , /g1/).value )
161
- end
162
-
163
- # def test_flash2
164
- # browser.button(:value, 'Click Me').flash
165
- # assert_raises( Watir::UnknownObjectException ) { browser.text_field( :name , 'g177').flash }
166
- # end
167
-
168
- def test_submitWithImage
169
- assert( browser.button(:alt , "submit").exists? )
170
- assert( browser.button(:alt , /sub/).exists? )
171
-
172
- assert_false( browser.button(:alt , "missing").exists? )
173
- assert_false( browser.button(:alt , /missing/).exists? )
174
-
175
- #assert( browser.button(:src , "file:///#{$myDir}/html/images/button.jpg").exists? ) # this doesnt work for everybody
176
- assert( browser.button(:src , /button/).exists? )
177
-
178
- assert_false( browser.button(:src , "missing").exists? )
179
- assert_false( browser.button(:src , /missing/).exists? )
180
- assert_nothing_raised("raised an exception when it shouldnt have") { browser.button(:src , /button/).click }
181
-
182
- assert( browser.text.include?("PASS") )
183
- end
184
- end
185
-
186
- #class TC_Forms3_Display < Test::Unit::TestCase
187
- #
188
- # include MockStdoutTestCase # BUG in test: output not verified!
189
- # def test_show_stuff
190
- # goto_page("forms3.html")
191
- # $stdout = @mockout
192
- # browser.showAllObjects
193
- # puts browser.getText
194
- # puts browser.getHTML
195
- # end
196
- #end
197
-
198
- class TC_Forms4 < Test::Unit::TestCase
199
-
200
- def setup
201
- goto_page("forms4.html")
202
- end
203
-
204
- def test_find_text_field_ignoring_form
205
- assert_equal(browser.text_field(:name, 'name').value, 'apple') # should it raise a not-unique error instead?
206
- end
207
-
208
- def test_correct_form_field_is_found_using_form_name
209
- assert_equal(browser.form(:name, 'apple_form').text_field(:name, 'name').value, 'apple')
210
- assert_equal(browser.form(:name, 'banana_form').text_field(:name, 'name').value, 'banana')
211
- end
212
-
213
- def test_correct_form_field_is_found_using_form_index
214
- assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'apple')
215
- assert_equal(browser.form(:index, 2).text_field(:name, 'name').value, 'banana')
216
- end
217
-
218
- def test_using_text_on_form
219
- browser.form(:name, 'apple_form').text_field(:name, 'name').set('strudel')
220
- assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'strudel')
221
- end
222
-
223
- def test_submit
224
- browser.form(:name, 'apple_form').submit
225
- assert( browser.text.include?("PASS") )
226
- end
227
- end
228
-
229
- class TC_Hidden_Fields2 < Test::Unit::TestCase
230
-
231
- def setup
232
- goto_page("forms3.html")
233
- end
234
-
235
- def test_hidden
236
-
237
- # test using index
238
- assert( browser.hidden(:index,1).exists? )
239
- assert( browser.hidden(:index,2).exists? )
240
- assert_false( browser.hidden(:index,3).exists? )
241
-
242
- browser.hidden(:index,1).value = 44
243
- browser.hidden(:index,2).value = 55
244
-
245
- browser.button(:value , "Show Hidden").click
246
-
247
- assert_equal("44" , browser.text_field(:name , "vis1").value )
248
- assert_equal("55" , browser.text_field(:name , "vis2").value )
249
-
250
- # test using name and ID
251
- assert( browser.hidden(:name ,"hid1").exists? )
252
- assert( browser.hidden(:id,"hidden_1").exists? )
253
- assert_false( browser.hidden(:name,"hidden_44").exists? )
254
- assert_false( browser.hidden(:id,"hidden_55").exists? )
255
-
256
- browser.hidden(:name ,"hid1").value = 444
257
- browser.hidden(:id,"hidden_1").value = 555
258
-
259
- browser.button(:value , "Show Hidden").click
260
-
261
- assert_equal("444" , browser.text_field(:name , "vis1").value )
262
- assert_equal("555" , browser.text_field(:name ,"vis2").value )
263
-
264
- # test the over-ridden append method
265
- browser.hidden(:name ,"hid1").append("a")
266
- browser.button(:value , "Show Hidden").click
267
- assert_equal("444a" , browser.text_field(:name , "vis1").value )
268
- assert_equal("555" , browser.text_field(:name ,"vis2").value )
269
-
270
- # test the over-ridden clear method
271
- browser.hidden(:name ,"hid1").clear
272
- browser.button(:value , "Show Hidden").click
273
- assert_equal("" , browser.text_field(:name , "vis1").value )
274
- assert_equal("555" , browser.text_field(:name ,"vis2").value )
275
-
276
- # test using a form
277
- assert( browser.form(:name , "has_a_hidden").hidden(:name ,"hid1").exists? )
278
- assert( browser.form(:name , "has_a_hidden").hidden(:id,"hidden_1").exists? )
279
- assert_false( browser.form(:name , "has_a_hidden").hidden(:name,"hidden_44").exists? )
280
- assert_false( browser.form(:name , "has_a_hidden").hidden(:id,"hidden_55").exists? )
281
-
282
- browser.form(:name , "has_a_hidden").hidden(:name ,"hid1").value = 222
283
- browser.form(:name , "has_a_hidden").hidden(:id,"hidden_1").value = 333
284
-
285
- browser.button(:value , "Show Hidden").click
286
-
287
- assert_equal("222" , browser.text_field(:name , "vis1").value )
288
- assert_equal("333" , browser.text_field(:name ,"vis2").value )
289
-
290
- # iterators
291
- ## assert_equal(2, browser.hiddens.length)
292
- ## count =1
293
- ## browser.hiddens.each do |h|
294
- ## case count
295
- ## when 1
296
- ## assert_equal( "", h.id)
297
- ## assert_equal( "hid1", h.name)
298
- ## when 2
299
- ## assert_equal( "", h.name)
300
- ## assert_equal( "hidden_1", h.id)
301
- ## end
302
- ## count+=1
303
- ## end
304
- #
305
- ## assert_equal("hid1" , browser.hiddens[1].name )
306
- ## assert_equal("hidden_1" , browser.hiddens[2].id )
307
- end
308
- end
1
+ # feature tests for Forms
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_Forms2 < Test::Unit::TestCase # Note: there is no TC_Forms
8
+
9
+
10
+ def setup
11
+ goto_page("forms2.html")
12
+ end
13
+
14
+ def test_Form_Exists
15
+ assert(browser.form(:name, "test2").exists?)
16
+ assert_false(browser.form(:name, "missing").exists?)
17
+
18
+ assert(browser.form("test2").exists?)
19
+ assert_false(browser.form( "missing").exists?)
20
+
21
+ assert(browser.form(:index, 1).exists?)
22
+ assert_false(browser.form(:index, 88).exists?)
23
+
24
+ assert(browser.form(:method, "get").exists?)
25
+ assert_false(browser.form(:method, "missing").exists?)
26
+
27
+ assert(browser.form(:id, 'f2').exists?)
28
+ assert_false(browser.form(:id, 'missing').exists?)
29
+
30
+ assert(browser.form(:action, /pass.html/).exists?)
31
+ assert_false(browser.form(:action, "missing").exists?)
32
+ end
33
+
34
+ def test_ButtonInForm
35
+ assert(browser.form(:name, "test2").button(:caption , "Submit").exists?)
36
+ end
37
+
38
+ # The following tests from bug 2261
39
+ tag_method :test_form_html, :fails_on_ie
40
+ def test_form_html
41
+ assert_equal("\n<BR><INPUT value=\"Submit\" type=\"submit\">\n".downcase(),
42
+ browser.form(:name, 'test2').html.downcase())
43
+ end
44
+ def test_form_flash
45
+ assert_nothing_raised{ browser.form(:name, 'test2').flash }
46
+ end
47
+ def test_form_sub_element
48
+ assert_equal('Click Me', browser.form(:index, 1).button(:name, 'b1').value)
49
+ end
50
+ end
51
+
52
+ class TC_Form_Display < Test::Unit::TestCase
53
+
54
+ include CaptureIOHelper
55
+
56
+ def test_showforms
57
+ goto_page("forms2.html")
58
+ actual = capture_stdout { browser.showForms }
59
+ assert_equal(<<END_OF_MESSAGE, actual)
60
+ There are 4 forms
61
+ Form name:
62
+ id:
63
+ method: get
64
+ action: pass.html
65
+ Form name: test2
66
+ id: f2
67
+ method: get
68
+ action: pass2.html
69
+ Form name: test3
70
+ id:
71
+ method: get
72
+ action: pass2.html
73
+ Form name: test2
74
+ id:
75
+ method: get
76
+ action: pass2.html
77
+ END_OF_MESSAGE
78
+ end
79
+ end
80
+
81
+ class TC_Forms3 < Test::Unit::TestCase
82
+
83
+ def setup
84
+ goto_page("forms3.html")
85
+ end
86
+
87
+ # The following tests from bug 2261
88
+ def test_p_in_form
89
+ browser.form(:name, 'buttonsubmit').p(:index, 1).text
90
+ end
91
+
92
+ def test_Form_Exists
93
+ assert(browser.form(:name, "test2").exists?)
94
+ assert_false(browser.form(:name, "missing").exists?)
95
+
96
+ assert(browser.form("test2").exists?)
97
+ assert_false(browser.form( "missing").exists?)
98
+
99
+ assert(browser.form(:index, 1).exists?)
100
+ assert_false(browser.form(:index, 88).exists?)
101
+
102
+ assert(browser.form(:method, "get").exists?)
103
+ assert_false(browser.form(:method, "missing").exists?)
104
+
105
+ assert(browser.form(:action, "pass.html").exists?)
106
+ assert_false(browser.form(:action, "missing").exists?)
107
+ end
108
+
109
+ def test_index_other_element_before_it
110
+ # test for bug reported by Scott Pack, http://rubyforge.org/pipermail/wtr-general/2005-June/002223.html
111
+ assert_equal("check1" , browser.checkbox(:index,1).name )
112
+ end
113
+
114
+ def test_reset
115
+ browser.text_field(:id, "t1").set("Hello, reset test!")
116
+ assert_equal(browser.text_field(:id, 't1').value, 'Hello, reset test!')
117
+
118
+ browser.button(:id, "reset_button").click
119
+ assert_equal("" , browser.text_field(:id, 't1').value )
120
+
121
+ # also verify it works under a form
122
+ browser.text_field(:id, "t1").set("reset test - using a form")
123
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
124
+
125
+ browser.form(:index,2).button(:index,2).click
126
+ assert_equal("" , browser.text_field(:id, 't1').value )
127
+
128
+ # also verify it works under a form, this time using the :id attribute
129
+ browser.text_field(:id, "t1").set("reset test - using a form")
130
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
131
+
132
+ browser.form(:index,2).button(:id,'reset_button').click
133
+ assert_equal("" , browser.text_field(:id, 't1').value )
134
+ end
135
+
136
+ ## def test_flash1
137
+ ## browser.form(:name ,"test2").button(:caption , "Submit").flash
138
+ ## end
139
+ #
140
+ def test_objects_with_same_name
141
+ assert_equal('textfield' ,browser.text_field( :name , 'g1').value )
142
+ assert_equal('button' ,browser.button( :name , 'g1').value )
143
+ assert_equal('1' ,browser.checkbox( :name , 'g1').value )
144
+ assert_equal('2' ,browser.radio( :name , 'g1').value )
145
+
146
+ assert_equal('textfield' ,browser.text_field( :name , /g1/).value )
147
+ assert_equal('button' ,browser.button( :name , /g1/).value )
148
+ assert_equal('1' ,browser.checkbox( :name , /g1/).value )
149
+ assert_equal('2' ,browser.radio( :name , /g1/).value )
150
+
151
+ assert_equal('textfield_id' ,browser.text_field( :id , 'g1').value )
152
+ assert_equal('button_id' ,browser.button( :id , 'g1').value )
153
+ assert_equal('1_id' ,browser.checkbox( :id , 'g1').value )
154
+ assert_equal('2_id' ,browser.radio( :id , 'g1').value )
155
+
156
+ assert_equal('textfield_id' ,browser.text_field( :id , /g1/).value )
157
+ assert_equal('button_id' ,browser.button( :id , /g1/).value )
158
+ assert_equal('1_id' ,browser.checkbox( :id , /g1/).value )
159
+ assert_equal('2_id' ,browser.radio( :id , /g1/).value )
160
+ end
161
+
162
+ # def test_flash2
163
+ # browser.button(:value, 'Click Me').flash
164
+ # assert_raises( Watir::UnknownObjectException ) { browser.text_field( :name , 'g177').flash }
165
+ # end
166
+
167
+ def test_submitWithImage
168
+ assert( browser.button(:alt , "submit").exists? )
169
+ assert( browser.button(:alt , /sub/).exists? )
170
+
171
+ assert_false( browser.button(:alt , "missing").exists? )
172
+ assert_false( browser.button(:alt , /missing/).exists? )
173
+
174
+ #assert( browser.button(:src , "file:///#{$myDir}/html/images/button.jpg").exists? ) # this doesnt work for everybody
175
+ assert( browser.button(:src , /button/).exists? )
176
+
177
+ assert_false( browser.button(:src , "missing").exists? )
178
+ assert_false( browser.button(:src , /missing/).exists? )
179
+ assert_nothing_raised("raised an exception when it shouldnt have") { browser.button(:src , /button/).click }
180
+
181
+ assert( browser.text.include?("PASS") )
182
+ end
183
+ end
184
+
185
+
186
+ class TC_Forms4 < Test::Unit::TestCase
187
+
188
+ def setup
189
+ goto_page("forms4.html")
190
+ end
191
+
192
+ def test_find_text_field_ignoring_form
193
+ assert_equal(browser.text_field(:name, 'name').value, 'apple') # should it raise a not-unique error instead?
194
+ end
195
+
196
+ def test_correct_form_field_is_found_using_form_name
197
+ assert_equal(browser.form(:name, 'apple_form').text_field(:name, 'name').value, 'apple')
198
+ assert_equal(browser.form(:name, 'banana_form').text_field(:name, 'name').value, 'banana')
199
+ end
200
+
201
+ def test_correct_form_field_is_found_using_form_index
202
+ assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'apple')
203
+ assert_equal(browser.form(:index, 2).text_field(:name, 'name').value, 'banana')
204
+ end
205
+
206
+ def test_using_text_on_form
207
+ browser.form(:name, 'apple_form').text_field(:name, 'name').set('strudel')
208
+ assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'strudel')
209
+ end
210
+
211
+ def test_submit
212
+ browser.form(:name, 'apple_form').submit
213
+ assert( browser.text.include?("PASS") )
214
+ end
215
+ end
216
+
217
+ class TC_Hidden_Fields2 < Test::Unit::TestCase
218
+
219
+ def setup
220
+ goto_page("forms3.html")
221
+ end
222
+
223
+ def test_hidden
224
+
225
+ # test using index
226
+ assert( browser.hidden(:index,1).exists? )
227
+ assert( browser.hidden(:index,2).exists? )
228
+ assert_false( browser.hidden(:index,3).exists? )
229
+
230
+ browser.hidden(:index,1).value = 44
231
+ browser.hidden(:index,2).value = 55
232
+
233
+ browser.button(:value , "Show Hidden").click
234
+
235
+ assert_equal("44" , browser.text_field(:name , "vis1").value )
236
+ assert_equal("55" , browser.text_field(:name , "vis2").value )
237
+
238
+ # test using name and ID
239
+ assert( browser.hidden(:name ,"hid1").exists? )
240
+ assert( browser.hidden(:id,"hidden_1").exists? )
241
+ assert_false( browser.hidden(:name,"hidden_44").exists? )
242
+ assert_false( browser.hidden(:id,"hidden_55").exists? )
243
+
244
+ browser.hidden(:name ,"hid1").value = 444
245
+ browser.hidden(:id,"hidden_1").value = 555
246
+
247
+ browser.button(:value , "Show Hidden").click
248
+
249
+ assert_equal("444" , browser.text_field(:name , "vis1").value )
250
+ assert_equal("555" , browser.text_field(:name ,"vis2").value )
251
+
252
+ # test the over-ridden append method
253
+ browser.hidden(:name ,"hid1").append("a")
254
+ browser.button(:value , "Show Hidden").click
255
+ assert_equal("444a" , browser.text_field(:name , "vis1").value )
256
+ assert_equal("555" , browser.text_field(:name ,"vis2").value )
257
+
258
+ # test the over-ridden clear method
259
+ browser.hidden(:name ,"hid1").clear
260
+ browser.button(:value , "Show Hidden").click
261
+ assert_equal("" , browser.text_field(:name , "vis1").value )
262
+ assert_equal("555" , browser.text_field(:name ,"vis2").value )
263
+
264
+ # test using a form
265
+ assert( browser.form(:name , "has_a_hidden").hidden(:name ,"hid1").exists? )
266
+ assert( browser.form(:name , "has_a_hidden").hidden(:id,"hidden_1").exists? )
267
+ assert_false( browser.form(:name , "has_a_hidden").hidden(:name,"hidden_44").exists? )
268
+ assert_false( browser.form(:name , "has_a_hidden").hidden(:id,"hidden_55").exists? )
269
+
270
+ browser.form(:name , "has_a_hidden").hidden(:name ,"hid1").value = 222
271
+ browser.form(:name , "has_a_hidden").hidden(:id,"hidden_1").value = 333
272
+
273
+ browser.button(:value , "Show Hidden").click
274
+
275
+ assert_equal("222" , browser.text_field(:name , "vis1").value )
276
+ assert_equal("333" , browser.text_field(:name ,"vis2").value )
277
+
278
+ # iterators
279
+ ## assert_equal(2, browser.hiddens.length)
280
+ ## count =1
281
+ ## browser.hiddens.each do |h|
282
+ ## case count
283
+ ## when 1
284
+ ## assert_equal( "", h.id)
285
+ ## assert_equal( "hid1", h.name)
286
+ ## when 2
287
+ ## assert_equal( "", h.name)
288
+ ## assert_equal( "hidden_1", h.id)
289
+ ## end
290
+ ## count+=1
291
+ ## end
292
+ #
293
+ ## assert_equal("hid1" , browser.hiddens[1].name )
294
+ ## assert_equal("hidden_1" , browser.hiddens[2].id )
295
+ end
296
+ end