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,109 @@
1
+ # feature tests for Tables
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_Tables_XPath < Test::Unit::TestCase
7
+ include Watir::Exception
8
+
9
+ def setup
10
+ goto_page "table1.html"
11
+ end
12
+
13
+ def test_Table_Exists
14
+ assert_false(browser.table(:xpath , "//table[@id='missingTable']/").exists? )
15
+ assert(browser.table(:xpath , "//table[@id='t1']/").exists? )
16
+ end
17
+
18
+ def test_rows
19
+ assert_raises( UnknownObjectException ){ browser.table(:xpath , "//table[@id='missingTable']/").row_count }
20
+ assert_equal( 5 , browser.table(:xpath , "//table[@id='t1']/").row_count) # 4 rows and a header
21
+ end
22
+
23
+ def test_dynamic_tables
24
+ t = browser.table(:xpath , "//table[@id='t1']/")
25
+ assert_equal( 5, t.row_count)
26
+
27
+ browser.button(:xpath,"//input[@value='add row']/").click
28
+ assert_equal( 6, t.row_count)
29
+ end
30
+
31
+ def test_columns
32
+ assert_raises( UnknownObjectException ){ browser.table(:xpath , "//table[@id='missingTable']/").column_count }
33
+ assert_equal( 1 , browser.table(:xpath , "//table[@id='t1']/").column_count) # row one has 1 cell with a colspan of 2
34
+ end
35
+
36
+ def test_links_and_images_in_table
37
+ table = browser.table(:xpath , "//table[@id='pic_table']/")
38
+ image = table[0][1].image(:index,0)
39
+ assert_equal("106", image.width)
40
+
41
+ link = table[0][3].link(:index,0)
42
+ assert_equal("Google", link.innerText)
43
+ end
44
+
45
+ def test_table_from_element
46
+ goto_page "simple_table_buttons.html"
47
+
48
+ button = browser.button(:xpath , "//input[@id='b1']/")
49
+ table = Watir::Table.create_from_element(browser,button)
50
+
51
+ table[1][0].button(:index,0).click
52
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
53
+ end
54
+
55
+ def test_cell_directly
56
+
57
+ assert( browser.cell(:xpath , "//td[@id='cell1']/").exists? )
58
+ assert_false( browser.cell(:xpath , "//td[@id='no_exist']/").exists? )
59
+ assert_equal( "Row 1 Col1", browser.cell(:xpath , "//td[@id='cell1']/").to_s.strip )
60
+ end
61
+
62
+ def test_row_directly
63
+ assert( browser.row(:xpath , "//tr[@id='row1']/").exists? )
64
+ assert_false( browser.row(:xpath , "//tr[@id='no_exist']/").exists? )
65
+
66
+ assert_equal('Row 2 Col1' , browser.row(:xpath , "//tr[@id='row1']/")[0].to_s.strip )
67
+ end
68
+
69
+
70
+ def test_table_body
71
+ assert_equal( 3, browser.table(:xpath , "//table[@id='body_test']/").bodies.length )
72
+
73
+ count = 1
74
+ browser.table(:xpath , "//table[@id='body_test']/").bodies.each do |n|
75
+
76
+ # do something better here!
77
+ # n.flash # this line commented out to speed up the test
78
+
79
+ case count
80
+ when 1
81
+ compare_text = "This text is in the FRST TBODY."
82
+ when 2
83
+ compare_text = "This text is in the SECOND TBODY."
84
+ when 3
85
+ compare_text = "This text is in the THIRD TBODY."
86
+ end
87
+
88
+ assert_equal( compare_text , n[0][0].to_s.strip ) # this is the 1st cell of the first row of this particular body
89
+
90
+ count +=1
91
+ end
92
+ assert_equal( count-1, browser.table(:xpath , "//table[@id='body_test']/").bodies.length )
93
+
94
+ assert_equal( "This text is in the THIRD TBODY." ,browser.table(:xpath , "//table[@id='body_test']/").body(:index,2)[0][0].to_s.strip )
95
+
96
+ # iterate through all the rows in a table body
97
+ count = 1
98
+ browser.table(:xpath , "//table[@id='body_test']/").body(:index,1).each do | row |
99
+ # row.flash # this line commented out, to speed up the tests
100
+ if count == 1
101
+ assert_equal('This text is in the SECOND TBODY.' , row[0].text.strip )
102
+ elsif count == 1
103
+ assert_equal('This text is also in the SECOND TBODY.' , row[0].text.strip )
104
+ end
105
+ count+=1
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
2
+
3
+ require 'unittests/setup'
4
+ require 'unittests/checkbox_test'
5
+
6
+ Watir::UnitTest.filter = proc do |test|
7
+ !test.tagged?(:firewatir_bug)
8
+ end
9
+
@@ -0,0 +1,92 @@
1
+ # tests for textarea elements
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_TextArea < Test::Unit::TestCase
7
+ include Watir::Exception
8
+
9
+ def setup
10
+ goto_page 'textarea.html'
11
+ end
12
+
13
+ def test_elements_exist_or_not
14
+ assert(browser.text_field(:name,"txtMultiLine1").exists?)
15
+ assert(browser.text_field(:name,"txtMultiLine2").exists?)
16
+ assert(browser.text_field(:name,"txtMultiLine3").exists?)
17
+ assert(browser.text_field(:name,"txtReadOnly").exists?)
18
+
19
+ assert(browser.text_field(:id,"txtMultiLine1").exists?)
20
+ assert(browser.text_field(:id,"txtMultiLine2").exists?)
21
+ assert(browser.text_field(:id,"txtMultiLine3").exists?)
22
+ assert(browser.text_field(:id,"txtReadOnly").exists?)
23
+
24
+ assert_false(browser.text_field(:name, "missing").exists?)
25
+ assert_false(browser.text_field(:name,"txtMultiLine4").exists?)
26
+ end
27
+
28
+ def test_to_s_bug
29
+ # from a bug reported by Zeljko Filipin
30
+ assert_nothing_raised { browser.text_field(:id,"txtMultiLine3").to_s }
31
+ end
32
+
33
+ def test_maxlength_bug
34
+ # from another bug
35
+ assert_nothing_raised { browser.text_field(:id,"txtMultiLine3").append('foo')}
36
+ end
37
+
38
+ def test_readonly_and_enabled
39
+ assert_false(browser.text_field(:name, "txtMultiLine1").readonly? )
40
+ assert(browser.text_field(:name,"txtReadOnly").readonly?)
41
+
42
+ assert_false(browser.text_field(:name, "txtDisabled").enabled? )
43
+ assert(browser.text_field(:id, "txtMultiLine1").enabled? )
44
+ end
45
+
46
+ def test_verify_contains
47
+ t1 = browser.text_field(:name, "txtMultiLine1")
48
+ assert(t1.verify_contains("Hello World") )
49
+ assert(t1.verify_contains(/el/) )
50
+ assert(browser.text_field(:name, "txtMultiLine2").verify_contains(/IE/))
51
+ end
52
+
53
+ def test_no_such_element
54
+ assert_raises(UnknownObjectException) do
55
+ browser.text_field(:name, "NoName").verify_contains("de nada")
56
+ end
57
+ assert_raises(UnknownObjectException) do
58
+ browser.text_field(:id, "noID").verify_contains("de nada")
59
+ end
60
+ assert_raises(UnknownObjectException) do
61
+ browser.text_field(:name, "txtNone").append("de nada")
62
+ end
63
+ end
64
+ def test_readonly_and_disabled_errors
65
+ assert_raises(ObjectReadOnlyException) do
66
+ browser.text_field(:id, "txtReadOnly").append("de nada")
67
+ end
68
+ assert_raises(ObjectDisabledException) do
69
+ browser.text_field(:name, "txtDisabled").append("de nada")
70
+ end
71
+ assert_raises(ObjectReadOnlyException) do
72
+ browser.text_field(:id, "txtReadOnly").append("Some Text")
73
+ end
74
+ assert_raises(ObjectDisabledException) do
75
+ browser.text_field(:name, "txtDisabled").append("Some Text")
76
+ end
77
+ end
78
+
79
+ def test_append_set_and_clear
80
+ browser.text_field(:name, "txtMultiLine1").append(" Some Text")
81
+ assert_equal("Hello World Some Text",
82
+ browser.text_field(:name, "txtMultiLine1").value )
83
+
84
+ browser.text_field(:name, "txtMultiLine1").set("watir IE Controller")
85
+ assert_equal("watir IE Controller",
86
+ browser.text_field(:name, "txtMultiLine1").value )
87
+
88
+ browser.text_field(:name, "txtMultiLine2").clear
89
+ assert_equal("" , browser.text_field(:name, "txtMultiLine2").value )
90
+ end
91
+
92
+ end
@@ -0,0 +1,77 @@
1
+ # feature tests for TextArea Fields
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_TextArea_XPath < Test::Unit::TestCase
7
+ include Watir::Exception
8
+
9
+ def setup
10
+ goto_page "textArea.html"
11
+ end
12
+
13
+ def test_textarea_field_exists
14
+ #test for existance of 4 text area
15
+ assert(browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").exists?)
16
+ assert(browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").exists?)
17
+ assert(browser.text_field(:xpath , "//textarea[@name='txtMultiLine3']/").exists?)
18
+ assert(browser.text_field(:xpath , "//textarea[@name='txtReadOnly']/").exists?)
19
+
20
+ assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine1']/").exists?)
21
+ assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine2']/").exists?)
22
+ assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine3']/").exists?)
23
+ assert(browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").exists?)
24
+ #test for missing
25
+ assert_false(browser.text_field(:xpath , "//textarea[@name='missing']/").exists?)
26
+ assert_false(browser.text_field(:xpath , "//textarea[@name='txtMultiLine4']/").exists?)
27
+ end
28
+
29
+ def xtest_textarea_to_s
30
+ # bug reported by Zeljko Filipin
31
+ # assert_nothing_raised { browser.text_field(:xpath , "//textarea[@id='txtMultiLine3']/").to_s }
32
+ # The above assertion fails. No property or method called maxlength
33
+ end
34
+
35
+ def test_textarea_field
36
+ # test for read only method
37
+ assert_false(browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").readonly? )
38
+ assert(browser.text_field(:xpath , "//textarea[@name='txtReadOnly']/").readonly?)
39
+
40
+ # test for enabled? method
41
+ assert_false(browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").enabled? )
42
+ assert(browser.text_field(:xpath , "//textarea[@id='txtMultiLine1']/").enabled? )
43
+
44
+
45
+ t1 = browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/")
46
+ assert(t1.verify_contains("Hello World") )
47
+ assert(t1.verify_contains(/el/) )
48
+ t2 = browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/")
49
+ assert(t2.verify_contains(/IE/))
50
+ assert_raises(UnknownObjectException) { browser.text_field(:xpath , "//textarea[@name='NoName']/").verify_contains("No field to get a value of") }
51
+ assert_raises(UnknownObjectException) { browser.text_field(:xpath , "//textarea[@id='noID']/").verify_contains("No field to get a value of") }
52
+
53
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtNone']/").append("Some Text") }
54
+
55
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
56
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
57
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
58
+
59
+ browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").append(" Some Text")
60
+ assert_equal( "Hello World Some Text" , browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").value)
61
+
62
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
63
+ assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
64
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
65
+
66
+ browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").set("watir IE Controller")
67
+ assert_equal( "watir IE Controller" , browser.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").value )
68
+
69
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
70
+ assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
71
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { browser.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
72
+
73
+ browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").clear
74
+ assert_equal( "" , browser.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").value )
75
+ end
76
+
77
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_Fields_For_Chinese_Char < Test::Unit::TestCase
7
+
8
+ def setup()
9
+ goto_page "textfields1.html"
10
+ end
11
+
12
+ def test_chinese_char_should_be_appended_to_text_field
13
+ browser.text_field(:name, "text1").append(" ijij")
14
+ assert_equal( "Hello World ijij" , browser.text_field(:name, "text1").value )
15
+ end
16
+
17
+ def test_mixed_char_should_be_appended_to_text_field
18
+ browser.text_field(:name, "text1").append(" ijaija")
19
+ assert_equal( "Hello World ijaija" , browser.text_field(:name, "text1").value )
20
+ end
21
+
22
+ def test_chinese_char_should_be_set_to_text_field
23
+ browser.text_field(:name, "text1").set("ijij")
24
+ assert_equal( "ijij" , browser.text_field(:name, "text1").value )
25
+ end
26
+
27
+ def test_mixed_char_should_be_set_to_text_field
28
+ browser.text_field(:name, "text1").set("ijaija")
29
+ assert_equal( "ijaija" , browser.text_field(:name, "text1").value )
30
+ end
31
+
32
+ end
@@ -0,0 +1,184 @@
1
+ # feature tests for Text Fields & Labels
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_Fields < Test::Unit::TestCase
7
+ include Watir::Exception
8
+
9
+ def setup
10
+ goto_page "textfields1.html"
11
+ end
12
+
13
+ tag_method :test_text_field_exists, :fails_on_firefox
14
+ def test_text_field_exists
15
+ assert(browser.text_field(:name, "text1").exists?)
16
+ assert_false(browser.text_field(:name, "missing").exists?)
17
+
18
+ assert(browser.text_field(:id, "text2").exists?)
19
+ assert_false(browser.text_field(:id, "alsomissing").exists?)
20
+
21
+ assert(browser.text_field(:value, 'foo').exists?)
22
+ end
23
+
24
+ tag_method :test_text_field_dragContentsTo, :fails_on_firefox
25
+ def test_text_field_dragContentsTo
26
+ browser.text_field(:name, "text1").drag_contents_to(:id, "text2")
27
+ assert_equal(browser.text_field(:name, "text1").value, "")
28
+ assert_equal(browser.text_field(:id, "text2").value, "goodbye allHello World")
29
+ end
30
+
31
+ def test_text_field_verify_contains
32
+ assert(browser.text_field(:name, "text1").verify_contains("Hello World"))
33
+ assert(browser.text_field(:name, "text1").verify_contains(/Hello\sW/))
34
+ assert_false(browser.text_field(:name, "text1").verify_contains("Ruby"))
35
+ assert_false(browser.text_field(:name, "text1").verify_contains(/R/))
36
+ assert_raises(UnknownObjectException) { browser.text_field(:name, "NoName").verify_contains("No field to get a value of") }
37
+
38
+ assert(browser.text_field(:id, "text2").verify_contains("goodbye all") )
39
+ assert_raises(UnknownObjectException) { browser.text_field(:id, "noID").verify_contains("No field to get a value of") }
40
+ end
41
+
42
+ def test_text_field_enabled
43
+ assert_false(browser.text_field(:name, "disabled").enabled? )
44
+ assert(browser.text_field(:name, "text1").enabled? )
45
+ assert(browser.text_field(:id, "text2").enabled? )
46
+ end
47
+
48
+ def test_text_field_readonly
49
+ assert_false(browser.text_field(:name, "disabled").readonly? )
50
+ assert(browser.text_field(:name, "readOnly").readonly? )
51
+ assert(browser.text_field(:id, "readOnly2").readonly? )
52
+ end
53
+
54
+ def test_text_field_get_contents
55
+ assert_raises(UnknownObjectException) { browser.text_field(:name, "missing_field").append("Some Text") }
56
+ assert_equal("Hello World", browser.text_field(:name, "text1").value)
57
+ end
58
+
59
+ tag_method :test_text_field_append, :fails_on_firefox
60
+ def test_text_field_append
61
+ assert_raises(ObjectReadOnlyException) { browser.text_field(:id, "readOnly2").append("Some Text") }
62
+ assert_raises(ObjectDisabledException) { browser.text_field(:name, "disabled").append("Some Text") }
63
+ assert_raises(UnknownObjectException) { browser.text_field(:name, "missing_field").append("Some Text") }
64
+
65
+ browser.text_field(:name, "text1").append(" Some Text")
66
+ assert_equal("Hello World Some Text", browser.text_field(:name, "text1").value)
67
+ end
68
+
69
+ def test_text_field_clear
70
+ browser.text_field(:name, "text1").clear
71
+ assert_equal("", browser.text_field(:name, "text1").value)
72
+ end
73
+
74
+ def test_text_field_set
75
+ browser.text_field(:name, "text1").set("watir IE Controller")
76
+ assert_equal("watir IE Controller", browser.text_field(:name, "text1").value)
77
+ # adding for issue: http://jira.openqa.org/browse/WTR-89
78
+ browser.text_field(:name, /reGex/i).set("pass")
79
+ assert_equal("pass", browser.text_field(:name, /REgEx/i).value)
80
+ end
81
+
82
+ def test_text_field_properties
83
+ assert_raises(UnknownObjectException) { browser.text_field(:index, 199).value }
84
+ assert_raises(UnknownObjectException) { browser.text_field(:index, 199).name }
85
+ assert_raises(UnknownObjectException) { browser.text_field(:index, 199).id }
86
+ assert_raises(UnknownObjectException) { browser.text_field(:index, 199).disabled? }
87
+ assert_raises(UnknownObjectException) { browser.text_field(:index, 199).type }
88
+
89
+ assert_equal("Hello World" , browser.text_field(:index, 0).value)
90
+ assert_equal("text" , browser.text_field(:index, 0).type)
91
+ assert_equal("text1" , browser.text_field(:index, 0).name)
92
+ assert_equal("" , browser.text_field(:index, 0).id)
93
+ assert_equal(false , browser.text_field(:index, 0).disabled?)
94
+
95
+ assert_equal("" , browser.text_field(:index, 1).name)
96
+ assert_equal("text2" , browser.text_field(:index, 1).id)
97
+
98
+ assert(browser.text_field(:index, 3).disabled?)
99
+
100
+ assert_equal("This used to test :afterText", browser.text_field(:name, "aftertest").title)
101
+ assert_equal("", browser.text_field(:index, 0).title)
102
+ # adding for issue: http://jira.openqa.org/browse/WTR-89
103
+ assert_equal("RegEx test", browser.text_field(:name, /REgEx/i).value)
104
+ end
105
+
106
+ def test_text_field_iterators
107
+ assert_equal(14, browser.text_fields.length)
108
+
109
+ assert_equal("Hello World", browser.text_fields[0].value)
110
+ assert_equal("text1", browser.text_fields[0].name)
111
+ assert_equal("password", browser.text_fields[browser.text_fields.length - 1].type)
112
+
113
+ index = 0
114
+ browser.text_fields.each do |t|
115
+ assert_equal(browser.text_field(:index, index).value, t.value)
116
+ assert_equal(browser.text_field(:index, index).id, t.id)
117
+ assert_equal(browser.text_field(:index, index).name, t.name)
118
+ index += 1
119
+ end
120
+ assert_equal(index, browser.text_fields.length)
121
+ end
122
+
123
+ tag_method :test_JS_Events, :fails_on_firefox
124
+ def test_JS_Events
125
+ browser.text_field(:name, 'events_tester').requires_typing.set('p')
126
+
127
+ # the following line has an extra keypress at the begining, as we mimic the delete key being pressed
128
+ assert_equal( "keypresskeydownkeypresskeyup" , browser.text_field(:name, 'events_text').value.gsub(/(\r|\n)/ , "") )
129
+ browser.button(:value, "Clear Events Box").click
130
+ browser.text_field(:name, 'events_tester').requires_typing.set('ab')
131
+
132
+ # the following line has an extra keypress at the begining, as we mimic the delete key being pressed
133
+ assert_equal( "keypresskeydownkeypresskeyupkeydownkeypresskeyup", browser.text_field(:name , 'events_text').value.gsub(/(\r|\n)/ , "") )
134
+ end
135
+
136
+ def test_password
137
+ browser.text_field(:name, "password1").set("secret")
138
+ assert( 'secret' , browser.text_field(:name, "password1").value )
139
+
140
+ browser.text_field(:id, "password1").set("top_secret")
141
+ assert('top_secret', browser.text_field(:id, "password1").value )
142
+ end
143
+
144
+ def test_labels_iterator
145
+ assert_equal(3, browser.labels.length)
146
+ assert_equal('Label For this Field' , browser.labels[0].text.strip )
147
+ assert_equal('Password With ID ( the text here is a label for it )' , browser.labels[2].text )
148
+
149
+ count=0
150
+ browser.labels.each do |l|
151
+ count +=1
152
+ end
153
+ assert_equal(count, browser.labels.length)
154
+ end
155
+
156
+ def test_label_properties
157
+ assert_raises(UnknownObjectException) { browser.label(:index,20).text }
158
+ assert_raises(UnknownObjectException) { browser.label(:index,20).for }
159
+ assert_raises(UnknownObjectException) { browser.label(:index,20).id }
160
+
161
+ assert_false(browser.label(:index,10).exists?)
162
+ assert_false(browser.label(:id,'missing').exists?)
163
+ assert(browser.label(:index,0).exists?)
164
+
165
+ assert_equal("", browser.label(:index,0).id)
166
+ assert_false(browser.label(:index,0).disabled?)
167
+ assert(browser.label(:index,0).enabled?)
168
+
169
+ assert_equal("label2", browser.label(:index,1).id )
170
+
171
+ assert_equal("Password With ID ( the text here is a label for it )" , browser.label(:index,2).text)
172
+ assert_equal("password1", browser.label(:index,2).for)
173
+ end
174
+
175
+ def test_max_length_is_not_exceeded
176
+ browser.text_field(:name, 'text1').set("abcdefghijklmnopqrstuv")
177
+ assert_equal("abcdefghijklmnopqrst", browser.text_field(:name, 'text1').value )
178
+ end
179
+
180
+ def test_max_length
181
+ assert_equal(20, browser.text_field(:name, 'text1').maxlength)
182
+ end
183
+
184
+ end