watir 1.4.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/bin/watir-console +1 -0
  2. data/changes.rb +119 -0
  3. data/license.rb +37 -0
  4. data/readme.rb +55 -120
  5. data/unittests/buttons_test.rb +107 -104
  6. data/unittests/buttons_xpath_test.rb +69 -0
  7. data/unittests/checkbox_test.rb +154 -141
  8. data/unittests/checkbox_xpath_test.rb +107 -0
  9. data/unittests/core_tests.rb +6 -2
  10. data/unittests/css_test.rb +50 -50
  11. data/unittests/defer_test.rb +47 -0
  12. data/unittests/dialog_test.rb +78 -0
  13. data/unittests/div2_xpath_test.rb +22 -0
  14. data/unittests/div_test.rb +159 -159
  15. data/unittests/div_xpath_test.rb +96 -0
  16. data/unittests/errorchecker_test.rb +22 -22
  17. data/unittests/filefield_test.rb +30 -23
  18. data/unittests/filefield_xpath_test.rb +35 -0
  19. data/unittests/form_test.rb +250 -229
  20. data/unittests/form_xpath_test.rb +253 -0
  21. data/unittests/frame_test.rb +123 -108
  22. data/unittests/google_form_test.rb +17 -0
  23. data/unittests/html/JavascriptClick.html +39 -0
  24. data/unittests/html/buttons1.html +3 -2
  25. data/unittests/html/checkboxes1.html +32 -14
  26. data/unittests/html/complex_table.html +1 -1
  27. data/unittests/html/depot_store.html +59 -0
  28. data/unittests/html/div.html +3 -21
  29. data/unittests/html/div_xml.html +21 -0
  30. data/unittests/html/fileupload.html +2 -2
  31. data/unittests/html/forms2.html +3 -3
  32. data/unittests/html/forms3.html +2 -2
  33. data/unittests/html/frame_links.html +2 -2
  34. data/unittests/html/google_india.html +119 -0
  35. data/unittests/html/iframeTest.html +2 -2
  36. data/unittests/html/images/map.GIF +0 -0
  37. data/unittests/html/images/map2.gif +0 -0
  38. data/unittests/html/images1.html +17 -2
  39. data/unittests/html/javascriptevents.html +3 -7
  40. data/unittests/html/links1.html +9 -8
  41. data/unittests/html/links_multi.html +14 -0
  42. data/unittests/html/list_matters.html +720 -0
  43. data/unittests/html/lists.html +18 -0
  44. data/unittests/html/map_test.html +31 -0
  45. data/unittests/html/modal_dialog.html +10 -0
  46. data/unittests/html/modal_dialog_launcher.html +12 -0
  47. data/unittests/html/new_browser.html +17 -0
  48. data/unittests/html/pass.html +3 -0
  49. data/unittests/html/popups1.html +1 -1
  50. data/unittests/html/pre.html +28 -0
  51. data/unittests/html/radioButtons1.html +6 -5
  52. data/unittests/html/selectboxes1.html +12 -11
  53. data/unittests/html/simple_table.html +1 -1
  54. data/unittests/html/simple_table_columns.html +1 -1
  55. data/unittests/html/table1.html +1 -1
  56. data/unittests/html/tableCell_using_xpath.html +19 -0
  57. data/unittests/html/textfields1.html +6 -4
  58. data/unittests/html/xpath_nbsp.html +12 -0
  59. data/unittests/ie_exists_test.rb +32 -0
  60. data/unittests/ie_mock.rb +78 -79
  61. data/unittests/ie_test.rb +39 -39
  62. data/unittests/images_test.rb +132 -155
  63. data/unittests/images_xpath_test.rb +91 -0
  64. data/unittests/links_multi_test.rb +36 -0
  65. data/unittests/links_test.rb +158 -152
  66. data/unittests/links_xpath_test.rb +40 -0
  67. data/unittests/lists_test.rb +29 -0
  68. data/unittests/map_test.rb +99 -0
  69. data/unittests/minmax_test.rb +23 -23
  70. data/unittests/navigate_test.rb +43 -51
  71. data/unittests/nbsp_xpath_test.rb +18 -0
  72. data/unittests/other/WindowLogonExample.rb +28 -0
  73. data/unittests/{WindowLogonExtra.rb → other/WindowLogonExtra.rb} +0 -0
  74. data/unittests/{all_tests_concurrent.rb → other/all_tests_concurrent.rb} +23 -23
  75. data/unittests/other/navigate_exception_test.rb +14 -0
  76. data/unittests/other/rexml_unit_test.rb +24 -0
  77. data/unittests/other/testcase_method_order_test.rb +36 -0
  78. data/unittests/other/testcase_verify_test.rb +25 -0
  79. data/unittests/other/wait_until_test.rb +99 -0
  80. data/unittests/pagecontainstext_test.rb +56 -37
  81. data/unittests/parent_child_test.rb +55 -0
  82. data/unittests/popups_test.rb +37 -37
  83. data/unittests/pre_test.rb +52 -0
  84. data/unittests/radios_test.rb +186 -155
  85. data/unittests/radios_xpath_test.rb +101 -0
  86. data/unittests/screen_capture_test.rb +41 -41
  87. data/unittests/selectbox_test.rb +223 -181
  88. data/unittests/selectbox_xpath_test.rb +113 -0
  89. data/unittests/setup.rb +29 -25
  90. data/unittests/speed_settings_test.rb +22 -0
  91. data/unittests/table_cell_using_xpath_test.rb +40 -0
  92. data/unittests/table_test.rb +315 -284
  93. data/unittests/table_xpath_test.rb +114 -0
  94. data/unittests/textarea_test.rb +81 -0
  95. data/unittests/textarea_xpath_test.rb +82 -0
  96. data/unittests/textfields_test.rb +205 -229
  97. data/unittests/textfields_xpath_test.rb +111 -0
  98. data/unittests/window_tests.rb +7 -0
  99. data/unittests/windows/attach_to_existing_window_test.rb +52 -0
  100. data/unittests/windows/attach_to_new_window_test.rb +82 -0
  101. data/unittests/windows/close_window_test.rb +22 -0
  102. data/unittests/windows/frame_links_test.rb +25 -0
  103. data/unittests/windows/ie-each_test.rb +48 -0
  104. data/unittests/windows/iedialog_test.rb +55 -0
  105. data/unittests/windows/js_events_test.rb +57 -0
  106. data/unittests/windows/jscriptExtraAlert.rb +6 -0
  107. data/unittests/windows/jscriptExtraConfirmCancel.rb +7 -0
  108. data/unittests/windows/jscriptExtraConfirmOk.rb +7 -0
  109. data/unittests/{jscriptPushButton.rb → windows/jscriptPushButton.rb} +1 -1
  110. data/unittests/windows/jscript_test.rb +64 -0
  111. data/unittests/windows/modal_dialog_test.rb +127 -0
  112. data/unittests/windows/new.rb +56 -0
  113. data/unittests/windows/open_close_test.rb +22 -0
  114. data/unittests/windows/send_keys_test.rb +34 -0
  115. data/unittests/xpath_tests.rb +10 -0
  116. data/watir.rb +4344 -3565
  117. data/watir/IEDialog/Release/IEDialog.dll +0 -0
  118. data/watir/WindowHelper.rb +13 -11
  119. data/watir/assertions.rb +36 -0
  120. data/watir/camel_case.rb +14 -5
  121. data/watir/close_all.rb +38 -0
  122. data/watir/contrib/enabled_popup.rb +21 -0
  123. data/watir/contrib/ie-new-process.rb +27 -0
  124. data/watir/contrib/page_checker.rb +29 -0
  125. data/watir/contrib/visible.rb +47 -0
  126. data/watir/cookiemanager.rb +4 -4
  127. data/watir/datahandler.rb +107 -0
  128. data/watir/dialog.rb +46 -0
  129. data/watir/elements.rb +65 -0
  130. data/watir/exceptions.rb +18 -36
  131. data/watir/ie-process.rb +40 -0
  132. data/watir/irb-history.rb +31 -0
  133. data/watir/process.rb +20 -0
  134. data/watir/testUnitAddons.rb +3 -42
  135. data/watir/testcase.rb +58 -0
  136. data/watir/utils.rb +20 -0
  137. data/watir/waiter.rb +88 -0
  138. data/watir/watir_simple.rb +4 -4
  139. data/watir/win32ole.rb +8 -0
  140. data/watir/win32ole/win32ole.so +0 -0
  141. data/watir/winClicker.rb +374 -400
  142. metadata +209 -128
  143. data/unittests/WindowLogonExample.rb +0 -30
  144. data/unittests/attachToExistingWindow_test.rb +0 -40
  145. data/unittests/js_events_test.rb +0 -77
  146. data/unittests/jscriptExtraAlert.rb +0 -6
  147. data/unittests/jscriptExtraConfirmCancel.rb +0 -7
  148. data/unittests/jscriptExtraConfirmOk.rb +0 -7
  149. data/unittests/jscript_test.rb +0 -57
  150. data/unittests/send_keys_test.rb +0 -29
  151. data/unittests/textAreafields_test.rb +0 -81
@@ -0,0 +1,114 @@
1
+ # feature tests for Tables
2
+ # revision: $Revision: 962 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_Tables_XPath < Test::Unit::TestCase
8
+ include Watir
9
+
10
+ def setup
11
+ gotoTablePage
12
+ end
13
+
14
+ def gotoTablePage
15
+ $ie.goto($htmlRoot + "table1.html")
16
+ end
17
+
18
+ def test_Table_Exists
19
+ assert(!$ie.table(:xpath , "//table[@id='missingTable']/").exists? )
20
+ assert($ie.table(:xpath , "//table[@id='t1']/").exists? )
21
+ end
22
+
23
+ def test_rows
24
+ assert_raises( UnknownObjectException ){ $ie.table(:xpath , "//table[@id='missingTable']/").row_count }
25
+ assert_equal( 5 , $ie.table(:xpath , "//table[@id='t1']/").row_count) # 4 rows and a header
26
+ end
27
+
28
+ def test_dynamic_tables
29
+ t = $ie.table(:xpath , "//table[@id='t1']/")
30
+ assert_equal( 5, t.row_count)
31
+
32
+ $ie.button(:xpath,"//input[@value='add row']/").click
33
+ assert_equal( 6, t.row_count)
34
+ end
35
+
36
+ def test_columns
37
+ assert_raises( UnknownObjectException ){ $ie.table(:xpath , "//table[@id='missingTable']/").column_count }
38
+ assert_equal( 1 , $ie.table(:xpath , "//table[@id='t1']/").column_count) # row one has 1 cell with a colspan of 2
39
+ end
40
+
41
+ def test_links_and_images_in_table
42
+ table = $ie.table(:xpath , "//table[@id='pic_table']/")
43
+ image = table[1][2].image(:index,1)
44
+ assert_equal("106", image.width)
45
+
46
+ link = table[1][4].link(:index,1)
47
+ assert_equal("Google", link.innerText)
48
+ end
49
+
50
+ def test_table_from_element
51
+ $ie.goto($htmlRoot + "simple_table_buttons.html")
52
+
53
+ button = $ie.button(:xpath , "//input[@id='b1']/")
54
+ table = Table.create_from_element($ie,button)
55
+
56
+ table[2][1].button(:index,1).click
57
+ assert($ie.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
58
+ end
59
+
60
+ def test_cell_directly
61
+
62
+ assert( $ie.cell(:xpath , "//td[@id='cell1']/").exists? )
63
+ assert(! $ie.cell(:xpath , "//td[@id='no_exist']/").exists? )
64
+ assert_equal( "Row 1 Col1", $ie.cell(:xpath , "//td[@id='cell1']/").to_s.strip )
65
+ end
66
+
67
+ def test_row_directly
68
+ assert( $ie.row(:xpath , "//tr[@id='row1']/").exists? )
69
+ assert(! $ie.row(:xpath , "//tr[@id='no_exist']/").exists? )
70
+
71
+ assert_equal('Row 2 Col1' , $ie.row(:xpath , "//tr[@id='row1']/")[1].to_s.strip )
72
+ end
73
+
74
+
75
+ def test_table_body
76
+ assert_equal( 3, $ie.table(:xpath , "//table[@id='body_test']/").bodies.length )
77
+
78
+ count = 1
79
+ $ie.table(:xpath , "//table[@id='body_test']/").bodies.each do |n|
80
+
81
+ # do something better here!
82
+ # n.flash # this line commented out to speed up the test
83
+
84
+ case count
85
+ when 1
86
+ compare_text = "This text is in the FRST TBODY."
87
+ when 2
88
+ compare_text = "This text is in the SECOND TBODY."
89
+ when 3
90
+ compare_text = "This text is in the THIRD TBODY."
91
+ end
92
+
93
+ assert_equal( compare_text , n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
94
+
95
+ count +=1
96
+ end
97
+ assert_equal( count-1, $ie.table(:xpath , "//table[@id='body_test']/").bodies.length )
98
+
99
+ assert_equal( "This text is in the THIRD TBODY." ,$ie.table(:xpath , "//table[@id='body_test']/").body(:index,3)[1][1].to_s.strip )
100
+
101
+ # iterate through all the rows in a table body
102
+ count = 1
103
+ $ie.table(:xpath , "//table[@id='body_test']/").body(:index,2).each do | row |
104
+ # row.flash # this line commented out, to speed up the tests
105
+ if count == 1
106
+ assert_equal('This text is in the SECOND TBODY.' , row[1].text.strip )
107
+ elsif count == 1
108
+ assert_equal('This text is also in the SECOND TBODY.' , row[1].text.strip )
109
+ end
110
+ count+=1
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,81 @@
1
+ # feature tests for TextArea Fields
2
+ # revision: $Revision: 963 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_TextArea < Test::Unit::TestCase
8
+ include Watir
9
+
10
+ def goto_page
11
+ $ie.goto($htmlRoot + "textArea.html")
12
+ end
13
+
14
+ def test_textarea_field_exists
15
+ goto_page
16
+ #test for existance of 4 text area
17
+ assert($ie.text_field(:name,"txtMultiLine1").exists?)
18
+ assert($ie.text_field(:name,"txtMultiLine2").exists?)
19
+ assert($ie.text_field(:name,"txtMultiLine3").exists?)
20
+ assert($ie.text_field(:name,"txtReadOnly").exists?)
21
+
22
+ assert($ie.text_field(:id,"txtMultiLine1").exists?)
23
+ assert($ie.text_field(:id,"txtMultiLine2").exists?)
24
+ assert($ie.text_field(:id,"txtMultiLine3").exists?)
25
+ assert($ie.text_field(:id,"txtReadOnly").exists?)
26
+ #test for missing
27
+ assert(!$ie.text_field(:name, "missing").exists?)
28
+ assert(!$ie.text_field(:name,"txtMultiLine4").exists?)
29
+ end
30
+
31
+ def test_textarea_to_s
32
+ # from a bug reported by Zeljko Filipin
33
+ assert_nothing_raised { $ie.text_field(:id,"txtMultiLine3").to_s }
34
+ end
35
+
36
+ def test_textarea_field
37
+ goto_page
38
+
39
+ # test for read only method
40
+ assert(!$ie.text_field(:name, "txtMultiLine1").readonly? )
41
+ assert($ie.text_field(:name,"txtReadOnly").readonly?)
42
+
43
+ # test for enabled? method
44
+ assert(!$ie.text_field(:name, "txtDisabled").enabled? )
45
+ assert($ie.text_field(:id, "txtMultiLine1").enabled? )
46
+
47
+
48
+ t1 = $ie.text_field(:name, "txtMultiLine1")
49
+ assert(t1.verify_contains("Hello World") )
50
+ assert(t1.verify_contains(/el/) )
51
+ t2 = $ie.text_field(:name, "txtMultiLine2")
52
+ assert(t2.verify_contains(/IE/))
53
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:name, "NoName").verify_contains("No field to get a value of") }
54
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:id, "noID").verify_contains("No field to get a value of") }
55
+
56
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "txtNone").append("Some Text") }
57
+
58
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:id, "txtReadOnly").append("Some Text") }
59
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ie.text_field(:name, "txtDisabled").append("Some Text") }
60
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
61
+
62
+ $ie.text_field(:name, "txtMultiLine1").append(" Some Text")
63
+ assert_equal( "Hello World Some Text" , $ie.text_field(:name, "txtMultiLine1").getContents )
64
+
65
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:id, "txtReadOnly").append("Some Text") }
66
+ assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "txtDisabled").append("Some Text") }
67
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
68
+
69
+ $ie.text_field(:name, "txtMultiLine1").set("watir IE Controller")
70
+ assert_equal( "watir IE Controller" , $ie.text_field(:name, "txtMultiLine1").getContents )
71
+
72
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:id, "txtReadOnly").append("Some Text") }
73
+ assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "txtDisabled").append("Some Text") }
74
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
75
+
76
+ $ie.text_field(:name, "txtMultiLine2").clear
77
+ assert_equal( "" , $ie.text_field(:name, "txtMultiLine2").getContents )
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,82 @@
1
+ # feature tests for TextArea Fields
2
+ # revision: $Revision: 963 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_TextArea_XPath < Test::Unit::TestCase
8
+ include Watir
9
+
10
+ def goto_page
11
+ $ie.goto($htmlRoot + "textArea.html")
12
+ end
13
+
14
+ def test_textarea_field_exists
15
+ goto_page
16
+ #test for existance of 4 text area
17
+ assert($ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").exists?)
18
+ assert($ie.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").exists?)
19
+ assert($ie.text_field(:xpath , "//textarea[@name='txtMultiLine3']/").exists?)
20
+ assert($ie.text_field(:xpath , "//textarea[@name='txtReadOnly']/").exists?)
21
+
22
+ assert($ie.text_field(:xpath , "//textarea[@id='txtMultiLine1']/").exists?)
23
+ assert($ie.text_field(:xpath , "//textarea[@id='txtMultiLine2']/").exists?)
24
+ assert($ie.text_field(:xpath , "//textarea[@id='txtMultiLine3']/").exists?)
25
+ assert($ie.text_field(:xpath , "//textarea[@id='txtReadOnly']/").exists?)
26
+ #test for missing
27
+ assert(!$ie.text_field(:xpath , "//textarea[@name='missing']/").exists?)
28
+ assert(!$ie.text_field(:xpath , "//textarea[@name='txtMultiLine4']/").exists?)
29
+ end
30
+
31
+ def test_textarea_to_s
32
+ # bug reported by Zeljko Filipin
33
+ # assert_nothing_raised { $ie.text_field(:xpath , "//textarea[@id='txtMultiLine3']/").to_s }
34
+ # The above assertion fails. No property or method called maxlength
35
+ end
36
+
37
+ def test_textarea_field
38
+ goto_page
39
+
40
+ # test for read only method
41
+ assert(!$ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").readonly? )
42
+ assert($ie.text_field(:xpath , "//textarea[@name='txtReadOnly']/").readonly?)
43
+
44
+ # test for enabled? method
45
+ assert(!$ie.text_field(:xpath , "//textarea[@name='txtDisabled']/").enabled? )
46
+ assert($ie.text_field(:xpath , "//textarea[@id='txtMultiLine1']/").enabled? )
47
+
48
+
49
+ t1 = $ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/")
50
+ assert(t1.verify_contains("Hello World") )
51
+ assert(t1.verify_contains(/el/) )
52
+ t2 = $ie.text_field(:xpath , "//textarea[@name='txtMultiLine2']/")
53
+ assert(t2.verify_contains(/IE/))
54
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='NoName']/").verify_contains("No field to get a value of") }
55
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@id='noID']/").verify_contains("No field to get a value of") }
56
+
57
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='txtNone']/").append("Some Text") }
58
+
59
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
60
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
61
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
62
+
63
+ $ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").append(" Some Text")
64
+ assert_equal( "Hello World Some Text" , $ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").value)
65
+
66
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
67
+ assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
68
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
69
+
70
+ $ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").set("watir IE Controller")
71
+ assert_equal( "watir IE Controller" , $ie.text_field(:xpath , "//textarea[@name='txtMultiLine1']/").value )
72
+
73
+ assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@id='txtReadOnly']/").append("Some Text") }
74
+ assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='txtDisabled']/").append("Some Text") }
75
+ assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:xpath , "//textarea[@name='missing_field']/").append("Some Text") }
76
+
77
+ $ie.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").clear
78
+ assert_equal( "" , $ie.text_field(:xpath , "//textarea[@name='txtMultiLine2']/").value )
79
+
80
+ end
81
+
82
+ end
@@ -1,239 +1,215 @@
1
- # feature tests for Text Fields
2
- # revision: $Revision: 1.31 $
1
+ # feature tests for Text Fields & Labels
2
+ # revision: $Revision: 1196 $
3
3
 
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
5
  require 'unittests/setup'
6
6
 
7
7
  class TC_Fields < Test::Unit::TestCase
8
- include Watir
9
-
10
- def setup()
11
- $ie.goto($htmlRoot + "textfields1.html")
12
- end
13
-
14
- def test_text_field_exists
15
- assert($ie.text_field(:name, "text1").exists?)
16
- assert_false($ie.text_field(:name, "missing").exists?)
17
-
18
- assert($ie.text_field(:id, "text2").exists?)
19
- assert_false($ie.text_field(:id, "alsomissing").exists?)
20
-
21
- assert($ie.text_field(:beforeText , "This Text After").exists? )
22
- assert($ie.text_field(:afterText , "This Text Before").exists? )
23
-
24
- assert($ie.text_field(:beforeText , /after/i).exists? )
25
- assert($ie.text_field(:afterText , /before/i).exists? )
26
- end
27
-
28
- def test_text_field_dragContentsTo
29
- $ie.text_field(:name, "text1").dragContentsTo(:id, "text2")
30
- assert_equal($ie.text_field(:name, "text1").getContents, "" )
31
- assert_equal($ie.text_field(:id, "text2").getContents, "goodbye allHello World" )
32
- end
33
-
34
- def test_text_field_VerifyContents
35
- assert($ie.text_field(:name, "text1").verify_contains("Hello World") )
36
- assert($ie.text_field(:name, "text1").verify_contains(/Hello\sW/ ) )
37
- assert_false($ie.text_field(:name, "text1").verify_contains("Ruby") )
38
- assert_false($ie.text_field(:name, "text1").verify_contains(/R/) )
39
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:name, "NoName").verify_contains("No field to get a value of") }
40
-
41
- assert($ie.text_field(:id, "text2").verify_contains("goodbye all") )
42
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:id, "noID").verify_contains("No field to get a value of") }
43
-
44
- end
45
-
46
- def test_text_field_enabled
47
- assert_false($ie.text_field(:name, "disabled").enabled? )
48
- assert($ie.text_field(:name, "text1").enabled? )
49
- assert($ie.text_field(:id, "text2").enabled? )
50
- end
51
-
52
- def test_text_field_readOnly
53
- assert_false($ie.text_field(:name, "disabled").readonly? )
54
- assert($ie.text_field(:name, "readOnly").readonly? )
55
- assert($ie.text_field(:id, "readOnly2").readonly? )
56
- end
57
-
58
- def test_text_field_getContents()
59
- assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
60
- assert_equal( "Hello World" , $ie.text_field(:name, "text1").getContents )
61
- end
62
-
63
- def test_TextField_to_s
64
- expected = [build_to_s_regex("type", "text"),
65
- build_to_s_regex("id", ""),
66
- build_to_s_regex("name", "text1"),
67
- build_to_s_regex("value", "Hello World"),
68
- build_to_s_regex("disabled", "false"),
69
- build_to_s_regex("length", "20"),
70
- build_to_s_regex("max length", "2147483647"),
71
- build_to_s_regex("read only", "false")]
72
- items = $ie.text_field(:index, 1).to_s.split(/\n/)
73
- expected.each_with_index{|regex, x| assert(regex =~ items[x]) }
74
- expected[1] = build_to_s_regex("id", "text2")
75
- expected[2] = build_to_s_regex("name", "")
76
- expected[3] = build_to_s_regex("value", "goodbye all")
77
- items = $ie.text_field(:index, 2).to_s.split(/\n/)
78
- expected.each_with_index{|regex, x| assert(regex =~ items[x]) }
79
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:index, 999 ).to_s}
80
- end
8
+ include Watir
9
+
10
+ def setup
11
+ $ie.goto($htmlRoot + "textfields1.html")
12
+ end
13
+
14
+ def test_text_field_exists
15
+ assert($ie.text_field(:name, "text1").exists?)
16
+ assert(!$ie.text_field(:name, "missing").exists?)
81
17
 
82
- def build_to_s_regex(lhs, rhs)
83
- Regexp.new("^#{lhs}: +#{rhs}$")
84
- end
85
-
86
- def test_text_field_Append
87
- assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:id, "readOnly2").append("Some Text") }
88
- assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ie.text_field(:name, "disabled").append("Some Text") }
89
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
90
-
91
- $ie.text_field(:name, "text1").append(" Some Text")
92
- assert_equal( "Hello World Some Text" , $ie.text_field(:name, "text1").getContents )
93
-
94
- # may need this to see that it really happened
95
- #puts "press return to continue"
96
- #gets
97
-
98
- end
99
-
100
-
101
- def test_text_field_Clear
102
- assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:id, "readOnly2").append("Some Text") }
103
- assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "disabled").append("Some Text") }
104
- assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
105
-
106
- $ie.text_field(:name, "text1").clear()
107
- assert_equal( "" , $ie.text_field(:name, "text1").getContents )
108
-
109
- # may need this to see that it really happened
110
- #puts "press return to continue"
111
- #gets
112
-
113
- end
114
-
115
- def test_text_field_Set
116
- assert_raises(ObjectReadOnlyException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:id, "readOnly2").append("Some Text") }
117
- assert_raises(ObjectDisabledException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "disabled").append("Some Text") }
118
- assert_raises(UnknownObjectException , "ObjectReadOnlyException was supposed to be thrown" ) { $ie.text_field(:name, "missing_field").append("Some Text") }
119
-
120
- $ie.text_field(:name, "text1").set("watir IE Controller")
121
- assert_equal( "watir IE Controller" , $ie.text_field(:name, "text1").getContents )
122
-
123
- # may need this to see that it really happened
124
- #puts "press return to continue"
125
- #gets
126
- end
127
-
128
- def test_text_field_properties
129
-
130
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:index, 199).value}
131
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:index, 199).name }
132
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:index, 199).id }
133
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:index, 199).disabled }
134
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ie.text_field(:index, 199).type }
135
-
136
- assert_equal( "Hello World" , $ie.text_field(:index, 1).value )
137
- assert_equal( "text" , $ie.text_field(:index, 1).type)
138
- assert_equal( "text1" , $ie.text_field(:index, 1).name )
139
- assert_equal( "" , $ie.text_field(:index, 1).id )
140
- assert_equal( false , $ie.text_field(:index, 1).disabled )
141
-
142
- assert_equal( "" , $ie.text_field(:index, 2).name )
143
- assert_equal( "text2" , $ie.text_field(:index, 2).id )
144
-
145
- assert( $ie.text_field(:index, 3).disabled )
146
-
147
- assert_equal( "This used to test :afterText" , $ie.text_field(:name, "aftertest" ).title )
148
- assert_equal( "" , $ie.text_field(:index, 1 ).title )
149
-
150
-
151
- end
152
-
153
- def test_text_field_iterators
154
-
155
- assert_equal( 12 , $ie.text_fields.length )
156
-
157
- # watir is 1 based, so this is the first text field
158
- assert_equal( "Hello World" , $ie.text_fields[1].value )
159
- assert_equal( "text1" , $ie.text_fields[1].name )
160
-
161
- assert_equal( "password" , $ie.text_fields[ $ie.text_fields.length ].type)
162
-
163
-
164
- index = 1
165
- $ie.text_fields.each do |t|
166
- assert_equal( $ie.text_field(:index, index).value, t.value )
167
- assert_equal( $ie.text_field(:index, index).id, t.id )
168
- assert_equal( $ie.text_field(:index, index).name, t.name )
169
- index +=1
170
- end
171
- assert_equal( index-1, $ie.text_fields.length)
172
-
173
- end
174
-
175
- def test_JS_Events
176
- $ie.text_field(:name , 'events_tester').set('p')
177
-
178
- # the following line has an extra keypress at the begining, as we mimic the delete key being pressed
179
- assert_equal( "keypresskeydownkeypresskeyup" , $ie.text_field(:name , 'events_text').value.gsub("\r\n" , "") )
180
- $ie.button(:value , "Clear Events Box").click
181
- $ie.text_field(:name , 'events_tester').set('ab')
182
-
183
- # the following line has an extra keypress at the begining, as we mimic the delete key being pressed
184
- assert_equal( "keypresskeydownkeypresskeyupkeydownkeypresskeyup" , $ie.text_field(:name , 'events_text').value.gsub("\r\n" , "") )
185
-
186
- end
187
-
188
- def test_password
189
-
190
- $ie.text_field(:name , "password1").set("secret")
191
- assert( 'secret' , $ie.text_field(:name , "password1").value )
192
-
193
- $ie.text_field(:id , "password1").set("top_secret")
194
- assert( 'top_secret' , $ie.text_field(:id, "password1").value )
195
- end
196
-
197
- def test_labels_iterator
198
-
199
- assert_equal(3, $ie.labels.length)
200
- assert_equal('Label For this Field' , $ie.labels[1].innerText.strip )
201
- assert_equal('Password With ID ( the text here is a label for it )' , $ie.labels[3].innerText )
202
-
203
- count=0
204
- $ie.labels.each do |l|
205
- count +=1
206
- end
207
- assert_equal(count, $ie.labels.length)
208
-
209
-
210
- end
211
-
212
- def test_label_properties
213
- assert_raises(UnknownObjectException ) { $ie.label(:index,20).innerText }
214
- assert_raises(UnknownObjectException ) { $ie.label(:index,20).for }
215
- assert_raises(UnknownObjectException ) { $ie.label(:index,20).name }
216
- assert_raises(UnknownObjectException ) { $ie.label(:index,20).type }
217
- assert_raises(UnknownObjectException ) { $ie.label(:index,20).id }
218
-
219
- assert_false( $ie.label(:index,10).exists? )
220
- assert_false( $ie.label(:id,'missing').exists? )
221
- assert( $ie.label(:index,1).exists? )
222
-
223
-
224
- assert_equal( "" , $ie.label(:index,1).id )
225
- assert_false( $ie.label(:index,1).disabled )
226
- assert( $ie.label(:index,1).enabled?)
227
-
228
-
229
- assert_equal( "label2" , $ie.label(:index,2).id )
230
- assert_equal( "Label" , $ie.label(:index,2).type )
231
-
232
- assert_equal( "Password With ID ( the text here is a label for it )" , $ie.label(:index,3).innerText)
233
- assert_equal( "password1" , $ie.label(:index,3).for)
234
- end
18
+ assert($ie.text_field(:id, "text2").exists?)
19
+ assert(!$ie.text_field(:id, "alsomissing").exists?)
20
+
21
+ assert($ie.text_field(:beforeText, "This Text After").exists? )
22
+ assert($ie.text_field(:afterText, "This Text Before").exists? )
23
+
24
+ assert($ie.text_field(:beforeText, /after/i).exists? )
25
+ assert($ie.text_field(:afterText, /before/i).exists? )
26
+ end
27
+
28
+ def test_text_field_dragContentsTo
29
+ $ie.text_field(:name, "text1").dragContentsTo(:id, "text2")
30
+ assert_equal($ie.text_field(:name, "text1").getContents, "")
31
+ assert_equal($ie.text_field(:id, "text2").getContents, "goodbye allHello World")
32
+ end
33
+
34
+ def test_text_field_verify_contains
35
+ assert($ie.text_field(:name, "text1").verify_contains("Hello World"))
36
+ assert($ie.text_field(:name, "text1").verify_contains(/Hello\sW/))
37
+ assert(!$ie.text_field(:name, "text1").verify_contains("Ruby"))
38
+ assert(!$ie.text_field(:name, "text1").verify_contains(/R/))
39
+ assert_raises(UnknownObjectException) { $ie.text_field(:name, "NoName").verify_contains("No field to get a value of") }
40
+
41
+ assert($ie.text_field(:id, "text2").verify_contains("goodbye all") )
42
+ assert_raises(UnknownObjectException) { $ie.text_field(:id, "noID").verify_contains("No field to get a value of") }
43
+ end
44
+
45
+ def test_text_field_enabled
46
+ assert(!$ie.text_field(:name, "disabled").enabled? )
47
+ assert($ie.text_field(:name, "text1").enabled? )
48
+ assert($ie.text_field(:id, "text2").enabled? )
49
+ end
50
+
51
+ def test_text_field_readonly
52
+ assert(!$ie.text_field(:name, "disabled").readonly? )
53
+ assert($ie.text_field(:name, "readOnly").readonly? )
54
+ assert($ie.text_field(:id, "readOnly2").readonly? )
55
+ end
56
+
57
+ def test_text_field_get_contents
58
+ assert_raises(UnknownObjectException) { $ie.text_field(:name, "missing_field").append("Some Text") }
59
+ assert_equal("Hello World", $ie.text_field(:name, "text1").getContents)
60
+ end
61
+
62
+ def test_text_field_to_s
63
+ expected = [
64
+ build_to_s_regex("type", "text"),
65
+ build_to_s_regex("id", ""),
66
+ build_to_s_regex("name", "text1"),
67
+ build_to_s_regex("value", "Hello World"),
68
+ build_to_s_regex("disabled", "false"),
69
+ build_to_s_regex("length", "20"),
70
+ build_to_s_regex("max length", "20"),
71
+ build_to_s_regex("read only", "false")
72
+ ]
73
+ items = $ie.text_field(:index, 1).to_s.split(/\n/)
74
+ expected.each_with_index{|regex, x| assert_match(regex, items[x]) }
75
+ expected[1] = build_to_s_regex("id", "text2")
76
+ expected[2] = build_to_s_regex("name", "")
77
+ expected[3] = build_to_s_regex("value", "goodbye all")
78
+ expected[6] = build_to_s_regex("max length", "2147483647")
79
+
80
+ items = $ie.text_field(:index, 2).to_s.split(/\n/)
81
+ expected.each_with_index{|regex, x| assert_match(regex, items[x]) }
82
+ assert_raises(UnknownObjectException) { $ie.text_field(:index, 999).to_s }
83
+ end
84
+
85
+ def build_to_s_regex(lhs, rhs)
86
+ Regexp.new("^#{lhs}: +#{rhs}$")
87
+ end
88
+
89
+ def test_text_field_append
90
+ assert_raises(ObjectReadOnlyException) { $ie.text_field(:id, "readOnly2").append("Some Text") }
91
+ assert_raises(ObjectDisabledException) { $ie.text_field(:name, "disabled").append("Some Text") }
92
+ assert_raises(UnknownObjectException) { $ie.text_field(:name, "missing_field").append("Some Text") }
93
+
94
+ $ie.text_field(:name, "text1").append(" Some Text")
95
+ assert_equal("Hello World Some Text", $ie.text_field(:name, "text1").getContents)
96
+ end
97
+
98
+ def test_text_field_clear
99
+ $ie.text_field(:name, "text1").clear
100
+ assert_equal("", $ie.text_field(:name, "text1").getContents)
101
+ end
102
+
103
+ def test_text_field_set
104
+ $ie.text_field(:name, "text1").set("watir IE Controller")
105
+ assert_equal("watir IE Controller" , $ie.text_field(:name, "text1").getContents)
106
+ # adding for issue: http://jira.openqa.org/browse/WTR-89
107
+ $ie.text_field(:name, /reGex/i).set("pass")
108
+ assert_equal("pass", $ie.text_field(:name, /REgEx/i).getContents)
109
+ end
110
+
111
+ def test_text_field_properties
112
+ assert_raises(UnknownObjectException) { $ie.text_field(:index, 199).value }
113
+ assert_raises(UnknownObjectException) { $ie.text_field(:index, 199).name }
114
+ assert_raises(UnknownObjectException) { $ie.text_field(:index, 199).id }
115
+ assert_raises(UnknownObjectException) { $ie.text_field(:index, 199).disabled }
116
+ assert_raises(UnknownObjectException) { $ie.text_field(:index, 199).type }
117
+
118
+ assert_equal("Hello World" , $ie.text_field(:index, 1).value)
119
+ assert_equal("text" , $ie.text_field(:index, 1).type)
120
+ assert_equal("text1" , $ie.text_field(:index, 1).name)
121
+ assert_equal("" , $ie.text_field(:index, 1).id)
122
+ assert_equal(false , $ie.text_field(:index, 1).disabled)
123
+
124
+ assert_equal("" , $ie.text_field(:index, 2).name)
125
+ assert_equal("text2" , $ie.text_field(:index, 2).id)
126
+
127
+ assert($ie.text_field(:index, 4).disabled)
128
+
129
+ assert_equal("This used to test :afterText", $ie.text_field(:name, "aftertest").title)
130
+ assert_equal("", $ie.text_field(:index, 1).title)
131
+ # adding for issue: http://jira.openqa.org/browse/WTR-89
132
+ assert_equal("RegEx test", $ie.text_field(:name, /REgEx/i).value)
133
+ end
134
+
135
+ def test_text_field_iterators
136
+ assert_equal(13, $ie.text_fields.length)
137
+
138
+ # watir is 1 based, so this is the first text field
139
+ assert_equal("Hello World" , $ie.text_fields[1].value)
140
+ assert_equal("text1" , $ie.text_fields[1].name)
141
+ assert_equal("password" , $ie.text_fields[$ie.text_fields.length].type)
142
+
143
+ index = 1
144
+ $ie.text_fields.each do |t|
145
+ assert_equal($ie.text_field(:index, index).value, t.value)
146
+ assert_equal($ie.text_field(:index, index).id, t.id)
147
+ assert_equal($ie.text_field(:index, index).name, t.name)
148
+ index += 1
149
+ end
150
+ assert_equal(index - 1, $ie.text_fields.length)
151
+ end
152
+
153
+ def test_JS_Events
154
+ $ie.text_field(:name, 'events_tester').set('p')
155
+
156
+ # the following line has an extra keypress at the begining, as we mimic the delete key being pressed
157
+ assert_equal( "keypresskeydownkeypresskeyup" , $ie.text_field(:name , 'events_text').value.gsub("\r\n" , "") )
158
+ $ie.button(:value , "Clear Events Box").click
159
+ $ie.text_field(:name , 'events_tester').set('ab')
160
+
161
+ # the following line has an extra keypress at the begining, as we mimic the delete key being pressed
162
+ assert_equal( "keypresskeydownkeypresskeyupkeydownkeypresskeyup" , $ie.text_field(:name , 'events_text').value.gsub("\r\n" , "") )
163
+ end
164
+
165
+ def test_password
166
+ $ie.text_field(:name , "password1").set("secret")
167
+ assert( 'secret' , $ie.text_field(:name , "password1").value )
168
+
169
+ $ie.text_field(:id , "password1").set("top_secret")
170
+ assert( 'top_secret' , $ie.text_field(:id, "password1").value )
171
+ end
172
+
173
+ def test_labels_iterator
174
+ assert_equal(3, $ie.labels.length)
175
+ assert_equal('Label For this Field' , $ie.labels[1].innerText.strip )
176
+ assert_equal('Password With ID ( the text here is a label for it )' , $ie.labels[3].innerText )
177
+
178
+ count=0
179
+ $ie.labels.each do |l|
180
+ count +=1
181
+ end
182
+ assert_equal(count, $ie.labels.length)
183
+ end
184
+
185
+ def test_label_properties
186
+ assert_raises(UnknownObjectException) { $ie.label(:index,20).innerText }
187
+ assert_raises(UnknownObjectException) { $ie.label(:index,20).for }
188
+ assert_raises(UnknownObjectException) { $ie.label(:index,20).name }
189
+ assert_raises(UnknownObjectException) { $ie.label(:index,20).type }
190
+ assert_raises(UnknownObjectException) { $ie.label(:index,20).id }
191
+
192
+ assert(!$ie.label(:index,10).exists?)
193
+ assert(!$ie.label(:id,'missing').exists?)
194
+ assert($ie.label(:index,1).exists?)
195
+
196
+ assert_equal("", $ie.label(:index,1).id)
197
+ assert(! $ie.label(:index,1).disabled?)
198
+ assert( $ie.label(:index,1).enabled?)
199
+
200
+ assert_equal("label2", $ie.label(:index,2).id )
201
+
202
+ assert_equal("Password With ID ( the text here is a label for it )" , $ie.label(:index,3).innerText)
203
+ assert_equal("password1", $ie.label(:index,3).for)
204
+ end
235
205
 
206
+ def test_max_length_is_not_exceeded
207
+ $ie.text_field(:name , 'text1').set("abcdefghijklmnopqrstuv")
208
+ assert_equal("abcdefghijklmnopqrst", $ie.text_field(:name , 'text1').value )
209
+ end
236
210
 
237
-
211
+ def test_max_length
212
+ assert_equal(20, $ie.text_field(:name , 'text1').maxLength )
238
213
 
214
+ end
239
215
  end