watir-classic 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/CHANGES +721 -0
  2. data/LICENSE +34 -0
  3. data/README.rdoc +78 -0
  4. data/VERSION +1 -0
  5. data/bin/watir-console +5 -0
  6. data/lib/watir-classic.rb +14 -0
  7. data/lib/watir-classic/IEDialog/Release/IEDialog.dll +0 -0
  8. data/lib/watir-classic/assertions.rb +44 -0
  9. data/lib/watir-classic/browser.rb +149 -0
  10. data/lib/watir-classic/browsers.rb +7 -0
  11. data/lib/watir-classic/close_all.rb +31 -0
  12. data/lib/watir-classic/container.rb +110 -0
  13. data/lib/watir-classic/contrib/enabled_popup.rb +21 -0
  14. data/lib/watir-classic/contrib/ie-new-process.rb +27 -0
  15. data/lib/watir-classic/contrib/page_checker.rb +29 -0
  16. data/lib/watir-classic/cookies.rb +80 -0
  17. data/lib/watir-classic/core.rb +43 -0
  18. data/lib/watir-classic/dialogs/file_field.rb +34 -0
  19. data/lib/watir-classic/dialogs/javascript.rb +43 -0
  20. data/lib/watir-classic/drag_and_drop_helper.rb +68 -0
  21. data/lib/watir-classic/element.rb +438 -0
  22. data/lib/watir-classic/element_collection.rb +109 -0
  23. data/lib/watir-classic/element_extensions.rb +69 -0
  24. data/lib/watir-classic/exceptions.rb +50 -0
  25. data/lib/watir-classic/form.rb +96 -0
  26. data/lib/watir-classic/frame.rb +47 -0
  27. data/lib/watir-classic/ie-class.rb +767 -0
  28. data/lib/watir-classic/ie-process.rb +47 -0
  29. data/lib/watir-classic/ie.rb +20 -0
  30. data/lib/watir-classic/image.rb +111 -0
  31. data/lib/watir-classic/input_elements.rb +480 -0
  32. data/lib/watir-classic/irb-history.rb +31 -0
  33. data/lib/watir-classic/link.rb +46 -0
  34. data/lib/watir-classic/locator.rb +243 -0
  35. data/lib/watir-classic/logger.rb +19 -0
  36. data/lib/watir-classic/matches.rb +23 -0
  37. data/lib/watir-classic/modal_dialog.rb +72 -0
  38. data/lib/watir-classic/module.rb +12 -0
  39. data/lib/watir-classic/non_control_elements.rb +114 -0
  40. data/lib/watir-classic/options.rb +56 -0
  41. data/lib/watir-classic/page-container.rb +114 -0
  42. data/lib/watir-classic/process.rb +20 -0
  43. data/lib/watir-classic/screen_capture.rb +115 -0
  44. data/lib/watir-classic/supported_elements.rb +172 -0
  45. data/lib/watir-classic/table.rb +224 -0
  46. data/lib/watir-classic/testcase.rb +97 -0
  47. data/lib/watir-classic/util.rb +35 -0
  48. data/lib/watir-classic/version.rb +4 -0
  49. data/lib/watir-classic/wait.rb +41 -0
  50. data/lib/watir-classic/wait_helper.rb +12 -0
  51. data/lib/watir-classic/waiter.rb +98 -0
  52. data/lib/watir-classic/win32.rb +40 -0
  53. data/lib/watir-classic/win32ole.rb +16 -0
  54. data/lib/watir-classic/win32ole/1.8.7/win32ole.so +0 -0
  55. data/lib/watir-classic/win32ole/1.9.3/win32ole.so +0 -0
  56. data/lib/watir-classic/window.rb +68 -0
  57. data/lib/watir-classic/xpath_locator.rb +52 -0
  58. data/rakefile.rb +54 -0
  59. data/unittests/all_tests.rb +10 -0
  60. data/unittests/buttons_xpath_test.rb +68 -0
  61. data/unittests/checkbox_test.rb +163 -0
  62. data/unittests/checkbox_xpath_test.rb +106 -0
  63. data/unittests/click_no_wait_test.rb +23 -0
  64. data/unittests/close_all_test.rb +17 -0
  65. data/unittests/core_tests.rb +17 -0
  66. data/unittests/css_selector_test.rb +44 -0
  67. data/unittests/css_test.rb +38 -0
  68. data/unittests/dialog_test.rb +64 -0
  69. data/unittests/div2_xpath_test.rb +21 -0
  70. data/unittests/div_test.rb +170 -0
  71. data/unittests/div_xpath_test.rb +95 -0
  72. data/unittests/document_standards.rb +63 -0
  73. data/unittests/element_collection_indexes_test.rb +57 -0
  74. data/unittests/element_collections_test.rb +100 -0
  75. data/unittests/element_test.rb +47 -0
  76. data/unittests/errorchecker_test.rb +31 -0
  77. data/unittests/filefield_test.rb +43 -0
  78. data/unittests/filefield_xpath_test.rb +35 -0
  79. data/unittests/form_test.rb +282 -0
  80. data/unittests/form_xpath_test.rb +254 -0
  81. data/unittests/frame_test.rb +165 -0
  82. data/unittests/google_form_test.rb +15 -0
  83. data/unittests/html/JavascriptClick.html +39 -0
  84. data/unittests/html/blankpage.html +11 -0
  85. data/unittests/html/buttons1.html +40 -0
  86. data/unittests/html/checkboxes1.html +89 -0
  87. data/unittests/html/click_no_wait.html +14 -0
  88. data/unittests/html/complex_table.html +35 -0
  89. data/unittests/html/cssTest.html +42 -0
  90. data/unittests/html/depot_store.html +59 -0
  91. data/unittests/html/div.html +92 -0
  92. data/unittests/html/div_xml.html +21 -0
  93. data/unittests/html/fileupload.html +44 -0
  94. data/unittests/html/formTest1.html +38 -0
  95. data/unittests/html/forms2.html +44 -0
  96. data/unittests/html/forms3.html +131 -0
  97. data/unittests/html/forms4.html +26 -0
  98. data/unittests/html/frame_buttons.html +4 -0
  99. data/unittests/html/frame_links.html +4 -0
  100. data/unittests/html/frame_multi.html +5 -0
  101. data/unittests/html/google_india.html +119 -0
  102. data/unittests/html/ie7_document_standards.html +9 -0
  103. data/unittests/html/ie8_document_standards.html +9 -0
  104. data/unittests/html/ie9_document_standards.html +9 -0
  105. data/unittests/html/iframe.html +3 -0
  106. data/unittests/html/iframeTest.html +17 -0
  107. data/unittests/html/iframeTest1.html +7 -0
  108. data/unittests/html/iframeTest2.html +5 -0
  109. data/unittests/html/images/1.gif +0 -0
  110. data/unittests/html/images/2.GIF +0 -0
  111. data/unittests/html/images/3.GIF +0 -0
  112. data/unittests/html/images/button.jpg +0 -0
  113. data/unittests/html/images/circle.jpg +0 -0
  114. data/unittests/html/images/map.GIF +0 -0
  115. data/unittests/html/images/map2.gif +0 -0
  116. data/unittests/html/images/minus.GIF +0 -0
  117. data/unittests/html/images/originaltriangle.jpg +0 -0
  118. data/unittests/html/images/plus.gif +0 -0
  119. data/unittests/html/images/square.jpg +0 -0
  120. data/unittests/html/images/triangle.jpg +0 -0
  121. data/unittests/html/images1.html +65 -0
  122. data/unittests/html/javascriptevents.html +33 -0
  123. data/unittests/html/link_pass.html +11 -0
  124. data/unittests/html/links1.html +37 -0
  125. data/unittests/html/links2.html +11 -0
  126. data/unittests/html/links_multi.html +12 -0
  127. data/unittests/html/list_matters.html +720 -0
  128. data/unittests/html/lists.html +18 -0
  129. data/unittests/html/map_test.html +30 -0
  130. data/unittests/html/modal_dialog.html +10 -0
  131. data/unittests/html/modal_dialog_launcher.html +12 -0
  132. data/unittests/html/multiple_specifiers.html +64 -0
  133. data/unittests/html/nestedFrames.html +6 -0
  134. data/unittests/html/new_browser.html +17 -0
  135. data/unittests/html/pass.html +13 -0
  136. data/unittests/html/popups1.html +59 -0
  137. data/unittests/html/pre.html +29 -0
  138. data/unittests/html/quirks_document_standards.html +8 -0
  139. data/unittests/html/radioButtons1.html +71 -0
  140. data/unittests/html/select_tealeaf.html +54 -0
  141. data/unittests/html/selectboxes1.html +52 -0
  142. data/unittests/html/simple_table.html +25 -0
  143. data/unittests/html/simple_table_buttons.html +104 -0
  144. data/unittests/html/simple_table_columns.html +75 -0
  145. data/unittests/html/table1.html +179 -0
  146. data/unittests/html/tableCell_using_xpath.html +19 -0
  147. data/unittests/html/table_and_tablerow_to_a.html +174 -0
  148. data/unittests/html/textarea.html +30 -0
  149. data/unittests/html/textfields1.html +100 -0
  150. data/unittests/html/textsearch.html +44 -0
  151. data/unittests/html/wallofcheckboxes.html +1003 -0
  152. data/unittests/html/xpath_nbsp.html +11 -0
  153. data/unittests/html/zeroindex.html +11 -0
  154. data/unittests/ie_exists_test.rb +16 -0
  155. data/unittests/ie_mock.rb +94 -0
  156. data/unittests/ie_test.rb +54 -0
  157. data/unittests/images_test.rb +156 -0
  158. data/unittests/images_xpath_test.rb +90 -0
  159. data/unittests/index_specifier_test.rb +31 -0
  160. data/unittests/js_events_test.rb +31 -0
  161. data/unittests/links_multi_test.rb +34 -0
  162. data/unittests/links_test.rb +131 -0
  163. data/unittests/links_xpath_test.rb +38 -0
  164. data/unittests/lists_test.rb +23 -0
  165. data/unittests/map_test.rb +98 -0
  166. data/unittests/minmax_test.rb +37 -0
  167. data/unittests/navigate_test.rb +38 -0
  168. data/unittests/nbsp_xpath_test.rb +16 -0
  169. data/unittests/no_wait_test.rb +28 -0
  170. data/unittests/non_core_tests.rb +12 -0
  171. data/unittests/other/all_tests_concurrent.rb +57 -0
  172. data/unittests/other/navigate_exception_test.rb +24 -0
  173. data/unittests/other/rexml_unit_test.rb +27 -0
  174. data/unittests/other/screen_capture_test.rb +53 -0
  175. data/unittests/other/testcase_method_order_test.rb +36 -0
  176. data/unittests/other/testcase_verify_test.rb +25 -0
  177. data/unittests/other/wait_until_test.rb +102 -0
  178. data/unittests/pagecontainstext_test.rb +69 -0
  179. data/unittests/parent_child_test.rb +27 -0
  180. data/unittests/perf_test.rb +20 -0
  181. data/unittests/pre_test.rb +49 -0
  182. data/unittests/radios_test.rb +181 -0
  183. data/unittests/radios_xpath_test.rb +100 -0
  184. data/unittests/security_setting_test.rb +24 -0
  185. data/unittests/selectbox_test.rb +144 -0
  186. data/unittests/selectbox_xpath_test.rb +102 -0
  187. data/unittests/setup.rb +69 -0
  188. data/unittests/speed_settings_test.rb +67 -0
  189. data/unittests/table_cell_using_xpath_test.rb +34 -0
  190. data/unittests/table_test.rb +296 -0
  191. data/unittests/table_xpath_test.rb +109 -0
  192. data/unittests/test_tests.rb +9 -0
  193. data/unittests/textarea_test.rb +92 -0
  194. data/unittests/textarea_xpath_test.rb +77 -0
  195. data/unittests/textfield_for_ch_char_test.rb +32 -0
  196. data/unittests/textfields_test.rb +184 -0
  197. data/unittests/textfields_xpath_test.rb +110 -0
  198. data/unittests/version_test.rb +15 -0
  199. data/unittests/win32ole_so_test.rb +35 -0
  200. data/unittests/window_tests.rb +10 -0
  201. data/unittests/windows/attach_to_existing_window_test.rb +52 -0
  202. data/unittests/windows/attach_to_new_window_test.rb +74 -0
  203. data/unittests/windows/close_window_test.rb +20 -0
  204. data/unittests/windows/frame_links_test.rb +23 -0
  205. data/unittests/windows/ie-each_test.rb +46 -0
  206. data/unittests/windows/modal_dialog_test.rb +95 -0
  207. data/unittests/windows/new_process_test.rb +24 -0
  208. data/unittests/windows/new_test.rb +58 -0
  209. data/unittests/windows/open_close_test.rb +19 -0
  210. data/unittests/windows/send_keys_test.rb +26 -0
  211. data/unittests/xpath_tests.rb +11 -0
  212. data/watir-rdoc.rb +7 -0
  213. metadata +370 -0
@@ -0,0 +1,282 @@
1
+ # feature tests for Forms
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_Forms2 < Test::Unit::TestCase # Note: there is no TC_Forms1
7
+ def setup
8
+ uses_page "forms2.html"
9
+ end
10
+
11
+ def test_form_exists
12
+ assert(browser.form(:name, "test2").exists?)
13
+ assert_false(browser.form(:name, "missing").exists?)
14
+
15
+ assert(browser.form(:index, 0).exists?)
16
+ assert_false(browser.form(:index, 87).exists?)
17
+
18
+ assert(browser.form(:method, "get").exists?)
19
+ assert_false(browser.form(:method, "missing").exists?)
20
+
21
+ assert(browser.form(:id, 'f2').exists?)
22
+ assert_false(browser.form(:id, 'missing').exists?)
23
+
24
+ assert(browser.form(:action, /pass.html/).exists?)
25
+ assert_false(browser.form(:action, "missing").exists?)
26
+ end
27
+
28
+ def test_multiple_attribute
29
+ assert_true(browser.form(:name => 'test2', :id => 'f2').exists?)
30
+ assert_true(browser.form(:name => 'test2', :method => 'get', :action => 'pass2.html'))
31
+ end
32
+
33
+ def test_button_in_form
34
+ assert(browser.form(:name, "test2").button(:caption, "Submit").exists?)
35
+ end
36
+ def test_form_sub_element
37
+ assert_equal('Click Me', browser.form(:index, 0).button(:name, 'b1').value)
38
+ end
39
+
40
+ # The following tests form bug 2261
41
+ tag_method :test_form_outer_html, :fails_on_firefox
42
+
43
+ def test_form_outer_html
44
+ expected = "\r\n<FORM id=f2 name=test2 action=pass2.html method=get><BR><INPUT type=submit value=Submit> </FORM>"
45
+ actual = browser.form(:name, 'test2').html
46
+ actual.sub!('style=""','') # ie9 adds in a style tag so just strip it out
47
+ #ie9 also has som additional formatting so remove that too
48
+ actual.gsub!('"','')
49
+ actual.gsub!(/\n/,'')
50
+ # ignore attributes order by sorting them
51
+ sorted_expected, sorted_actual = [expected, actual].map! do |html|
52
+ html.strip.downcase.scan(%r{<form (.*)><br><(.*)>\s*</form>}).flatten.
53
+ map {|part| part.split(" ").sort.join(" ")}.join("><br><")
54
+ end
55
+ assert_not_equal("", sorted_expected)
56
+ assert_not_equal("", sorted_actual)
57
+ assert_equal(sorted_expected, sorted_actual)
58
+ end
59
+
60
+ tag_method :test_form_inner_html, :fails_on_ie
61
+ def test_form_inner_html
62
+ expected = "\n<br><input value=\"Submit\" type=\"submit\">\n"
63
+ assert_equal(expected, browser.form(:name, 'test2').html)
64
+ end
65
+ def test_form_flash
66
+ assert_nothing_raised{ browser.form(:name, 'test2').flash }
67
+ end
68
+ end
69
+
70
+ class TC_Forms_Collection < Test::Unit::TestCase
71
+ def setup
72
+ goto_page "forms2.html"
73
+ end
74
+
75
+ def test_forms_collection
76
+ forms = browser.forms
77
+ assert_equal(4, forms.length)
78
+ assert(forms.first.action =~ /pass.html$/)
79
+ assert_equal('test2', forms.last.name)
80
+ end
81
+ end
82
+
83
+ class TC_Forms3 < Test::Unit::TestCase
84
+ def setup
85
+ goto_page "forms3.html"
86
+ end
87
+
88
+ # The following tests form bug 2261
89
+ def test_p_in_form
90
+ assert_equal "This form has a submit button that is an image",
91
+ browser.form(:name, 'buttonsubmit').p(:index, 0).text
92
+ end
93
+
94
+ # test for bug reported by Scott Pack, http://rubyforge.org/pipermail/wtr-general/2005-June/002223.html
95
+ def test_index_other_element_before_it
96
+ assert_equal("check1" , browser.checkbox(:index,0).name)
97
+ end
98
+
99
+ tag_method :test_reset, :fails_on_firefox
100
+ def test_reset
101
+ browser.text_field(:id, "t1").set("Hello, reset test!")
102
+ assert_equal(browser.text_field(:id, 't1').value, 'Hello, reset test!')
103
+
104
+ browser.button(:id, "reset_button").click
105
+ assert_equal("" , browser.text_field(:id, 't1').value)
106
+
107
+ # also verify it works under a form
108
+ browser.text_field(:id, "t1").set("reset test - using a form")
109
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
110
+
111
+ browser.form(:index,1).button(:index,1).click
112
+ assert_equal("" , browser.text_field(:id, 't1').value)
113
+
114
+ # also verify it works under a form, this time using the :id attribute
115
+ browser.text_field(:id, "t1").set("reset test - using a form")
116
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
117
+
118
+ browser.form(:index,1).button(:id,'reset_button').click
119
+ assert_equal("" , browser.text_field(:id, 't1').value)
120
+ end
121
+
122
+ def test_flash1
123
+ assert_nothing_raised do
124
+ browser.form(:name, "test2").button(:caption , "Submit").flash
125
+ end
126
+ end
127
+
128
+ def test_objects_with_same_name
129
+ assert_equal('textfield' ,browser.text_field( :name, 'g1').value )
130
+ assert_equal('button' ,browser.button( :name, 'g1').value )
131
+ assert_equal('1' ,browser.checkbox( :name, 'g1').value )
132
+ assert_equal('2' ,browser.radio( :name, 'g1').value )
133
+
134
+ assert_equal('textfield' ,browser.text_field( :name, /g1/).value )
135
+ assert_equal('button' ,browser.button( :name, /g1/).value )
136
+ assert_equal('1' ,browser.checkbox( :name, /g1/).value )
137
+ assert_equal('2' ,browser.radio( :name, /g1/).value )
138
+
139
+ assert_equal('textfield_id' ,browser.text_field( :id, 'g1').value )
140
+ assert_equal('button_id' ,browser.button( :id, 'g1').value )
141
+ assert_equal('1_id' ,browser.checkbox( :id, 'g1').value )
142
+ assert_equal('2_id' ,browser.radio( :id, 'g1').value )
143
+
144
+ assert_equal('textfield_id' ,browser.text_field( :id, /g1/).value )
145
+ assert_equal('button_id' ,browser.button( :id, /g1/).value )
146
+ assert_equal('1_id' ,browser.checkbox( :id, /g1/).value )
147
+ assert_equal('2_id' ,browser.radio( :id, /g1/).value )
148
+ end
149
+
150
+ def test_flash2
151
+ browser.button(:value, 'Click Me').flash
152
+ assert_raises(UnknownObjectException) { browser.text_field( :name , 'g177').flash }
153
+ end
154
+
155
+ def test_submitWithImage
156
+ assert( browser.button(:alt, "submit").exists? )
157
+ assert( browser.button(:alt, /sub/).exists? )
158
+
159
+ assert_false( browser.button(:alt, "missing").exists? )
160
+ assert_false( browser.button(:alt, /missing/).exists? )
161
+
162
+ #assert( browser.button(:src , "file:///#{$myDir}/html/images/button.jpg").exists? ) # this doesnt work for everybody
163
+ assert( browser.button(:src, /button/).exists? )
164
+
165
+ assert_false( browser.button(:src, "missing").exists? )
166
+ assert_false( browser.button(:src, /missing/).exists? )
167
+ assert_nothing_raised("raised an exception when it shouldnt have") { browser.button(:src , /button/).click }
168
+
169
+ assert( browser.text.include?("PASS") )
170
+ end
171
+ end
172
+
173
+ class TC_Forms4 < Test::Unit::TestCase
174
+ def setup
175
+ uses_page "forms4.html"
176
+ end
177
+
178
+ def test_find_text_field_ignoring_form
179
+ assert_equal(browser.text_field(:name, 'name').value, 'apple')
180
+ end
181
+
182
+ def test_correct_form_field_is_found_using_form_name
183
+ assert_equal(browser.form(:name, 'apple_form').text_field(:name, 'name').value, 'apple')
184
+ assert_equal(browser.form(:name, 'banana_form').text_field(:name, 'name').value, 'banana')
185
+ end
186
+
187
+ def test_correct_form_field_is_found_using_form_index
188
+ assert_equal(browser.form(:index, 0).text_field(:name, 'name').value, 'apple')
189
+ assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'banana')
190
+ end
191
+
192
+ def test_using_text_on_form
193
+ browser.form(:name, 'apple_form').text_field(:name, 'name').set('strudel')
194
+ assert_equal(browser.form(:index, 0).text_field(:name, 'name').value, 'strudel')
195
+ end
196
+
197
+ def test_submit
198
+ browser.form(:name, 'apple_form').submit
199
+ assert(browser.text.include?("PASS"))
200
+ end
201
+ end
202
+
203
+ class TC_Hidden_Fields < Test::Unit::TestCase
204
+ def setup
205
+ goto_page "forms3.html"
206
+ end
207
+
208
+ def test_hidden
209
+
210
+ # test using index
211
+ assert( browser.hidden(:index, 0).exists? )
212
+ assert( browser.hidden(:index, 1).exists? )
213
+ assert_false( browser.hidden(:index, 2).exists? )
214
+
215
+ browser.hidden(:index, 0).value = 44
216
+ browser.hidden(:index, 1).value = 55
217
+
218
+ browser.button(:value, "Show Hidden").click
219
+
220
+ assert_equal("44", browser.text_field(:name, "vis1").value )
221
+ assert_equal("55", browser.text_field(:name, "vis2").value )
222
+
223
+ # test using name and ID
224
+ assert( browser.hidden(:name, "hid1").exists? )
225
+ assert( browser.hidden(:id, "hidden_1").exists? )
226
+ assert_false( browser.hidden(:name, "hidden_44").exists? )
227
+ assert_false( browser.hidden(:id, "hidden_55").exists? )
228
+
229
+ browser.hidden(:name, "hid1").value = 444
230
+ browser.hidden(:id, "hidden_1").value = 555
231
+
232
+ browser.button(:value, "Show Hidden").click
233
+
234
+ assert_equal("444", browser.text_field(:name, "vis1").value)
235
+ assert_equal("555", browser.text_field(:name, "vis2").value)
236
+
237
+ # test the over-ridden append method
238
+ browser.hidden(:name, "hid1").append("a")
239
+ browser.button(:value, "Show Hidden").click
240
+ assert_equal("444a", browser.text_field(:name, "vis1").value )
241
+ assert_equal("555", browser.text_field(:name, "vis2").value )
242
+
243
+ # test the over-ridden clear method
244
+ browser.hidden(:name, "hid1").clear
245
+ browser.button(:value, "Show Hidden").click
246
+ assert_equal("", browser.text_field(:name, "vis1").value)
247
+ assert_equal("555", browser.text_field(:name, "vis2").value)
248
+
249
+ # test using a form
250
+ assert( browser.form(:name, "has_a_hidden").hidden(:name, "hid1").exists? )
251
+ assert( browser.form(:name, "has_a_hidden").hidden(:id, "hidden_1").exists? )
252
+ assert_false( browser.form(:name, "has_a_hidden").hidden(:name, "hidden_44").exists? )
253
+ assert_false( browser.form(:name, "has_a_hidden").hidden(:id, "hidden_55").exists? )
254
+
255
+ browser.form(:name, "has_a_hidden").hidden(:name, "hid1").value = 222
256
+ browser.form(:name, "has_a_hidden").hidden(:id, "hidden_1").value = 333
257
+
258
+ browser.button(:value, "Show Hidden").click
259
+
260
+ assert_equal("222", browser.text_field(:name, "vis1").value)
261
+ assert_equal("333", browser.text_field(:name, "vis2").value)
262
+
263
+ # iterators
264
+ assert_equal(2, browser.hiddens.length)
265
+ count = 1
266
+ browser.hiddens.each do |h|
267
+ case count
268
+ when 1
269
+ assert_equal("", h.id)
270
+ assert_equal("hid1", h.name)
271
+ when 2
272
+ assert_equal("", h.name)
273
+ assert_equal("hidden_1", h.id)
274
+ end
275
+ count += 1
276
+ end
277
+
278
+ assert_equal("hid1", browser.hiddens[0].name)
279
+ assert_equal("hidden_1", browser.hiddens[1].id)
280
+ end
281
+ end
282
+
@@ -0,0 +1,254 @@
1
+ # feature tests for Forms
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_Forms2_XPath < Test::Unit::TestCase
7
+ def setup
8
+ goto_page "forms2.html"
9
+ end
10
+
11
+ def test_Form_Exists
12
+ assert(browser.form(:xpath , "//form[@name='test2']/").exists?)
13
+ assert_false(browser.form(:xpath , "//form[@name='missing']/").exists?)
14
+
15
+ assert(browser.form(:xpath , "//form[@method='get']/").exists?)
16
+ assert_false(browser.form(:xpath , "//form[@method='missing']/").exists?)
17
+
18
+ assert(browser.form(:xpath , "//form[@action='pass.html']/").exists?)
19
+ assert_false(browser.form(:xpath , "//form[@action='missing']/").exists?)
20
+ end
21
+
22
+ def test_ButtonInForm
23
+ assert(browser.form(:xpath , "//form[@name='test2']/").button(:caption , "Submit").exists?)
24
+ end
25
+ end
26
+
27
+ class TC_Form_Display_XPath < Test::Unit::TestCase
28
+ include CaptureIOHelper
29
+ def test_showforms
30
+ goto_page "forms2.html"
31
+
32
+ actual = capture_stdout { browser.show_forms }
33
+ expected = <<END_OF_MESSAGE
34
+ There are 4 forms
35
+ Form name:
36
+ id:
37
+ method: get
38
+ action: pass.html
39
+ Form name: test2
40
+ id: f2
41
+ method: get
42
+ action: pass2.html
43
+ Form name: test3
44
+ id:
45
+ method: get
46
+ action: pass2.html
47
+ Form name: test2
48
+ id:
49
+ method: get
50
+ action: pass2.html
51
+ END_OF_MESSAGE
52
+ actual.gsub!(/(action: )file:.*\/(.*)$/,'\\1\\2') if actual =~ /file:/
53
+ actual.gsub!(/\s+\n/,"\n")
54
+ assert_equal(expected, actual)
55
+ end
56
+ end
57
+
58
+ class TC_Forms3_XPath < Test::Unit::TestCase
59
+ def setup
60
+ goto_page "forms3.html"
61
+ end
62
+
63
+ def test_Form_Exists
64
+ assert(browser.form(:xpath , "//form[@name='test2']/").exists?)
65
+ assert_false(browser.form(:xpath , "//form[@name='missing']/").exists?)
66
+
67
+ assert(browser.form(:xpath , "//form[@method='get']/").exists?)
68
+ assert_false(browser.form(:xpath , "//form[@method='missing']/").exists?)
69
+
70
+ assert(browser.form(:xpath , "//form[@action='pass.html']/").exists?)
71
+ assert_false(browser.form(:xpath , "//form[@action='missing']/").exists?)
72
+ end
73
+
74
+ def test_getObject_when_non_watir_object_before_it
75
+ # test for bug reported by Scott Pack, http://rubyforge.org/pipermail/wtr-general/2005-June/002223.html
76
+ assert_equal("check1" , browser.checkbox(:index,0).name )
77
+ end
78
+
79
+ def test_showforms # add verification of output!
80
+ browser.show_forms
81
+ end
82
+
83
+ def test_reset
84
+
85
+ browser.text_field(:id, "t1").set("Hello, reset test!")
86
+ assert_equal(browser.text_field(:id, 't1').value, 'Hello, reset test!')
87
+
88
+ browser.button(:caption, "Reset").click
89
+ assert_equal("" , browser.text_field(:id, 't1').value )
90
+
91
+ # also verify it works under a form
92
+ browser.text_field(:id, "t1").set("reset test - using a form")
93
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
94
+
95
+ # also verify it works under a form, this time using the :id attribute
96
+ browser.text_field(:id, "t1").set("reset test - using a form")
97
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
98
+ end
99
+
100
+ def test_flash1
101
+ browser.form(:xpath , "//form[@name='test2']/").button(:caption , "Submit").flash
102
+ end
103
+
104
+ def test_objects_with_same_name
105
+ assert_equal('textfield' ,browser.text_field( :name , 'g1').value )
106
+ assert_equal('button' ,browser.button( :name , 'g1').value )
107
+ assert_equal('1' ,browser.checkbox( :name , 'g1').value )
108
+ assert_equal('2' ,browser.radio( :name , 'g1').value )
109
+
110
+ assert_equal('textfield_id' ,browser.text_field( :id , 'g1').value )
111
+ assert_equal('button_id' ,browser.button( :id , 'g1').value )
112
+ assert_equal('1_id' ,browser.checkbox( :id , 'g1').value )
113
+ assert_equal('2_id' ,browser.radio( :id , 'g1').value )
114
+ end
115
+
116
+ def test_flash2
117
+ browser.button(:value, 'Click Me').flash
118
+ assert_raises( Watir::UnknownObjectException ) { browser.text_field( :name , 'g177').flash }
119
+ end
120
+
121
+ def test_showElements # add verification!
122
+ browser.show_all_objects
123
+ end
124
+
125
+ def test_showText
126
+ puts browser.text
127
+ end
128
+
129
+ def test_showHTML
130
+ puts browser.html
131
+ end
132
+
133
+ def test_submitWithImage
134
+ assert( browser.button(:alt , "submit").exists? )
135
+ assert( browser.button(:alt , /sub/).exists? )
136
+
137
+ assert_false( browser.button(:alt , "missing").exists? )
138
+ assert_false( browser.button(:alt , /missing/).exists? )
139
+
140
+ #assert( browser.button(:src , "file:///#{$myDir}/html/images/button.jpg").exists? ) # this doesnt work for everybody
141
+ assert( browser.button(:src , /button/).exists? )
142
+
143
+ assert_false( browser.button(:src , "missing").exists? )
144
+ assert_false( browser.button(:src , /missing/).exists? )
145
+ assert_nothing_raised("raised an exception when it shouldnt have") { browser.button(:src , /button/).click }
146
+
147
+ assert( browser.contains_text("PASS") )
148
+ end
149
+ end
150
+
151
+ class TC_Forms4_XPath < Test::Unit::TestCase
152
+ def setup
153
+ goto_page "forms4.html"
154
+ end
155
+
156
+ def test_find_text_field_ignoring_form
157
+ assert_equal(browser.text_field(:name, 'name').value, 'apple') # should it raise a not-unique error instead?
158
+ end
159
+
160
+ def test_correct_form_field_is_found_using_form_name
161
+ assert_equal(browser.form(:xpath , "//form[@name='apple_form']/").text_field(:name, 'name').value, 'apple')
162
+ assert_equal(browser.form(:xpath , "//form[@name='banana_form']/").text_field(:name, 'name').value, 'banana')
163
+ end
164
+
165
+ def test_using_text_on_form
166
+ browser.form(:xpath , "//form[@name='apple_form']/").text_field(:name, 'name').set('strudel')
167
+ assert_equal(browser.form(:index, 0).text_field(:name, 'name').value, 'strudel')
168
+ end
169
+
170
+ def test_submit
171
+ browser.form(:xpath , "//form[@name='apple_form']/").submit
172
+ assert( browser.contains_text("PASS") )
173
+ end
174
+ end
175
+
176
+ class TC_Hidden_Fields_XPath < Test::Unit::TestCase
177
+ def setup
178
+ goto_page "forms3.html"
179
+ end
180
+
181
+ def test_hidden
182
+
183
+ # test using index
184
+ assert( browser.hidden(:index,0).exists? )
185
+ assert( browser.hidden(:index,1).exists? )
186
+ assert_false( browser.hidden(:index,2).exists? )
187
+
188
+ browser.hidden(:index,0).value = 44
189
+ browser.hidden(:index,1).value = 55
190
+
191
+ browser.button(:value , "Show Hidden").click
192
+
193
+ assert_equal("44" , browser.text_field(:name , "vis1").value )
194
+ assert_equal("55" , browser.text_field(:name , "vis2").value )
195
+
196
+ # test using name and ID
197
+ assert( browser.hidden(:name ,"hid1").exists? )
198
+ assert( browser.hidden(:id,"hidden_1").exists? )
199
+ assert_false( browser.hidden(:name,"hidden_44").exists? )
200
+ assert_false( browser.hidden(:id,"hidden_55").exists? )
201
+
202
+ browser.hidden(:name ,"hid1").value = 444
203
+ browser.hidden(:id,"hidden_1").value = 555
204
+
205
+ browser.button(:value , "Show Hidden").click
206
+
207
+ assert_equal("444" , browser.text_field(:name , "vis1").value )
208
+ assert_equal("555" , browser.text_field(:name ,"vis2").value )
209
+
210
+ # test the over-ridden append method
211
+ browser.hidden(:name ,"hid1").append("a")
212
+ browser.button(:value , "Show Hidden").click
213
+ assert_equal("444a" , browser.text_field(:name , "vis1").value )
214
+ assert_equal("555" , browser.text_field(:name ,"vis2").value )
215
+
216
+ # test the over-ridden clear method
217
+ browser.hidden(:name ,"hid1").clear
218
+ browser.button(:value , "Show Hidden").click
219
+ assert_equal("" , browser.text_field(:name , "vis1").value )
220
+ assert_equal("555" , browser.text_field(:name ,"vis2").value )
221
+
222
+ # test using a form
223
+ assert( browser.form(:xpath , "//form[@name='has_a_hidden']/").hidden(:name ,"hid1").exists? )
224
+ assert( browser.form(:xpath , "//form[@name='has_a_hidden']/").hidden(:id,"hidden_1").exists? )
225
+ assert_false( browser.form(:xpath , "//form[@name='has_a_hidden']/").hidden(:name,"hidden_44").exists? )
226
+ assert_false( browser.form(:xpath , "//form[@name='has_a_hidden']/").hidden(:id,"hidden_55").exists? )
227
+
228
+ browser.form(:xpath , "//form[@name='has_a_hidden']/").hidden(:name ,"hid1").value = 222
229
+ browser.form(:xpath , "//form[@name='has_a_hidden']/").hidden(:id,"hidden_1").value = 333
230
+
231
+ browser.button(:value , "Show Hidden").click
232
+
233
+ assert_equal("222" , browser.text_field(:name , "vis1").value )
234
+ assert_equal("333" , browser.text_field(:name ,"vis2").value )
235
+
236
+ # iterators
237
+ assert_equal(2, browser.hiddens.length)
238
+ count =1
239
+ browser.hiddens.each do |h|
240
+ case count
241
+ when 1
242
+ assert_equal( "", h.id)
243
+ assert_equal( "hid1", h.name)
244
+ when 2
245
+ assert_equal( "", h.name)
246
+ assert_equal( "hidden_1", h.id)
247
+ end
248
+ count+=1
249
+ end
250
+
251
+ assert_equal("hid1" , browser.hiddens[0].name )
252
+ assert_equal("hidden_1" , browser.hiddens[1].id )
253
+ end
254
+ end