firewatir 1.6.5 → 1.6.6.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/CHANGES +461 -0
  2. data/LICENSE +31 -31
  3. data/README.rdoc +112 -0
  4. data/VERSION +1 -0
  5. data/lib/firewatir.rb +41 -40
  6. data/lib/firewatir/container.rb +491 -491
  7. data/lib/firewatir/document.rb +239 -239
  8. data/lib/firewatir/element.rb +1364 -1364
  9. data/lib/firewatir/element_collections.rb +314 -314
  10. data/lib/firewatir/elements/button.rb +15 -15
  11. data/lib/firewatir/elements/file_field.rb +29 -29
  12. data/lib/firewatir/elements/form.rb +40 -40
  13. data/lib/firewatir/elements/frame.rb +55 -55
  14. data/lib/firewatir/elements/hidden.rb +56 -56
  15. data/lib/firewatir/elements/image.rb +139 -139
  16. data/lib/firewatir/elements/input_element.rb +44 -44
  17. data/lib/firewatir/elements/link.rb +76 -76
  18. data/lib/firewatir/elements/non_control_element.rb +53 -53
  19. data/lib/firewatir/elements/non_control_elements.rb +108 -108
  20. data/lib/firewatir/elements/not_used.rb +278 -278
  21. data/lib/firewatir/elements/option.rb +130 -130
  22. data/lib/firewatir/elements/radio_check_common.rb +163 -163
  23. data/lib/firewatir/elements/select_list.rb +188 -188
  24. data/lib/firewatir/elements/table.rb +218 -218
  25. data/lib/firewatir/elements/table_cell.rb +54 -54
  26. data/lib/firewatir/elements/table_row.rb +100 -100
  27. data/lib/firewatir/elements/text_field.rb +218 -218
  28. data/lib/firewatir/exceptions.rb +10 -10
  29. data/lib/firewatir/firefox.rb +984 -1040
  30. data/lib/firewatir/jssh_socket.rb +100 -100
  31. data/lib/firewatir/winClicker.rb +122 -122
  32. data/lib/firewatir/x11.rb +192 -192
  33. data/rakefile.rb +15 -0
  34. data/unittests/attach_to_new_window_test.rb +49 -49
  35. data/unittests/bug_fixes_test.rb +195 -195
  36. data/unittests/buttons_xpath_test.rb +88 -88
  37. data/unittests/checkbox_test.rb +158 -158
  38. data/unittests/checkbox_xpath_test.rb +107 -107
  39. data/unittests/div_test.rb +275 -275
  40. data/unittests/ff_test.rb +47 -0
  41. data/unittests/filefield_test.rb +49 -49
  42. data/unittests/filefield_xpath_test.rb +35 -35
  43. data/unittests/form_test.rb +296 -296
  44. data/unittests/frame_test.rb +159 -159
  45. data/unittests/hidden_test.rb +85 -85
  46. data/unittests/hidden_xpath_test.rb +72 -72
  47. data/unittests/html/JavascriptClick.html +42 -42
  48. data/unittests/html/blankpage.html +11 -11
  49. data/unittests/html/buttons1.html +61 -61
  50. data/unittests/html/checkboxes1.html +70 -70
  51. data/unittests/html/complex_table.html +36 -36
  52. data/unittests/html/cssTest.html +42 -42
  53. data/unittests/html/div.html +72 -72
  54. data/unittests/html/div_xml.html +20 -20
  55. data/unittests/html/fileupload.html +45 -45
  56. data/unittests/html/formTest1.html +38 -38
  57. data/unittests/html/forms2.html +45 -45
  58. data/unittests/html/forms3.html +132 -132
  59. data/unittests/html/forms4.html +27 -27
  60. data/unittests/html/frame_buttons.html +3 -3
  61. data/unittests/html/frame_links.html +3 -3
  62. data/unittests/html/frame_multi.html +4 -4
  63. data/unittests/html/iframeTest.html +14 -14
  64. data/unittests/html/iframeTest1.html +13 -13
  65. data/unittests/html/iframeTest2.html +5 -5
  66. data/unittests/html/images1.html +66 -66
  67. data/unittests/html/javascriptevents.html +35 -35
  68. data/unittests/html/link_pass.html +10 -10
  69. data/unittests/html/links1.html +42 -42
  70. data/unittests/html/links2.html +10 -10
  71. data/unittests/html/modal_dialog.html +8 -8
  72. data/unittests/html/modal_dialog_launcher.html +11 -11
  73. data/unittests/html/nestedFrames.html +6 -6
  74. data/unittests/html/new_browser.html +17 -17
  75. data/unittests/html/new_browser_popup.html +7 -7
  76. data/unittests/html/pass.html +9 -9
  77. data/unittests/html/popups1.html +60 -60
  78. data/unittests/html/pre.html +27 -27
  79. data/unittests/html/radioButtons1.html +70 -70
  80. data/unittests/html/redirect.html +10 -10
  81. data/unittests/html/redirect1.html +8 -8
  82. data/unittests/html/redirect2.html +8 -8
  83. data/unittests/html/redirect3.html +8 -8
  84. data/unittests/html/select_tealeaf.html +54 -54
  85. data/unittests/html/selectboxes1.html +55 -55
  86. data/unittests/html/simple_table.html +26 -26
  87. data/unittests/html/simple_table_buttons.html +104 -104
  88. data/unittests/html/simple_table_columns.html +74 -74
  89. data/unittests/html/table1.html +165 -165
  90. data/unittests/html/tableCell_using_xpath.html +19 -19
  91. data/unittests/html/textarea.html +30 -30
  92. data/unittests/html/textfields1.html +62 -62
  93. data/unittests/html/textsearch.html +44 -44
  94. data/unittests/images_test.rb +198 -198
  95. data/unittests/images_xpath_test.rb +118 -118
  96. data/unittests/javascript_test.rb +75 -75
  97. data/unittests/links_test.rb +231 -231
  98. data/unittests/links_xpath_test.rb +79 -79
  99. data/unittests/mozilla_all_tests.rb +7 -7
  100. data/unittests/pre_test.rb +75 -75
  101. data/unittests/radios_test.rb +166 -166
  102. data/unittests/radios_xpath_test.rb +101 -101
  103. data/unittests/redirect_test.rb +41 -41
  104. data/unittests/selectbox_test.rb +142 -142
  105. data/unittests/selectbox_xpath_test.rb +129 -129
  106. data/unittests/setup.rb +29 -29
  107. data/unittests/table_test.rb +385 -385
  108. data/unittests/table_xpath_test.rb +185 -185
  109. data/unittests/textfields_test.rb +234 -234
  110. data/unittests/textfields_xpath_test.rb +113 -113
  111. metadata +51 -19
  112. data/lib/firewatir/version.rb +0 -5
@@ -1,129 +1,129 @@
1
- # feature tests for Select Boxes
2
- # revision: $Revision: 1.0 $
3
-
4
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
- require 'unittests/setup'
6
-
7
- class TC_Selectbox_XPath < Test::Unit::TestCase
8
-
9
-
10
- def setup()
11
- goto_page("selectboxes1.html")
12
- end
13
-
14
- def test_textBox_Exists
15
- assert(browser.select_list(:xpath, "//select[@name='sel1']").exists?)
16
- assert_false(browser.select_list(:xpath, "//select[@name='missing']").exists?)
17
- assert_false(browser.select_list(:xpath, "//select[@id='missing']").exists?)
18
- end
19
-
20
- tag_method :test_element_by_xpath_class, :fails_on_ie
21
- def test_element_by_xpath_class
22
- element = browser.element_by_xpath("//select[@name='sel1']")
23
- assert_class(element, 'SelectList')
24
- # FIXME got HTMLAnchorElement, should've gotten HTMLSelectElement
25
- # TODO: If element is not present, this should return null
26
- #element = browser.element_by_xpath("//select[@name='missing']")
27
- #assert(element.instance_of?(SelectList),"element class should be #{SelectList}; got #{element.class}")
28
- # FIXME got HTMLAnchorElement, should've gotten HTMLSelectElement
29
- # TODO: If element is not present, this should return null
30
- #element = browser.element_by_xpath("//select[@id='missing']")
31
- #assert(element.instance_of?(SelectList),"element class should be #{SelectList}; got #{element.class}")
32
- end
33
-
34
- def test_select_list_enabled
35
- assert(browser.select_list(:xpath, "//select[@name='sel1']").enabled?)
36
- assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").enabled? }
37
- end
38
-
39
- def test_select_list_getAllContents
40
- assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getAllContents }
41
- assert_equal( ["Option 1" ,"Option 2" , "Option 3" , "Option 4"] ,
42
- browser.select_list(:xpath, "//select[@name='sel1']").getAllContents)
43
- end
44
-
45
- def test_select_list_getSelectedItems
46
- assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getSelectedItems }
47
- assert_equal( ["Option 3" ] ,
48
- browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
49
- assert_equal( ["Option 3" , "Option 6" ] ,
50
- browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
51
- end
52
-
53
- tag_method :test_clearSelection, :fails_on_ie
54
- def test_clearSelection
55
- assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").clearSelection }
56
- browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
57
-
58
- # the box sel1 has no ability to have a de-selected item
59
- # By default Option 1 will be selected
60
- assert_equal( ["Option 1" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
61
-
62
- browser.select_list(:xpath, "//select[@name='sel2']").clearSelection
63
- assert_equal( [ ] , browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
64
- end
65
-
66
- def test_select_list_select
67
- assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getSelectedItems }
68
- assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select("missing item") }
69
- assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select(/missing/) }
70
-
71
- # the select method keeps any currently selected items - use the clear selectcion method first
72
- browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
73
- browser.select_list(:xpath, "//select[@name='sel1']").select("Option 1")
74
- assert_equal( ["Option 1" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
75
-
76
- browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
77
- browser.select_list(:xpath, "//select[@name='sel1']").select(/2/)
78
- assert_equal( ["Option 2" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
79
-
80
- browser.select_list(:xpath, "//select[@name='sel2']").clearSelection
81
- browser.select_list(:xpath, "//select[@name='sel2']").select( /2/ )
82
- browser.select_list(:xpath, "//select[@name='sel2']").select( /4/ )
83
- assert_equal( ["Option 2" , "Option 4" ] ,
84
- browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
85
-
86
- # these are to test the onchange event
87
- # the event shouldnt get fired, as this is the selected item
88
- browser.select_list(:xpath, "//select[@name='sel3']").select( /3/ )
89
- assert_false(browser.text.include?("Pass") )
90
- end
91
-
92
- def test_select_list_select2
93
- # the event should get fired
94
- browser.select_list(:xpath, "//select[@name='sel3']").select( /2/ )
95
- assert(browser.text.include?("PASS") )
96
- end
97
-
98
- def test_select_list_select_using_value
99
- assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getSelectedItems }
100
- assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select_value("missing item") }
101
- assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select_value(/missing/) }
102
-
103
- # the select method keeps any currently selected items - use the clear selectcion method first
104
- browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
105
- browser.select_list(:xpath, "//select[@name='sel1']").select_value("o1")
106
- assert_equal( ["Option 1" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
107
-
108
- browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
109
- browser.select_list(:xpath, "//select[@name='sel1']").select_value(/2/)
110
- assert_equal( ["Option 2" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
111
-
112
- browser.select_list(:xpath, "//select[@name='sel2']").clearSelection
113
- browser.select_list(:xpath, "//select[@name='sel2']").select( /2/ )
114
- browser.select_list(:xpath, "//select[@name='sel2']").select( /4/ )
115
- assert_equal( ["Option 2" , "Option 4" ] , browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
116
-
117
- # these are to test the onchange event
118
- # the event shouldnt get fired, as this is the selected item
119
- browser.select_list(:xpath, "//select[@name='sel3']").select_value( /3/ )
120
- assert_false(browser.text.include?("Pass") )
121
- end
122
-
123
- def test_select_list_select_using_value2
124
- # the event should get fired
125
- browser.select_list(:xpath, "//select[@name='sel3']").select_value( /2/ )
126
- assert(browser.text.include?("PASS") )
127
- end
128
-
129
- end
1
+ # feature tests for Select Boxes
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
+ require 'unittests/setup'
6
+
7
+ class TC_Selectbox_XPath < Test::Unit::TestCase
8
+
9
+
10
+ def setup()
11
+ goto_page("selectboxes1.html")
12
+ end
13
+
14
+ def test_textBox_Exists
15
+ assert(browser.select_list(:xpath, "//select[@name='sel1']").exists?)
16
+ assert_false(browser.select_list(:xpath, "//select[@name='missing']").exists?)
17
+ assert_false(browser.select_list(:xpath, "//select[@id='missing']").exists?)
18
+ end
19
+
20
+ tag_method :test_element_by_xpath_class, :fails_on_ie
21
+ def test_element_by_xpath_class
22
+ element = browser.element_by_xpath("//select[@name='sel1']")
23
+ assert_class(element, 'SelectList')
24
+ # FIXME got HTMLAnchorElement, should've gotten HTMLSelectElement
25
+ # TODO: If element is not present, this should return null
26
+ #element = browser.element_by_xpath("//select[@name='missing']")
27
+ #assert(element.instance_of?(SelectList),"element class should be #{SelectList}; got #{element.class}")
28
+ # FIXME got HTMLAnchorElement, should've gotten HTMLSelectElement
29
+ # TODO: If element is not present, this should return null
30
+ #element = browser.element_by_xpath("//select[@id='missing']")
31
+ #assert(element.instance_of?(SelectList),"element class should be #{SelectList}; got #{element.class}")
32
+ end
33
+
34
+ def test_select_list_enabled
35
+ assert(browser.select_list(:xpath, "//select[@name='sel1']").enabled?)
36
+ assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").enabled? }
37
+ end
38
+
39
+ def test_select_list_getAllContents
40
+ assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getAllContents }
41
+ assert_equal( ["Option 1" ,"Option 2" , "Option 3" , "Option 4"] ,
42
+ browser.select_list(:xpath, "//select[@name='sel1']").getAllContents)
43
+ end
44
+
45
+ def test_select_list_getSelectedItems
46
+ assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getSelectedItems }
47
+ assert_equal( ["Option 3" ] ,
48
+ browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
49
+ assert_equal( ["Option 3" , "Option 6" ] ,
50
+ browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
51
+ end
52
+
53
+ tag_method :test_clearSelection, :fails_on_ie
54
+ def test_clearSelection
55
+ assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").clearSelection }
56
+ browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
57
+
58
+ # the box sel1 has no ability to have a de-selected item
59
+ # By default Option 1 will be selected
60
+ assert_equal( ["Option 1" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
61
+
62
+ browser.select_list(:xpath, "//select[@name='sel2']").clearSelection
63
+ assert_equal( [ ] , browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
64
+ end
65
+
66
+ def test_select_list_select
67
+ assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getSelectedItems }
68
+ assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select("missing item") }
69
+ assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select(/missing/) }
70
+
71
+ # the select method keeps any currently selected items - use the clear selectcion method first
72
+ browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
73
+ browser.select_list(:xpath, "//select[@name='sel1']").select("Option 1")
74
+ assert_equal( ["Option 1" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
75
+
76
+ browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
77
+ browser.select_list(:xpath, "//select[@name='sel1']").select(/2/)
78
+ assert_equal( ["Option 2" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
79
+
80
+ browser.select_list(:xpath, "//select[@name='sel2']").clearSelection
81
+ browser.select_list(:xpath, "//select[@name='sel2']").select( /2/ )
82
+ browser.select_list(:xpath, "//select[@name='sel2']").select( /4/ )
83
+ assert_equal( ["Option 2" , "Option 4" ] ,
84
+ browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
85
+
86
+ # these are to test the onchange event
87
+ # the event shouldnt get fired, as this is the selected item
88
+ browser.select_list(:xpath, "//select[@name='sel3']").select( /3/ )
89
+ assert_false(browser.text.include?("Pass") )
90
+ end
91
+
92
+ def test_select_list_select2
93
+ # the event should get fired
94
+ browser.select_list(:xpath, "//select[@name='sel3']").select( /2/ )
95
+ assert(browser.text.include?("PASS") )
96
+ end
97
+
98
+ def test_select_list_select_using_value
99
+ assert_raises(UnknownObjectException) { browser.select_list(:xpath, "//select[@name='NoName']").getSelectedItems }
100
+ assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select_value("missing item") }
101
+ assert_raises(NoValueFoundException) { browser.select_list(:xpath, "//select[@name='sel1']").select_value(/missing/) }
102
+
103
+ # the select method keeps any currently selected items - use the clear selectcion method first
104
+ browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
105
+ browser.select_list(:xpath, "//select[@name='sel1']").select_value("o1")
106
+ assert_equal( ["Option 1" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
107
+
108
+ browser.select_list(:xpath, "//select[@name='sel1']").clearSelection
109
+ browser.select_list(:xpath, "//select[@name='sel1']").select_value(/2/)
110
+ assert_equal( ["Option 2" ] , browser.select_list(:xpath, "//select[@name='sel1']").getSelectedItems)
111
+
112
+ browser.select_list(:xpath, "//select[@name='sel2']").clearSelection
113
+ browser.select_list(:xpath, "//select[@name='sel2']").select( /2/ )
114
+ browser.select_list(:xpath, "//select[@name='sel2']").select( /4/ )
115
+ assert_equal( ["Option 2" , "Option 4" ] , browser.select_list(:xpath, "//select[@name='sel2']").getSelectedItems)
116
+
117
+ # these are to test the onchange event
118
+ # the event shouldnt get fired, as this is the selected item
119
+ browser.select_list(:xpath, "//select[@name='sel3']").select_value( /3/ )
120
+ assert_false(browser.text.include?("Pass") )
121
+ end
122
+
123
+ def test_select_list_select_using_value2
124
+ # the event should get fired
125
+ browser.select_list(:xpath, "//select[@name='sel3']").select_value( /2/ )
126
+ assert(browser.text.include?("PASS") )
127
+ end
128
+
129
+ end
data/unittests/setup.rb CHANGED
@@ -1,29 +1,29 @@
1
- $SETUP_LOADED = true
2
-
3
- $myDir = File.expand_path(File.dirname(__FILE__))
4
-
5
- topdir = File.join(File.dirname(__FILE__), '..')
6
- $firewatir_dev_lib = File.join(topdir, 'lib')
7
- $watir_dev_lib = File.join(topdir, '..', 'watir', 'lib')
8
- libs = []
9
- libs << File.join(topdir, '..', 'commonwatir', 'lib')
10
- libs << File.join(topdir, '..', 'commonwatir') # for the unit tests
11
- libs.each { |lib| $LOAD_PATH.unshift File.expand_path(lib) }
12
-
13
- require 'watir'
14
- Watir::Browser.default = 'firefox'
15
- require 'unittests/setup/lib'
16
- module Watir::UnitTest
17
- alias :uses_page :goto_page
18
- end
19
-
20
- require 'unittests/setup/testUnitAddons'
21
-
22
- commondir = File.join(topdir, '..', 'commonwatir')
23
- $all_tests = []
24
- Dir.chdir topdir do
25
- $all_tests += Dir["unittests/*_test.rb"]
26
- end
27
- Dir.chdir commondir do
28
- $all_tests += Dir["unittests/*_test.rb"]
29
- end
1
+ $SETUP_LOADED = true
2
+
3
+ $myDir = File.expand_path(File.dirname(__FILE__))
4
+
5
+ topdir = File.join(File.dirname(__FILE__), '..')
6
+ $firewatir_dev_lib = File.join(topdir, 'lib')
7
+ $watir_dev_lib = File.join(topdir, '..', 'watir', 'lib')
8
+ libs = []
9
+ libs << File.join(topdir, '..', 'commonwatir', 'lib')
10
+ libs << File.join(topdir, '..', 'commonwatir') # for the unit tests
11
+ libs.each { |lib| $LOAD_PATH.unshift File.expand_path(lib) }
12
+
13
+ require 'watir'
14
+ Watir::Browser.default = 'firefox'
15
+ require 'unittests/setup/lib'
16
+ module Watir::UnitTest
17
+ alias :uses_page :goto_page
18
+ end
19
+
20
+ require 'unittests/setup/testUnitAddons'
21
+
22
+ commondir = File.join(topdir, '..', 'commonwatir')
23
+ $all_tests = []
24
+ Dir.chdir topdir do
25
+ $all_tests += Dir["unittests/*_test.rb"]
26
+ end
27
+ Dir.chdir commondir do
28
+ $all_tests += Dir["unittests/*_test.rb"]
29
+ end
@@ -1,385 +1,385 @@
1
- # feature tests for Tables
2
- # revision: $Revision: 1.0 $
3
-
4
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
- require 'unittests/setup'
6
-
7
- class TC_Tables < Test::Unit::TestCase
8
-
9
-
10
- def setup
11
- goto_page("table1.html")
12
- end
13
-
14
- def test_Table_Exists
15
- assert_false(browser.table(:id, 'missingTable').exists?)
16
- assert_false(browser.table(:index, 33).exists?)
17
-
18
- assert(browser.table(:id, 't1').exists?)
19
- assert(browser.table(:id, /t/).exists?)
20
- assert_false(browser.table(:id, /missing_table/).exists?)
21
-
22
- assert(browser.table(:index, 1).exists?)
23
- assert(browser.table(:index, 2).exists?)
24
- end
25
-
26
- tag_method :test_rows, :fails_on_ie
27
- def test_rows
28
- assert_raises(UnknownObjectException ){ browser.table(:id, 'missingTable').row_count }
29
- assert_raises(UnknownObjectException ){ browser.table(:index, 66).row_count }
30
- assert_raises(UnknownObjectException){ browser.table(:bad_attribute, 99).row_count }
31
-
32
- assert_equal(2, browser.table(:index, 1).row_count)
33
- assert_equal(2, browser.table(:index, 1).rows.length)
34
-
35
- assert_equal(5, browser.table(:id, 't1').row_count) # 4 rows and a header
36
- assert_equal(5, browser.table(:index, 2).row_count) # same table as above, just accessed by index
37
- assert_equal(5, browser.table(:id, 't1').rows.length)
38
-
39
- # test the each iterator on rows - ie, go through each cell
40
- row = browser.table(:index, 2)[2]
41
- count = 1
42
- row.each do |cell|
43
- if count == 1
44
- assert_equal('Row 1 Col1', cell.to_s.strip)
45
- elsif count==2
46
- assert_equal('Row 1 Col2', cell.to_s.strip)
47
- end
48
- count += 1
49
- end
50
- assert_equal(2, count -1)
51
- assert_equal(2, browser.table(:index, 2)[2].column_count)
52
- end
53
-
54
- def test_dynamic_tables
55
- t = browser.table(:id, 't1')
56
- assert_equal(5, t.row_count)
57
-
58
- browser.button(:value, 'add row').click
59
- assert_equal(6, t.row_count)
60
- end
61
-
62
- def test_columns
63
- assert_raises(UnknownObjectException ){ browser.table(:id, 'missingTable').column_count }
64
- assert_raises(UnknownObjectException ){ browser.table(:index, 77).column_count }
65
- assert_equal(2, browser.table(:index, 1).column_count)
66
- assert_equal(1, browser.table(:id, 't1').column_count) # row one has 1 cell with a colspan of 2
67
- end
68
-
69
- def test_to_a
70
- table1Expected = [ ["Row 1 Col1" , "Row 1 Col2"] ,[ "Row 2 Col1" , "Row 2 Col2"] ]
71
- assert_equal(table1Expected, browser.table(:index , 1).to_a )
72
- end
73
-
74
- def test_links_and_images_in_table
75
- table = browser.table(:id, 'pic_table')
76
- image = table[1][2].image(:index,1)
77
- assert_equal("106", image.width)
78
-
79
- link = table[2][2].link(:index,1)
80
- assert_equal("Google", link.innerText)
81
- end
82
-
83
- def test_cell_directly
84
- assert( browser.cell(:id, 'cell1').exists? )
85
- assert_false( browser.cell(:id, 'no_exist').exists? )
86
- assert_equal( "Row 1 Col1", browser.cell(:id, 'cell1').to_s.strip )
87
-
88
- # not really cell directly, but just to show another way of geting the cell
89
- assert_equal( "Row 1 Col1", browser.table(:index,1)[1][1].to_s.strip )
90
- assert_equal(2, browser.cell(:id, "cell_with_colspan").colspan)
91
- end
92
-
93
- def test_row_directly
94
- assert( browser.row(:id, 'row1').exists? )
95
- assert_false( browser.row(:id, 'no_exist').exists? )
96
-
97
- assert_equal('Row 2 Col1' , browser.row(:id, 'row1')[1].to_s.strip )
98
- end
99
-
100
- def test_row_iterator
101
- t = browser.table(:index, 1)
102
- count = 1
103
- t.each do |row|
104
- if count == 1
105
- assert("Row 1 Col1", row[1].text)
106
- assert("Row 1 Col2", row[2].text)
107
- elsif count == 2
108
- assert("Row 2 Col1", row[1].text)
109
- assert("Row 2 Col2", row[2].text)
110
- end
111
- count += 1
112
- end
113
- end
114
-
115
- def test_row_collection
116
- t = browser.table(:index,1)
117
- count = 1
118
- t.rows.each do |row|
119
- if count == 1
120
- assert("Row 1 Col1", row[1].text)
121
- assert("Row 1 Col2", row[2].text)
122
- elsif count == 2
123
- assert("Row 2 Col1", row[1].text)
124
- assert("Row 2 Col2", row[2].text)
125
- end
126
- count += 1
127
- end
128
- end
129
-
130
- #def test_table_body
131
- # assert_equal( 1, browser.table(:index,1).bodies.length )
132
- # assert_equal( 3, browser.table(:id, 'body_test' ).bodies.length )
133
- #
134
- # count = 1
135
- # browser.table(:id, 'body_test').bodies.each do |n|
136
- #
137
- # # do something better here!
138
- # n.flash # this line commented out to speed up the test
139
-
140
- # case count
141
- # when 1
142
- # compare_text = "This text is in the FRST TBODY."
143
- # when 2
144
- # compare_text = "This text is in the SECOND TBODY."
145
- # when 3
146
- # compare_text = "This text is in the THIRD TBODY."
147
- # end
148
- #
149
- # assert_equal(compare_text, n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
150
- #
151
- # count += 1
152
- # end
153
- # assert_equal( count - 1, browser.table(:id, 'body_test').bodies.length )
154
- #
155
- # assert_equal( "This text is in the THIRD TBODY." ,browser.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
156
- #
157
- # # iterate through all the rows in a table body
158
- # count = 1
159
- # browser.table(:id, 'body_test').body(:index, 2).each do | row |
160
- # # row.flash # this line commented out, to speed up the tests
161
- # if count == 1
162
- # assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
163
- # elsif count == 1 # BUG: Huh?
164
- # assert_equal('This text is also in the SECOND TBODY.', row[1].text.strip )
165
- # end
166
- # count+=1
167
- # end
168
- #end
169
-
170
- def test_table_container
171
- assert_nothing_raised { browser.table(:id, 't1').html }
172
- end
173
- end
174
-
175
- class TC_Tables_Simple < Test::Unit::TestCase
176
-
177
-
178
- def setup
179
- goto_page("simple_table.html")
180
- end
181
-
182
- def test_simple_table_access
183
- table = browser.table(:index,1)
184
-
185
- assert_equal("Row 3 Col1",table[3][1].text.strip)
186
- assert_equal("Row 1 Col1",table[1][1].text.strip)
187
- assert_equal("Row 3 Col2",table[3][2].text.strip)
188
- assert_equal(2,table.column_count)
189
- end
190
- end
191
-
192
- class TC_Tables_Buttons < Test::Unit::TestCase
193
-
194
-
195
- def setup
196
- goto_page("simple_table_buttons.html")
197
- end
198
-
199
- def test_simple_table_buttons
200
- table = browser.table(:index,1)
201
-
202
- table[1][1].button(:index,1).click
203
- assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
204
- table[2][1].button(:index,1).click
205
- assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
206
-
207
- table[1][1].button(:id,'b1').click
208
- assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
209
-
210
- assert_raises(UnknownObjectException ) { table[1][1].button(:id,'b_missing').click }
211
-
212
- table[3][1].button(:index,2).click
213
- assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
214
-
215
- table[3][1].button(:value ,"Click too").click
216
- assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
217
-
218
- browser.table(:index,1)[4][1].text_field(:index,1).set("123")
219
- assert(browser.text_field(:index,2).verify_contains("123"))
220
-
221
- # check when a cell contains 2 objects
222
-
223
- # if there were 2 different html objects in the same cell, some weird things happened ( button caption could change for example)
224
- assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
225
- browser.table(:index,1)[5][1].text_field(:index,1).click
226
- assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
227
-
228
- browser.table(:index,1)[5][1].button(:index,1).click
229
- assert_equal( '' , browser.table(:index,1)[5][1].text_field(:index,1).value )
230
- end
231
-
232
- def test_simple_table_gif
233
- table = browser.table(:index,2)
234
-
235
- assert_match( /1\.gif/ , table[1][1].image( :index,1).src )
236
- assert_match( /2\.gif/ , table[1][2].image( :index ,1).src )
237
- assert_match( /3\.gif/ , table[1][3].image( :index ,1).src )
238
-
239
- assert_match( /1\.gif/ , table[3][1].image( :index ,1).src )
240
- assert_match( /2\.gif/ , table[3][2].image( :index ,1).src )
241
- assert_match( /3\.gif/ , table[3][3].image( :index ,1).src )
242
-
243
- table = browser.table(:index,3)
244
- assert_match( /1\.gif/ , table[1][1].image( :index ,1).src )
245
- assert_match( /2\.gif/ , table[1][1].image( :index ,2).src )
246
- assert_match( /3\.gif/ , table[1][1].image( :index ,3).src )
247
-
248
- assert_match( /1\.gif/ , table[3][1].image( :index ,1).src )
249
- assert_match( /2\.gif/ , table[3][1].image( :index ,2).src )
250
- assert_match( /3\.gif/ , table[3][1].image( :index ,3).src )
251
- end
252
-
253
- def test_table_with_hidden_or_visible_rows
254
- t = browser.table(:id , 'show_hide')
255
-
256
- # expand the table
257
- t.each do |r|
258
- r[1].image(:src, /plus/).click if r[1].image(:src, /plus/).exists?
259
- end
260
-
261
- # shrink rows 1,2,3
262
- count=1
263
- t.each do |r|
264
- r[1].image(:src, /minus/).click if r[1].image(:src, /minus/).exists? and (1..3) === count
265
- count=2
266
- end
267
- end
268
-
269
- # def test_table_from_element
270
- # button = browser.button(:id, "b1")
271
- # table = Table.create_from_element(browser, button)
272
-
273
- # table[2][1].button(:index, 1).click
274
- # assert(browser.textField(:name, "confirmtext").verify_contains(/CLICK2/i))
275
- # end
276
- end
277
-
278
- class TC_Table_Columns < Test::Unit::TestCase
279
-
280
- def setup
281
- goto_page("simple_table_columns.html")
282
- end
283
-
284
- # def test_get_columnvalues_single_column
285
- # assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 1).column_values(1))
286
- # end
287
-
288
- def test_colspan
289
- assert_equal(2, browser.table(:index, 3)[2][1].colspan)
290
- assert_equal(1, browser.table(:index, 3)[1][1].colspan)
291
- assert_equal(3, browser.table(:index, 3)[4][1].colspan)
292
- end
293
-
294
- def test_get_columnvalues_multiple_column
295
- assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 2).column_values(1))
296
- assert_equal(["R1C3", "R2C3", "R3C3"], browser.table(:index, 2).column_values(3))
297
- end
298
-
299
- def test_get_columnvalues_with_colspan
300
- assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], browser.table(:index, 3).column_values(1))
301
- end
302
-
303
- def test_get_rowvalues_full_row
304
- assert_equal(["R1C1", "R1C2", "R1C3"], browser.table(:index, 3).row_values(1))
305
- end
306
-
307
- def test_get_rowvalues_with_colspan
308
- assert_equal(["R2C1", "R2C2"], browser.table(:index, 3).row_values(2))
309
- end
310
-
311
- def test_getrowvalues_with_rowspan
312
- assert_equal(["R5C1", "R5C2", "R5C3"], browser.table(:index, 3).row_values(5))
313
- assert_equal(["R6C2", "R6C3"], browser.table(:index, 3).row_values(6))
314
- end
315
- end
316
-
317
- class TC_Tables_Complex < Test::Unit::TestCase
318
-
319
- def setup
320
- goto_page("complex_table.html")
321
- end
322
-
323
- def test_complex_table_access
324
- table = browser.table(:index,1)
325
-
326
- assert_equal("subtable1 Row 1 Col1",table[1][1].table(:index,1)[1][1].text.strip)
327
- assert_equal("subtable1 Row 1 Col2",table[1][1].table(:index,1)[1][2].text.strip)
328
- assert_equal("subtable2 Row 1 Col2",table[2][1].table(:index,1)[1][2].text.strip)
329
- assert_equal("subtable2 Row 1 Col1",table[2][1].table(:index,1)[1][1].text.strip)
330
- end
331
-
332
- def test_each_itterator
333
- # for WTR-324: keep Watir::Table.each from crashing when run on nested tables
334
- table = browser.table(:index,1)
335
- assert_equal(table.row_count, 2)
336
- example_row_count = 0
337
- assert_nothing_thrown do
338
- table.each do
339
- example_row_count += 1
340
- end
341
- end
342
- assert_equal(example_row_count, 2)
343
- end
344
- end
345
-
346
- class TC_Tables_Display < Test::Unit::TestCase
347
- include CaptureIOHelper
348
-
349
- tag_method :test_showTables, :fails_on_ie
350
- def test_showTables
351
- goto_page("table1.html")
352
- actual = capture_stdout { browser.showTables }
353
- assert_equal(<<END_OF_MESSAGE, actual)
354
- There are 7 tables
355
- table: id: tblTest
356
- rows: 2
357
- columns: 2
358
- index: 1
359
- table: id: t1
360
- rows: 5
361
- columns: 1
362
- index: 2
363
- table: id: t2
364
- rows: 2
365
- columns: 2
366
- index: 3
367
- table: id:
368
- rows: 1
369
- columns: 2
370
- index: 4
371
- table: id: body_test
372
- rows: 5
373
- columns: 1
374
- index: 5
375
- table: id: pic_table
376
- rows: 2
377
- columns: 2
378
- index: 6
379
- table: id: tblTest1
380
- rows: 5
381
- columns: 1
382
- index: 7
383
- END_OF_MESSAGE
384
- end
385
- end
1
+ # feature tests for Tables
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
+ require 'unittests/setup'
6
+
7
+ class TC_Tables < Test::Unit::TestCase
8
+
9
+
10
+ def setup
11
+ goto_page("table1.html")
12
+ end
13
+
14
+ def test_Table_Exists
15
+ assert_false(browser.table(:id, 'missingTable').exists?)
16
+ assert_false(browser.table(:index, 33).exists?)
17
+
18
+ assert(browser.table(:id, 't1').exists?)
19
+ assert(browser.table(:id, /t/).exists?)
20
+ assert_false(browser.table(:id, /missing_table/).exists?)
21
+
22
+ assert(browser.table(:index, 1).exists?)
23
+ assert(browser.table(:index, 2).exists?)
24
+ end
25
+
26
+ tag_method :test_rows, :fails_on_ie
27
+ def test_rows
28
+ assert_raises(UnknownObjectException ){ browser.table(:id, 'missingTable').row_count }
29
+ assert_raises(UnknownObjectException ){ browser.table(:index, 66).row_count }
30
+ assert_raises(UnknownObjectException){ browser.table(:bad_attribute, 99).row_count }
31
+
32
+ assert_equal(2, browser.table(:index, 1).row_count)
33
+ assert_equal(2, browser.table(:index, 1).rows.length)
34
+
35
+ assert_equal(5, browser.table(:id, 't1').row_count) # 4 rows and a header
36
+ assert_equal(5, browser.table(:index, 2).row_count) # same table as above, just accessed by index
37
+ assert_equal(5, browser.table(:id, 't1').rows.length)
38
+
39
+ # test the each iterator on rows - ie, go through each cell
40
+ row = browser.table(:index, 2)[2]
41
+ count = 1
42
+ row.each do |cell|
43
+ if count == 1
44
+ assert_equal('Row 1 Col1', cell.to_s.strip)
45
+ elsif count==2
46
+ assert_equal('Row 1 Col2', cell.to_s.strip)
47
+ end
48
+ count += 1
49
+ end
50
+ assert_equal(2, count -1)
51
+ assert_equal(2, browser.table(:index, 2)[2].column_count)
52
+ end
53
+
54
+ def test_dynamic_tables
55
+ t = browser.table(:id, 't1')
56
+ assert_equal(5, t.row_count)
57
+
58
+ browser.button(:value, 'add row').click
59
+ assert_equal(6, t.row_count)
60
+ end
61
+
62
+ def test_columns
63
+ assert_raises(UnknownObjectException ){ browser.table(:id, 'missingTable').column_count }
64
+ assert_raises(UnknownObjectException ){ browser.table(:index, 77).column_count }
65
+ assert_equal(2, browser.table(:index, 1).column_count)
66
+ assert_equal(1, browser.table(:id, 't1').column_count) # row one has 1 cell with a colspan of 2
67
+ end
68
+
69
+ def test_to_a
70
+ table1Expected = [ ["Row 1 Col1" , "Row 1 Col2"] ,[ "Row 2 Col1" , "Row 2 Col2"] ]
71
+ assert_equal(table1Expected, browser.table(:index , 1).to_a )
72
+ end
73
+
74
+ def test_links_and_images_in_table
75
+ table = browser.table(:id, 'pic_table')
76
+ image = table[1][2].image(:index,1)
77
+ assert_equal("106", image.width)
78
+
79
+ link = table[2][2].link(:index,1)
80
+ assert_equal("Google", link.innerText)
81
+ end
82
+
83
+ def test_cell_directly
84
+ assert( browser.cell(:id, 'cell1').exists? )
85
+ assert_false( browser.cell(:id, 'no_exist').exists? )
86
+ assert_equal( "Row 1 Col1", browser.cell(:id, 'cell1').to_s.strip )
87
+
88
+ # not really cell directly, but just to show another way of geting the cell
89
+ assert_equal( "Row 1 Col1", browser.table(:index,1)[1][1].to_s.strip )
90
+ assert_equal(2, browser.cell(:id, "cell_with_colspan").colspan)
91
+ end
92
+
93
+ def test_row_directly
94
+ assert( browser.row(:id, 'row1').exists? )
95
+ assert_false( browser.row(:id, 'no_exist').exists? )
96
+
97
+ assert_equal('Row 2 Col1' , browser.row(:id, 'row1')[1].to_s.strip )
98
+ end
99
+
100
+ def test_row_iterator
101
+ t = browser.table(:index, 1)
102
+ count = 1
103
+ t.each do |row|
104
+ if count == 1
105
+ assert("Row 1 Col1", row[1].text)
106
+ assert("Row 1 Col2", row[2].text)
107
+ elsif count == 2
108
+ assert("Row 2 Col1", row[1].text)
109
+ assert("Row 2 Col2", row[2].text)
110
+ end
111
+ count += 1
112
+ end
113
+ end
114
+
115
+ def test_row_collection
116
+ t = browser.table(:index,1)
117
+ count = 1
118
+ t.rows.each do |row|
119
+ if count == 1
120
+ assert("Row 1 Col1", row[1].text)
121
+ assert("Row 1 Col2", row[2].text)
122
+ elsif count == 2
123
+ assert("Row 2 Col1", row[1].text)
124
+ assert("Row 2 Col2", row[2].text)
125
+ end
126
+ count += 1
127
+ end
128
+ end
129
+
130
+ #def test_table_body
131
+ # assert_equal( 1, browser.table(:index,1).bodies.length )
132
+ # assert_equal( 3, browser.table(:id, 'body_test' ).bodies.length )
133
+ #
134
+ # count = 1
135
+ # browser.table(:id, 'body_test').bodies.each do |n|
136
+ #
137
+ # # do something better here!
138
+ # n.flash # this line commented out to speed up the test
139
+
140
+ # case count
141
+ # when 1
142
+ # compare_text = "This text is in the FRST TBODY."
143
+ # when 2
144
+ # compare_text = "This text is in the SECOND TBODY."
145
+ # when 3
146
+ # compare_text = "This text is in the THIRD TBODY."
147
+ # end
148
+ #
149
+ # assert_equal(compare_text, n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
150
+ #
151
+ # count += 1
152
+ # end
153
+ # assert_equal( count - 1, browser.table(:id, 'body_test').bodies.length )
154
+ #
155
+ # assert_equal( "This text is in the THIRD TBODY." ,browser.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
156
+ #
157
+ # # iterate through all the rows in a table body
158
+ # count = 1
159
+ # browser.table(:id, 'body_test').body(:index, 2).each do | row |
160
+ # # row.flash # this line commented out, to speed up the tests
161
+ # if count == 1
162
+ # assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
163
+ # elsif count == 1 # BUG: Huh?
164
+ # assert_equal('This text is also in the SECOND TBODY.', row[1].text.strip )
165
+ # end
166
+ # count+=1
167
+ # end
168
+ #end
169
+
170
+ def test_table_container
171
+ assert_nothing_raised { browser.table(:id, 't1').html }
172
+ end
173
+ end
174
+
175
+ class TC_Tables_Simple < Test::Unit::TestCase
176
+
177
+
178
+ def setup
179
+ goto_page("simple_table.html")
180
+ end
181
+
182
+ def test_simple_table_access
183
+ table = browser.table(:index,1)
184
+
185
+ assert_equal("Row 3 Col1",table[3][1].text.strip)
186
+ assert_equal("Row 1 Col1",table[1][1].text.strip)
187
+ assert_equal("Row 3 Col2",table[3][2].text.strip)
188
+ assert_equal(2,table.column_count)
189
+ end
190
+ end
191
+
192
+ class TC_Tables_Buttons < Test::Unit::TestCase
193
+
194
+
195
+ def setup
196
+ goto_page("simple_table_buttons.html")
197
+ end
198
+
199
+ def test_simple_table_buttons
200
+ table = browser.table(:index,1)
201
+
202
+ table[1][1].button(:index,1).click
203
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
204
+ table[2][1].button(:index,1).click
205
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
206
+
207
+ table[1][1].button(:id,'b1').click
208
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
209
+
210
+ assert_raises(UnknownObjectException ) { table[1][1].button(:id,'b_missing').click }
211
+
212
+ table[3][1].button(:index,2).click
213
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
214
+
215
+ table[3][1].button(:value ,"Click too").click
216
+ assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
217
+
218
+ browser.table(:index,1)[4][1].text_field(:index,1).set("123")
219
+ assert(browser.text_field(:index,2).verify_contains("123"))
220
+
221
+ # check when a cell contains 2 objects
222
+
223
+ # if there were 2 different html objects in the same cell, some weird things happened ( button caption could change for example)
224
+ assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
225
+ browser.table(:index,1)[5][1].text_field(:index,1).click
226
+ assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
227
+
228
+ browser.table(:index,1)[5][1].button(:index,1).click
229
+ assert_equal( '' , browser.table(:index,1)[5][1].text_field(:index,1).value )
230
+ end
231
+
232
+ def test_simple_table_gif
233
+ table = browser.table(:index,2)
234
+
235
+ assert_match( /1\.gif/ , table[1][1].image( :index,1).src )
236
+ assert_match( /2\.gif/ , table[1][2].image( :index ,1).src )
237
+ assert_match( /3\.gif/ , table[1][3].image( :index ,1).src )
238
+
239
+ assert_match( /1\.gif/ , table[3][1].image( :index ,1).src )
240
+ assert_match( /2\.gif/ , table[3][2].image( :index ,1).src )
241
+ assert_match( /3\.gif/ , table[3][3].image( :index ,1).src )
242
+
243
+ table = browser.table(:index,3)
244
+ assert_match( /1\.gif/ , table[1][1].image( :index ,1).src )
245
+ assert_match( /2\.gif/ , table[1][1].image( :index ,2).src )
246
+ assert_match( /3\.gif/ , table[1][1].image( :index ,3).src )
247
+
248
+ assert_match( /1\.gif/ , table[3][1].image( :index ,1).src )
249
+ assert_match( /2\.gif/ , table[3][1].image( :index ,2).src )
250
+ assert_match( /3\.gif/ , table[3][1].image( :index ,3).src )
251
+ end
252
+
253
+ def test_table_with_hidden_or_visible_rows
254
+ t = browser.table(:id , 'show_hide')
255
+
256
+ # expand the table
257
+ t.each do |r|
258
+ r[1].image(:src, /plus/).click if r[1].image(:src, /plus/).exists?
259
+ end
260
+
261
+ # shrink rows 1,2,3
262
+ count=1
263
+ t.each do |r|
264
+ r[1].image(:src, /minus/).click if r[1].image(:src, /minus/).exists? and (1..3) === count
265
+ count=2
266
+ end
267
+ end
268
+
269
+ # def test_table_from_element
270
+ # button = browser.button(:id, "b1")
271
+ # table = Table.create_from_element(browser, button)
272
+
273
+ # table[2][1].button(:index, 1).click
274
+ # assert(browser.textField(:name, "confirmtext").verify_contains(/CLICK2/i))
275
+ # end
276
+ end
277
+
278
+ class TC_Table_Columns < Test::Unit::TestCase
279
+
280
+ def setup
281
+ goto_page("simple_table_columns.html")
282
+ end
283
+
284
+ # def test_get_columnvalues_single_column
285
+ # assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 1).column_values(1))
286
+ # end
287
+
288
+ def test_colspan
289
+ assert_equal(2, browser.table(:index, 3)[2][1].colspan)
290
+ assert_equal(1, browser.table(:index, 3)[1][1].colspan)
291
+ assert_equal(3, browser.table(:index, 3)[4][1].colspan)
292
+ end
293
+
294
+ def test_get_columnvalues_multiple_column
295
+ assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 2).column_values(1))
296
+ assert_equal(["R1C3", "R2C3", "R3C3"], browser.table(:index, 2).column_values(3))
297
+ end
298
+
299
+ def test_get_columnvalues_with_colspan
300
+ assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], browser.table(:index, 3).column_values(1))
301
+ end
302
+
303
+ def test_get_rowvalues_full_row
304
+ assert_equal(["R1C1", "R1C2", "R1C3"], browser.table(:index, 3).row_values(1))
305
+ end
306
+
307
+ def test_get_rowvalues_with_colspan
308
+ assert_equal(["R2C1", "R2C2"], browser.table(:index, 3).row_values(2))
309
+ end
310
+
311
+ def test_getrowvalues_with_rowspan
312
+ assert_equal(["R5C1", "R5C2", "R5C3"], browser.table(:index, 3).row_values(5))
313
+ assert_equal(["R6C2", "R6C3"], browser.table(:index, 3).row_values(6))
314
+ end
315
+ end
316
+
317
+ class TC_Tables_Complex < Test::Unit::TestCase
318
+
319
+ def setup
320
+ goto_page("complex_table.html")
321
+ end
322
+
323
+ def test_complex_table_access
324
+ table = browser.table(:index,1)
325
+
326
+ assert_equal("subtable1 Row 1 Col1",table[1][1].table(:index,1)[1][1].text.strip)
327
+ assert_equal("subtable1 Row 1 Col2",table[1][1].table(:index,1)[1][2].text.strip)
328
+ assert_equal("subtable2 Row 1 Col2",table[2][1].table(:index,1)[1][2].text.strip)
329
+ assert_equal("subtable2 Row 1 Col1",table[2][1].table(:index,1)[1][1].text.strip)
330
+ end
331
+
332
+ def test_each_itterator
333
+ # for WTR-324: keep Watir::Table.each from crashing when run on nested tables
334
+ table = browser.table(:index,1)
335
+ assert_equal(table.row_count, 2)
336
+ example_row_count = 0
337
+ assert_nothing_thrown do
338
+ table.each do
339
+ example_row_count += 1
340
+ end
341
+ end
342
+ assert_equal(example_row_count, 2)
343
+ end
344
+ end
345
+
346
+ class TC_Tables_Display < Test::Unit::TestCase
347
+ include CaptureIOHelper
348
+
349
+ tag_method :test_showTables, :fails_on_ie
350
+ def test_showTables
351
+ goto_page("table1.html")
352
+ actual = capture_stdout { browser.showTables }
353
+ assert_equal(<<END_OF_MESSAGE, actual)
354
+ There are 7 tables
355
+ table: id: tblTest
356
+ rows: 2
357
+ columns: 2
358
+ index: 1
359
+ table: id: t1
360
+ rows: 5
361
+ columns: 1
362
+ index: 2
363
+ table: id: t2
364
+ rows: 2
365
+ columns: 2
366
+ index: 3
367
+ table: id:
368
+ rows: 1
369
+ columns: 2
370
+ index: 4
371
+ table: id: body_test
372
+ rows: 5
373
+ columns: 1
374
+ index: 5
375
+ table: id: pic_table
376
+ rows: 2
377
+ columns: 2
378
+ index: 6
379
+ table: id: tblTest1
380
+ rows: 5
381
+ columns: 1
382
+ index: 7
383
+ END_OF_MESSAGE
384
+ end
385
+ end