watir 1.6.5 → 1.6.6.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +461 -326
- data/VERSION +1 -0
- data/bin/watir-console +6 -6
- data/lib/changes.rb +3 -3
- data/lib/license.rb +38 -38
- data/lib/readme.rb +140 -140
- data/lib/watir/WindowHelper.rb +49 -49
- data/lib/watir/camel_case.rb +66 -66
- data/lib/watir/clickJSDialog.rb +19 -19
- data/lib/watir/close_all.rb +37 -37
- data/lib/watir/collections.rb +392 -344
- data/lib/watir/container.rb +857 -815
- data/lib/watir/contrib/enabled_popup.rb +20 -20
- data/lib/watir/contrib/ie-new-process.rb +27 -27
- data/lib/watir/contrib/page_checker.rb +29 -29
- data/lib/watir/cookiemanager.rb +55 -55
- data/lib/watir/core.rb +28 -0
- data/lib/watir/core_ext.rb +17 -17
- data/lib/watir/datahandler.rb +107 -107
- data/lib/watir/dialog.rb +46 -46
- data/lib/watir/element.rb +351 -343
- data/lib/watir/element_collections.rb +97 -97
- data/lib/watir/form.rb +170 -170
- data/lib/watir/frame.rb +59 -59
- data/lib/watir/html_element.rb +22 -0
- data/lib/watir/ie-class.rb +1006 -1009
- data/lib/watir/ie-process.rb +39 -39
- data/lib/watir/ie.rb +70 -133
- data/lib/watir/image.rb +130 -130
- data/lib/watir/input_elements.rb +614 -572
- data/lib/watir/irb-history.rb +30 -30
- data/lib/watir/link.rb +64 -64
- data/lib/watir/locator.rb +200 -176
- data/lib/watir/logger.rb +19 -19
- data/lib/watir/modal_dialog.rb +122 -122
- data/lib/watir/module.rb +37 -0
- data/lib/watir/non_control_elements.rb +145 -145
- data/lib/watir/page-container.rb +116 -107
- data/lib/watir/popup.rb +29 -29
- data/lib/watir/process.rb +19 -19
- data/lib/watir/screen_capture.rb +115 -115
- data/lib/watir/setFileDialog.rb +16 -16
- data/lib/watir/table.rb +395 -362
- data/lib/watir/watir_simple.rb +475 -475
- data/lib/watir/win32.rb +35 -35
- data/lib/watir/win32ole.rb +14 -14
- data/lib/watir/winClicker.rb +496 -496
- data/rakefile.rb +70 -0
- data/unittests/all_tests.rb +10 -10
- data/unittests/buttons_xpath_test.rb +69 -69
- data/unittests/checkbox_test.rb +179 -179
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/click_no_wait_test.rb +21 -0
- data/unittests/core_tests.rb +17 -17
- data/unittests/css_test.rb +42 -35
- data/unittests/defer_test.rb +46 -46
- data/unittests/dialog_test.rb +77 -77
- data/unittests/div2_xpath_test.rb +21 -21
- data/unittests/div_test.rb +188 -188
- data/unittests/div_xpath_test.rb +96 -96
- data/unittests/element_test.rb +49 -0
- data/unittests/errorchecker_test.rb +32 -22
- data/unittests/filefield_test.rb +39 -39
- data/unittests/filefield_xpath_test.rb +33 -33
- data/unittests/form_test.rb +280 -280
- data/unittests/form_xpath_test.rb +252 -252
- data/unittests/frame_test.rb +155 -155
- data/unittests/google_form_test.rb +15 -15
- data/unittests/html/JavascriptClick.html +39 -39
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +40 -40
- data/unittests/html/checkboxes1.html +89 -89
- data/unittests/html/click_no_wait.html +14 -0
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/depot_store.html +59 -59
- data/unittests/html/div.html +93 -93
- data/unittests/html/div_xml.html +20 -20
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +44 -44
- data/unittests/html/forms3.html +131 -131
- data/unittests/html/forms4.html +27 -27
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/frame_links.html +3 -3
- data/unittests/html/frame_multi.html +4 -4
- data/unittests/html/google_india.html +119 -119
- data/unittests/html/iframeTest.html +12 -12
- data/unittests/html/iframeTest1.html +6 -6
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/images1.html +66 -66
- data/unittests/html/javascriptevents.html +35 -35
- data/unittests/html/link_pass.html +10 -10
- data/unittests/html/links1.html +38 -38
- data/unittests/html/links2.html +10 -10
- data/unittests/html/links_multi.html +14 -14
- data/unittests/html/list_matters.html +720 -720
- data/unittests/html/lists.html +17 -17
- data/unittests/html/map_test.html +31 -31
- data/unittests/html/modal_dialog.html +10 -10
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +16 -16
- data/unittests/html/pass.html +12 -12
- data/unittests/html/popups1.html +59 -59
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +71 -71
- data/unittests/html/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +52 -52
- data/unittests/html/simple_table.html +26 -26
- data/unittests/html/simple_table_buttons.html +104 -104
- data/unittests/html/simple_table_columns.html +76 -76
- data/unittests/html/table1.html +181 -181
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/table_and_tablerow_to_a.html +174 -0
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +88 -88
- data/unittests/html/textsearch.html +44 -44
- data/unittests/html/wallofcheckboxes.html +1003 -1003
- data/unittests/html/xpath_nbsp.html +12 -12
- data/unittests/ie_exists_test.rb +33 -33
- data/unittests/ie_mock.rb +94 -94
- data/unittests/ie_test.rb +51 -51
- data/unittests/images_test.rb +157 -157
- data/unittests/images_xpath_test.rb +91 -91
- data/unittests/links_multi_test.rb +48 -48
- data/unittests/links_test.rb +175 -175
- data/unittests/links_xpath_test.rb +39 -39
- data/unittests/lists_test.rb +32 -32
- data/unittests/map_test.rb +98 -98
- data/unittests/minmax_test.rb +31 -31
- data/unittests/navigate_test.rb +39 -39
- data/unittests/nbsp_xpath_test.rb +16 -16
- data/unittests/non_core_tests.rb +12 -12
- data/unittests/other/WindowLogonExample.rb +27 -27
- data/unittests/other/WindowLogonExtra.rb +6 -6
- data/unittests/other/all_tests_concurrent.rb +57 -57
- data/unittests/other/jscriptExtraAlert.rb +6 -6
- data/unittests/other/jscriptExtraConfirmCancel.rb +6 -6
- data/unittests/other/jscriptExtraConfirmOk.rb +6 -6
- data/unittests/other/jscriptPushButton.rb +6 -6
- data/unittests/other/jscript_test.rb +63 -63
- data/unittests/other/navigate_exception_test.rb +24 -24
- data/unittests/other/rexml_unit_test.rb +27 -27
- data/unittests/other/screen_capture_test.rb +54 -54
- data/unittests/other/testcase_method_order_test.rb +35 -35
- data/unittests/other/testcase_verify_test.rb +24 -24
- data/unittests/other/wait_until_test.rb +99 -99
- data/unittests/pagecontainstext_test.rb +69 -69
- data/unittests/parent_child_test.rb +43 -43
- data/unittests/perf_test.rb +20 -20
- data/unittests/popups_test.rb +43 -43
- data/unittests/pre_test.rb +53 -53
- data/unittests/radios_test.rb +212 -212
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/security_setting_test.rb +23 -23
- data/unittests/selectbox_test.rb +148 -148
- data/unittests/selectbox_xpath_test.rb +113 -113
- data/unittests/setup.rb +87 -77
- data/unittests/speed_settings_test.rb +67 -67
- data/unittests/table_and_tablerow_to_a_test.rb +117 -0
- data/unittests/table_cell_using_xpath_test.rb +35 -35
- data/unittests/table_test.rb +376 -376
- data/unittests/table_xpath_test.rb +110 -110
- data/unittests/test_tests.rb +9 -9
- data/unittests/textarea_test.rb +92 -92
- data/unittests/textarea_xpath_test.rb +78 -78
- data/unittests/textfield_for_ch_char_test.rb +31 -31
- data/unittests/textfields_test.rb +218 -218
- data/unittests/textfields_xpath_test.rb +111 -111
- data/unittests/window_tests.rb +10 -10
- data/unittests/windows/attach_to_existing_window_test.rb +53 -53
- data/unittests/windows/attach_to_new_window_test.rb +83 -83
- data/unittests/windows/close_window_test.rb +20 -20
- data/unittests/windows/frame_links_test.rb +25 -25
- data/unittests/windows/ie-each_test.rb +47 -47
- data/unittests/windows/iedialog_test.rb +54 -54
- data/unittests/windows/js_events_test.rb +42 -55
- data/unittests/windows/modal_dialog_test.rb +128 -128
- data/unittests/windows/new_test.rb +57 -57
- data/unittests/windows/open_close_test.rb +18 -18
- data/unittests/windows/send_keys_test.rb +33 -33
- data/unittests/xpath_tests.rb +10 -10
- metadata +85 -31
- data/lib/watir/utils.rb +0 -20
- data/lib/watir/version.rb +0 -5
data/unittests/table_test.rb
CHANGED
@@ -1,376 +1,376 @@
|
|
1
|
-
# feature tests for Tables
|
2
|
-
# revision: $Revision$
|
3
|
-
|
4
|
-
# Why do so many of these tests call "strip"? A distinct smell...
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
7
|
-
require 'unittests/setup'
|
8
|
-
|
9
|
-
class TC_Tables < Test::Unit::TestCase
|
10
|
-
include Watir::Exception
|
11
|
-
|
12
|
-
def setup
|
13
|
-
uses_page "table1.html"
|
14
|
-
end
|
15
|
-
def teardown
|
16
|
-
browser.refresh if @reload_page
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_exists
|
20
|
-
assert browser.table(:id, 't1').exists?
|
21
|
-
assert browser.table(:id, /t/).exists?
|
22
|
-
|
23
|
-
assert !browser.table(:id, 'missingTable').exists?
|
24
|
-
assert !browser.table(:id, /missing_table/).exists?
|
25
|
-
|
26
|
-
assert browser.table(:index, 1).exists?
|
27
|
-
assert !browser.table(:index, 33).exists?
|
28
|
-
end
|
29
|
-
|
30
|
-
tag_method :test_row_count_exceptions, :fails_on_firefox
|
31
|
-
def test_row_count_exceptions
|
32
|
-
assert_raises UnknownObjectException do
|
33
|
-
browser.table(:id, 'missingTable').row_count
|
34
|
-
end
|
35
|
-
assert_raises UnknownObjectException do
|
36
|
-
browser.table(:index, 66).row_count
|
37
|
-
end
|
38
|
-
assert_raises MissingWayOfFindingObjectException do
|
39
|
-
browser.table(:bad_attribute, 99).row_count
|
40
|
-
end
|
41
|
-
end
|
42
|
-
def test_rows
|
43
|
-
assert_equal(2, browser.table(:index, 1).row_count)
|
44
|
-
assert_equal(2, browser.table(:index, 1).rows.length)
|
45
|
-
|
46
|
-
assert_equal(5, browser.table(:id, 't1').row_count) # 4 rows and a header
|
47
|
-
assert_equal(5, browser.table(:index, 2).row_count) # same table as above, just accessed by index
|
48
|
-
assert_equal(5, browser.table(:id, 't1').rows.length)
|
49
|
-
|
50
|
-
# test the each iterator on rows - ie, go through each cell
|
51
|
-
row = browser.table(:index, 2)[2]
|
52
|
-
result = []
|
53
|
-
row.each do |cell|
|
54
|
-
result << cell.to_s.strip
|
55
|
-
end
|
56
|
-
assert_equal(['Row 1 Col1', 'Row 1 Col2'], result)
|
57
|
-
assert_equal(2, row.column_count)
|
58
|
-
end
|
59
|
-
|
60
|
-
tag_method :test_row_counts, :fails_on_firefox
|
61
|
-
def test_row_counts
|
62
|
-
table = browser.table(:id => 't2')
|
63
|
-
assert_equal(3, table.row_count)
|
64
|
-
assert_equal(2, table.row_count_excluding_nested_tables)
|
65
|
-
end
|
66
|
-
|
67
|
-
tag_method :test_dynamic_tables, :fails_on_firefox
|
68
|
-
def test_dynamic_tables
|
69
|
-
@reload_page = true
|
70
|
-
t = browser.table(:id, 't1')
|
71
|
-
assert_equal(5, t.row_count)
|
72
|
-
browser.button(:value, 'add row').click
|
73
|
-
assert_equal(6, t.row_count)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_columns
|
77
|
-
assert_raises UnknownObjectException do
|
78
|
-
browser.table(:id, 'missingTable').column_count
|
79
|
-
end
|
80
|
-
assert_raises UnknownObjectException do
|
81
|
-
browser.table(:index, 77).column_count
|
82
|
-
end
|
83
|
-
assert_equal(2, browser.table(:index, 1).column_count)
|
84
|
-
assert_equal(1, browser.table(:id, 't1').column_count) # row one has 1 cell with a colspan of 2
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_to_a
|
88
|
-
expected = [ ["Row 1 Col1" , "Row 1 Col2"],
|
89
|
-
[ "Row 2 Col1" , "Row 2 Col2"] ]
|
90
|
-
assert_equal(expected, browser.table(:index , 1).to_a)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_links_and_images_in_table
|
94
|
-
table = browser.table(:id, 'pic_table')
|
95
|
-
image = table[1][2].image(:index,1)
|
96
|
-
assert_equal("106", image.width)
|
97
|
-
|
98
|
-
link = table[1][4].link(:index,1)
|
99
|
-
assert_equal("Google", link.innerText)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_cell_directly
|
103
|
-
assert browser.cell(:id, 'cell1').exists?
|
104
|
-
assert ! browser.cell(:id, 'no_exist').exists?
|
105
|
-
assert_equal("Row 1 Col1", browser.cell(:id, 'cell1').to_s.strip)
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_cell_another_way
|
109
|
-
assert_equal( "Row 1 Col1", browser.table(:index,1)[1][1].to_s.strip)
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_row_directly
|
113
|
-
assert browser.row(:id, 'row1').exists?
|
114
|
-
assert ! browser.row(:id, 'no_exist').exists?
|
115
|
-
end
|
116
|
-
def test_row_another_way
|
117
|
-
assert_equal('Row 2 Col1', browser.row(:id, 'row1')[1].to_s.strip)
|
118
|
-
end
|
119
|
-
|
120
|
-
tag_method :test_row_in_table, :fails_on_firefox
|
121
|
-
def test_row_in_table
|
122
|
-
assert_equal 'Row 2 Col1 Row 2 Col2',
|
123
|
-
browser.table(:id, 't1').row(:id, 'row1').text
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_row_iterator
|
127
|
-
t = browser.table(:index, 1)
|
128
|
-
count = 1
|
129
|
-
t.each do |row|
|
130
|
-
if count == 1
|
131
|
-
assert("Row 1 Col1", row[1].text)
|
132
|
-
assert("Row 1 Col2", row[2].text)
|
133
|
-
elsif count == 2
|
134
|
-
assert("Row 2 Col1", row[1].text)
|
135
|
-
assert("Row 2 Col2", row[2].text)
|
136
|
-
end
|
137
|
-
count += 1
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_row_collection
|
142
|
-
t = browser.table(:index,1)
|
143
|
-
count = 1
|
144
|
-
t.rows.each do |row|
|
145
|
-
if count == 1
|
146
|
-
assert("Row 1 Col1", row[1].text)
|
147
|
-
assert("Row 1 Col2", row[2].text)
|
148
|
-
elsif count == 2
|
149
|
-
assert("Row 2 Col1", row[1].text)
|
150
|
-
assert("Row 2 Col2", row[2].text)
|
151
|
-
end
|
152
|
-
count += 1
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
tag_method :test_cell_collection, :fails_on_firefox
|
157
|
-
def test_cell_collection
|
158
|
-
t = browser.table(:index,1)
|
159
|
-
contents = t.cells.collect {|c| c.text}
|
160
|
-
assert_equal(["Row 1 Col1","Row 1 Col2","Row 2 Col1","Row 2 Col2"], contents)
|
161
|
-
end
|
162
|
-
|
163
|
-
tag_method :test_table_body, :fails_on_firefox
|
164
|
-
def test_table_body
|
165
|
-
assert_equal(1, browser.table(:index, 1).bodies.length)
|
166
|
-
assert_equal(3, browser.table(:id, 'body_test').bodies.length)
|
167
|
-
|
168
|
-
count = 1
|
169
|
-
browser.table(:id, 'body_test').bodies.each do |n|
|
170
|
-
# do something better here!
|
171
|
-
case count
|
172
|
-
when 1
|
173
|
-
compare_text = "This text is in the FRST TBODY."
|
174
|
-
when 2
|
175
|
-
compare_text = "This text is in the SECOND TBODY."
|
176
|
-
when 3
|
177
|
-
compare_text = "This text is in the THIRD TBODY."
|
178
|
-
end
|
179
|
-
assert_equal(compare_text, n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
|
180
|
-
count += 1
|
181
|
-
end
|
182
|
-
assert_equal( count - 1, browser.table(:id, 'body_test').bodies.length )
|
183
|
-
assert_equal( "This text is in the THIRD TBODY." ,browser.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
|
184
|
-
|
185
|
-
# iterate through all the rows in a table body
|
186
|
-
count = 1
|
187
|
-
browser.table(:id, 'body_test').body(:index, 2).each do | row |
|
188
|
-
# row.flash # this line commented out, to speed up the tests
|
189
|
-
if count == 1
|
190
|
-
assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
|
191
|
-
elsif count == 1 # BUG: Huh?
|
192
|
-
assert_equal('This text is also in the SECOND TBODY.', row[1].text.strip )
|
193
|
-
end
|
194
|
-
count+=1
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_table_container
|
199
|
-
assert_nothing_raised { browser.table(:id, 't1').html }
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_multiple_selector
|
203
|
-
assert_equal('Second table with css class',
|
204
|
-
browser.table(:class => 'sample', :index => 2)[1][1].text)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
class TC_Tables_Simple < Test::Unit::TestCase
|
209
|
-
include Watir
|
210
|
-
|
211
|
-
def setup
|
212
|
-
goto_page "simple_table.html"
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_simple_table_access
|
216
|
-
table = browser.table(:index,1)
|
217
|
-
assert_equal("Row 3 Col1", table[3][1].text.strip)
|
218
|
-
assert_equal("Row 1 Col1", table[1][1].text.strip)
|
219
|
-
assert_equal("Row 3 Col2", table[3][2].text.strip)
|
220
|
-
assert_equal(2, table.column_count)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
class TC_Tables_Buttons < Test::Unit::TestCase
|
224
|
-
include Watir
|
225
|
-
|
226
|
-
def setup
|
227
|
-
uses_page "simple_table_buttons.html"
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_simple_table_buttons
|
231
|
-
table = browser.table(:index, 1)
|
232
|
-
|
233
|
-
table[1][1].button(:index, 1).click
|
234
|
-
assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
|
235
|
-
table[2][1].button(:index, 1).click
|
236
|
-
assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
|
237
|
-
|
238
|
-
table[1][1].button(:id, 'b1').click
|
239
|
-
assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
|
240
|
-
|
241
|
-
assert_raises(UnknownObjectException ) { table[1][1].button(:id,'b_missing').click }
|
242
|
-
|
243
|
-
table[3][1].button(:index, 2).click
|
244
|
-
assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
|
245
|
-
|
246
|
-
table[3][1].button(:value, "Click too").click
|
247
|
-
assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
|
248
|
-
|
249
|
-
browser.table(:index, 1)[4][1].text_field(:index,1).set("123")
|
250
|
-
assert(browser.text_field(:index,2).verify_contains("123"))
|
251
|
-
|
252
|
-
# check when a cell contains 2 objects
|
253
|
-
|
254
|
-
# if there were 2 different html objects in the same cell, some weird things happened ( button caption could change for example)
|
255
|
-
assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
|
256
|
-
browser.table(:index,1)[5][1].text_field(:index,1).click
|
257
|
-
assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
|
258
|
-
|
259
|
-
browser.table(:index,1)[5][1].button(:index,1).click
|
260
|
-
assert_equal( '' , browser.table(:index,1)[5][1].text_field(:index,1).value )
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_simple_table_gif
|
264
|
-
table = browser.table(:index,2)
|
265
|
-
assert_match(/1\.gif/, table[1][1].image(:index, 1).src)
|
266
|
-
assert_match(/2\.gif/, table[1][2].image(:index, 1).src)
|
267
|
-
assert_match(/3\.gif/, table[1][3].image(:index, 1).src)
|
268
|
-
|
269
|
-
assert_match(/1\.gif/, table[3][1].image(:index, 1).src)
|
270
|
-
assert_match(/2\.gif/, table[3][2].image(:index, 1).src)
|
271
|
-
assert_match(/3\.gif/, table[3][3].image(:index, 1).src)
|
272
|
-
|
273
|
-
table = browser.table(:index,3)
|
274
|
-
assert_match(/1\.gif/, table[1][1].image(:index, 1).src)
|
275
|
-
assert_match(/2\.gif/, table[1][1].image(:index, 2).src)
|
276
|
-
assert_match(/3\.gif/, table[1][1].image(:index, 3).src)
|
277
|
-
|
278
|
-
assert_match(/1\.gif/, table[3][1].image(:index, 1).src)
|
279
|
-
assert_match(/2\.gif/, table[3][1].image(:index, 2).src)
|
280
|
-
assert_match(/3\.gif/, table[3][1].image(:index, 3).src)
|
281
|
-
end
|
282
|
-
|
283
|
-
def test_table_with_hidden_or_visible_rows
|
284
|
-
t = browser.table(:id , 'show_hide')
|
285
|
-
|
286
|
-
# expand the table
|
287
|
-
t.each do |r|
|
288
|
-
r[1].image(:src, /plus/).click if r[1].image(:src, /plus/).exists?
|
289
|
-
end
|
290
|
-
|
291
|
-
# shrink rows 1,2,3
|
292
|
-
count = 1
|
293
|
-
t.each do |r|
|
294
|
-
r[1].image(:src, /minus/).click if r[1].image(:src, /minus/).exists? and (1..3) === count
|
295
|
-
count = 2
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
tag_method :test_table_from_element, :fails_on_firefox
|
300
|
-
def test_table_from_element
|
301
|
-
button = browser.button(:id, "b1")
|
302
|
-
table = Watir::Table.create_from_element(browser, button)
|
303
|
-
|
304
|
-
table[2][1].button(:index, 1).click
|
305
|
-
assert(browser.text_field(:name, "confirmtext").verify_contains(/CLICK2/i))
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
class TC_Table_Columns < Test::Unit::TestCase
|
310
|
-
include Watir::Exception
|
311
|
-
def setup
|
312
|
-
uses_page "simple_table_columns.html"
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_get_columnvalues_single_column
|
316
|
-
assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 1).column_values(1))
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_colspan
|
320
|
-
assert_equal(2, browser.table(:index, 3)[2][1].colspan)
|
321
|
-
assert_equal(1, browser.table(:index, 3)[1][1].colspan)
|
322
|
-
assert_equal(3, browser.table(:index, 3)[4][1].colspan)
|
323
|
-
end
|
324
|
-
|
325
|
-
def test_get_columnvalues_multiple_column
|
326
|
-
assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 2).column_values(1))
|
327
|
-
assert_equal(["R1C3", "R2C3", "R3C3"], browser.table(:index, 2).column_values(3))
|
328
|
-
end
|
329
|
-
|
330
|
-
tag_method :test_get_columnvalues_with_colspan, :fails_on_firefox
|
331
|
-
def test_get_columnvalues_with_colspan
|
332
|
-
assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], browser.table(:index, 3).column_values(1))
|
333
|
-
(2..4).each{|x|assert_raises(UnknownCellException){browser.table(:index, 3).column_values(x)}}
|
334
|
-
end
|
335
|
-
|
336
|
-
def test_get_rowvalues_full_row
|
337
|
-
assert_equal(["R1C1", "R1C2", "R1C3"], browser.table(:index, 3).row_values(1))
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_get_rowvalues_with_colspan
|
341
|
-
assert_equal(["R2C1", "R2C2"], browser.table(:index, 3).row_values(2))
|
342
|
-
end
|
343
|
-
|
344
|
-
def test_getrowvalues_with_rowspan
|
345
|
-
assert_equal(["R5C1", "R5C2", "R5C3"], browser.table(:index, 3).row_values(5))
|
346
|
-
assert_equal(["R6C2", "R6C3"], browser.table(:index, 3).row_values(6))
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
class TC_Tables_Complex < Test::Unit::TestCase
|
351
|
-
def setup
|
352
|
-
uses_page "complex_table.html"
|
353
|
-
end
|
354
|
-
|
355
|
-
def test_complex_table_access
|
356
|
-
table = browser.table(:index,1)
|
357
|
-
assert_equal("subtable1 Row 1 Col1",table[1][1].table(:index,1)[1][1].text.strip)
|
358
|
-
assert_equal("subtable1 Row 1 Col2",table[1][1].table(:index,1)[1][2].text.strip)
|
359
|
-
assert_equal("subtable2 Row 1 Col2",table[2][1].table(:index,1)[1][2].text.strip)
|
360
|
-
assert_equal("subtable2 Row 1 Col1",table[2][1].table(:index,1)[1][1].text.strip)
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_each_itterator
|
364
|
-
# for WTR-324: keep Watir::Table.each from crashing when run on nested tables
|
365
|
-
table = browser.table(:index,1)
|
366
|
-
assert_equal(table.row_count, 4)
|
367
|
-
assert_equal(table.row_count_excluding_nested_tables, 2)
|
368
|
-
example_row_count = 0
|
369
|
-
assert_nothing_thrown do
|
370
|
-
table.each do
|
371
|
-
example_row_count += 1
|
372
|
-
end
|
373
|
-
end
|
374
|
-
assert_equal(example_row_count, 2)
|
375
|
-
end
|
376
|
-
end
|
1
|
+
# feature tests for Tables
|
2
|
+
# revision: $Revision$
|
3
|
+
|
4
|
+
# Why do so many of these tests call "strip"? A distinct smell...
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
|
7
|
+
require 'unittests/setup'
|
8
|
+
|
9
|
+
class TC_Tables < Test::Unit::TestCase
|
10
|
+
include Watir::Exception
|
11
|
+
|
12
|
+
def setup
|
13
|
+
uses_page "table1.html"
|
14
|
+
end
|
15
|
+
def teardown
|
16
|
+
browser.refresh if @reload_page
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_exists
|
20
|
+
assert browser.table(:id, 't1').exists?
|
21
|
+
assert browser.table(:id, /t/).exists?
|
22
|
+
|
23
|
+
assert !browser.table(:id, 'missingTable').exists?
|
24
|
+
assert !browser.table(:id, /missing_table/).exists?
|
25
|
+
|
26
|
+
assert browser.table(:index, 1).exists?
|
27
|
+
assert !browser.table(:index, 33).exists?
|
28
|
+
end
|
29
|
+
|
30
|
+
tag_method :test_row_count_exceptions, :fails_on_firefox
|
31
|
+
def test_row_count_exceptions
|
32
|
+
assert_raises UnknownObjectException do
|
33
|
+
browser.table(:id, 'missingTable').row_count
|
34
|
+
end
|
35
|
+
assert_raises UnknownObjectException do
|
36
|
+
browser.table(:index, 66).row_count
|
37
|
+
end
|
38
|
+
assert_raises MissingWayOfFindingObjectException do
|
39
|
+
browser.table(:bad_attribute, 99).row_count
|
40
|
+
end
|
41
|
+
end
|
42
|
+
def test_rows
|
43
|
+
assert_equal(2, browser.table(:index, 1).row_count)
|
44
|
+
assert_equal(2, browser.table(:index, 1).rows.length)
|
45
|
+
|
46
|
+
assert_equal(5, browser.table(:id, 't1').row_count) # 4 rows and a header
|
47
|
+
assert_equal(5, browser.table(:index, 2).row_count) # same table as above, just accessed by index
|
48
|
+
assert_equal(5, browser.table(:id, 't1').rows.length)
|
49
|
+
|
50
|
+
# test the each iterator on rows - ie, go through each cell
|
51
|
+
row = browser.table(:index, 2)[2]
|
52
|
+
result = []
|
53
|
+
row.each do |cell|
|
54
|
+
result << cell.to_s.strip
|
55
|
+
end
|
56
|
+
assert_equal(['Row 1 Col1', 'Row 1 Col2'], result)
|
57
|
+
assert_equal(2, row.column_count)
|
58
|
+
end
|
59
|
+
|
60
|
+
tag_method :test_row_counts, :fails_on_firefox
|
61
|
+
def test_row_counts
|
62
|
+
table = browser.table(:id => 't2')
|
63
|
+
assert_equal(3, table.row_count)
|
64
|
+
assert_equal(2, table.row_count_excluding_nested_tables)
|
65
|
+
end
|
66
|
+
|
67
|
+
tag_method :test_dynamic_tables, :fails_on_firefox
|
68
|
+
def test_dynamic_tables
|
69
|
+
@reload_page = true
|
70
|
+
t = browser.table(:id, 't1')
|
71
|
+
assert_equal(5, t.row_count)
|
72
|
+
browser.button(:value, 'add row').click
|
73
|
+
assert_equal(6, t.row_count)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_columns
|
77
|
+
assert_raises UnknownObjectException do
|
78
|
+
browser.table(:id, 'missingTable').column_count
|
79
|
+
end
|
80
|
+
assert_raises UnknownObjectException do
|
81
|
+
browser.table(:index, 77).column_count
|
82
|
+
end
|
83
|
+
assert_equal(2, browser.table(:index, 1).column_count)
|
84
|
+
assert_equal(1, browser.table(:id, 't1').column_count) # row one has 1 cell with a colspan of 2
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_to_a
|
88
|
+
expected = [ ["Row 1 Col1" , "Row 1 Col2"],
|
89
|
+
[ "Row 2 Col1" , "Row 2 Col2"] ]
|
90
|
+
assert_equal(expected, browser.table(:index , 1).to_a)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_links_and_images_in_table
|
94
|
+
table = browser.table(:id, 'pic_table')
|
95
|
+
image = table[1][2].image(:index,1)
|
96
|
+
assert_equal("106", image.width)
|
97
|
+
|
98
|
+
link = table[1][4].link(:index,1)
|
99
|
+
assert_equal("Google", link.innerText)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_cell_directly
|
103
|
+
assert browser.cell(:id, 'cell1').exists?
|
104
|
+
assert ! browser.cell(:id, 'no_exist').exists?
|
105
|
+
assert_equal("Row 1 Col1", browser.cell(:id, 'cell1').to_s.strip)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_cell_another_way
|
109
|
+
assert_equal( "Row 1 Col1", browser.table(:index,1)[1][1].to_s.strip)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_row_directly
|
113
|
+
assert browser.row(:id, 'row1').exists?
|
114
|
+
assert ! browser.row(:id, 'no_exist').exists?
|
115
|
+
end
|
116
|
+
def test_row_another_way
|
117
|
+
assert_equal('Row 2 Col1', browser.row(:id, 'row1')[1].to_s.strip)
|
118
|
+
end
|
119
|
+
|
120
|
+
tag_method :test_row_in_table, :fails_on_firefox
|
121
|
+
def test_row_in_table
|
122
|
+
assert_equal 'Row 2 Col1 Row 2 Col2',
|
123
|
+
browser.table(:id, 't1').row(:id, 'row1').text
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_row_iterator
|
127
|
+
t = browser.table(:index, 1)
|
128
|
+
count = 1
|
129
|
+
t.each do |row|
|
130
|
+
if count == 1
|
131
|
+
assert("Row 1 Col1", row[1].text)
|
132
|
+
assert("Row 1 Col2", row[2].text)
|
133
|
+
elsif count == 2
|
134
|
+
assert("Row 2 Col1", row[1].text)
|
135
|
+
assert("Row 2 Col2", row[2].text)
|
136
|
+
end
|
137
|
+
count += 1
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_row_collection
|
142
|
+
t = browser.table(:index,1)
|
143
|
+
count = 1
|
144
|
+
t.rows.each do |row|
|
145
|
+
if count == 1
|
146
|
+
assert("Row 1 Col1", row[1].text)
|
147
|
+
assert("Row 1 Col2", row[2].text)
|
148
|
+
elsif count == 2
|
149
|
+
assert("Row 2 Col1", row[1].text)
|
150
|
+
assert("Row 2 Col2", row[2].text)
|
151
|
+
end
|
152
|
+
count += 1
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
tag_method :test_cell_collection, :fails_on_firefox
|
157
|
+
def test_cell_collection
|
158
|
+
t = browser.table(:index,1)
|
159
|
+
contents = t.cells.collect {|c| c.text}
|
160
|
+
assert_equal(["Row 1 Col1","Row 1 Col2","Row 2 Col1","Row 2 Col2"], contents)
|
161
|
+
end
|
162
|
+
|
163
|
+
tag_method :test_table_body, :fails_on_firefox
|
164
|
+
def test_table_body
|
165
|
+
assert_equal(1, browser.table(:index, 1).bodies.length)
|
166
|
+
assert_equal(3, browser.table(:id, 'body_test').bodies.length)
|
167
|
+
|
168
|
+
count = 1
|
169
|
+
browser.table(:id, 'body_test').bodies.each do |n|
|
170
|
+
# do something better here!
|
171
|
+
case count
|
172
|
+
when 1
|
173
|
+
compare_text = "This text is in the FRST TBODY."
|
174
|
+
when 2
|
175
|
+
compare_text = "This text is in the SECOND TBODY."
|
176
|
+
when 3
|
177
|
+
compare_text = "This text is in the THIRD TBODY."
|
178
|
+
end
|
179
|
+
assert_equal(compare_text, n[1][1].to_s.strip ) # this is the 1st cell of the first row of this particular body
|
180
|
+
count += 1
|
181
|
+
end
|
182
|
+
assert_equal( count - 1, browser.table(:id, 'body_test').bodies.length )
|
183
|
+
assert_equal( "This text is in the THIRD TBODY." ,browser.table(:id, 'body_test' ).body(:index,3)[1][1].to_s.strip )
|
184
|
+
|
185
|
+
# iterate through all the rows in a table body
|
186
|
+
count = 1
|
187
|
+
browser.table(:id, 'body_test').body(:index, 2).each do | row |
|
188
|
+
# row.flash # this line commented out, to speed up the tests
|
189
|
+
if count == 1
|
190
|
+
assert_equal('This text is in the SECOND TBODY.', row[1].text.strip )
|
191
|
+
elsif count == 1 # BUG: Huh?
|
192
|
+
assert_equal('This text is also in the SECOND TBODY.', row[1].text.strip )
|
193
|
+
end
|
194
|
+
count+=1
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_table_container
|
199
|
+
assert_nothing_raised { browser.table(:id, 't1').html }
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_multiple_selector
|
203
|
+
assert_equal('Second table with css class',
|
204
|
+
browser.table(:class => 'sample', :index => 2)[1][1].text)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
class TC_Tables_Simple < Test::Unit::TestCase
|
209
|
+
include Watir
|
210
|
+
|
211
|
+
def setup
|
212
|
+
goto_page "simple_table.html"
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_simple_table_access
|
216
|
+
table = browser.table(:index,1)
|
217
|
+
assert_equal("Row 3 Col1", table[3][1].text.strip)
|
218
|
+
assert_equal("Row 1 Col1", table[1][1].text.strip)
|
219
|
+
assert_equal("Row 3 Col2", table[3][2].text.strip)
|
220
|
+
assert_equal(2, table.column_count)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
class TC_Tables_Buttons < Test::Unit::TestCase
|
224
|
+
include Watir
|
225
|
+
|
226
|
+
def setup
|
227
|
+
uses_page "simple_table_buttons.html"
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_simple_table_buttons
|
231
|
+
table = browser.table(:index, 1)
|
232
|
+
|
233
|
+
table[1][1].button(:index, 1).click
|
234
|
+
assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
|
235
|
+
table[2][1].button(:index, 1).click
|
236
|
+
assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK2/i))
|
237
|
+
|
238
|
+
table[1][1].button(:id, 'b1').click
|
239
|
+
assert(browser.text_field(:name,"confirmtext").verify_contains(/CLICK1/i))
|
240
|
+
|
241
|
+
assert_raises(UnknownObjectException ) { table[1][1].button(:id,'b_missing').click }
|
242
|
+
|
243
|
+
table[3][1].button(:index, 2).click
|
244
|
+
assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
|
245
|
+
|
246
|
+
table[3][1].button(:value, "Click too").click
|
247
|
+
assert(browser.text_field(:name,"confirmtext").verify_contains(/TOO/i))
|
248
|
+
|
249
|
+
browser.table(:index, 1)[4][1].text_field(:index,1).set("123")
|
250
|
+
assert(browser.text_field(:index,2).verify_contains("123"))
|
251
|
+
|
252
|
+
# check when a cell contains 2 objects
|
253
|
+
|
254
|
+
# if there were 2 different html objects in the same cell, some weird things happened ( button caption could change for example)
|
255
|
+
assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
|
256
|
+
browser.table(:index,1)[5][1].text_field(:index,1).click
|
257
|
+
assert_equal( 'Click ->' , browser.table(:index,1)[5][1].text_field(:index,1).value )
|
258
|
+
|
259
|
+
browser.table(:index,1)[5][1].button(:index,1).click
|
260
|
+
assert_equal( '' , browser.table(:index,1)[5][1].text_field(:index,1).value )
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_simple_table_gif
|
264
|
+
table = browser.table(:index,2)
|
265
|
+
assert_match(/1\.gif/, table[1][1].image(:index, 1).src)
|
266
|
+
assert_match(/2\.gif/, table[1][2].image(:index, 1).src)
|
267
|
+
assert_match(/3\.gif/, table[1][3].image(:index, 1).src)
|
268
|
+
|
269
|
+
assert_match(/1\.gif/, table[3][1].image(:index, 1).src)
|
270
|
+
assert_match(/2\.gif/, table[3][2].image(:index, 1).src)
|
271
|
+
assert_match(/3\.gif/, table[3][3].image(:index, 1).src)
|
272
|
+
|
273
|
+
table = browser.table(:index,3)
|
274
|
+
assert_match(/1\.gif/, table[1][1].image(:index, 1).src)
|
275
|
+
assert_match(/2\.gif/, table[1][1].image(:index, 2).src)
|
276
|
+
assert_match(/3\.gif/, table[1][1].image(:index, 3).src)
|
277
|
+
|
278
|
+
assert_match(/1\.gif/, table[3][1].image(:index, 1).src)
|
279
|
+
assert_match(/2\.gif/, table[3][1].image(:index, 2).src)
|
280
|
+
assert_match(/3\.gif/, table[3][1].image(:index, 3).src)
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_table_with_hidden_or_visible_rows
|
284
|
+
t = browser.table(:id , 'show_hide')
|
285
|
+
|
286
|
+
# expand the table
|
287
|
+
t.each do |r|
|
288
|
+
r[1].image(:src, /plus/).click if r[1].image(:src, /plus/).exists?
|
289
|
+
end
|
290
|
+
|
291
|
+
# shrink rows 1,2,3
|
292
|
+
count = 1
|
293
|
+
t.each do |r|
|
294
|
+
r[1].image(:src, /minus/).click if r[1].image(:src, /minus/).exists? and (1..3) === count
|
295
|
+
count = 2
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
tag_method :test_table_from_element, :fails_on_firefox
|
300
|
+
def test_table_from_element
|
301
|
+
button = browser.button(:id, "b1")
|
302
|
+
table = Watir::Table.create_from_element(browser, button)
|
303
|
+
|
304
|
+
table[2][1].button(:index, 1).click
|
305
|
+
assert(browser.text_field(:name, "confirmtext").verify_contains(/CLICK2/i))
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
class TC_Table_Columns < Test::Unit::TestCase
|
310
|
+
include Watir::Exception
|
311
|
+
def setup
|
312
|
+
uses_page "simple_table_columns.html"
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_get_columnvalues_single_column
|
316
|
+
assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 1).column_values(1))
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_colspan
|
320
|
+
assert_equal(2, browser.table(:index, 3)[2][1].colspan)
|
321
|
+
assert_equal(1, browser.table(:index, 3)[1][1].colspan)
|
322
|
+
assert_equal(3, browser.table(:index, 3)[4][1].colspan)
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_get_columnvalues_multiple_column
|
326
|
+
assert_equal(["R1C1", "R2C1", "R3C1"], browser.table(:index, 2).column_values(1))
|
327
|
+
assert_equal(["R1C3", "R2C3", "R3C3"], browser.table(:index, 2).column_values(3))
|
328
|
+
end
|
329
|
+
|
330
|
+
tag_method :test_get_columnvalues_with_colspan, :fails_on_firefox
|
331
|
+
def test_get_columnvalues_with_colspan
|
332
|
+
assert_equal(["R1C1", "R2C1", "R3C1", "R4C1", "R5C1", "R6C2"], browser.table(:index, 3).column_values(1))
|
333
|
+
(2..4).each{|x|assert_raises(UnknownCellException){browser.table(:index, 3).column_values(x)}}
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_get_rowvalues_full_row
|
337
|
+
assert_equal(["R1C1", "R1C2", "R1C3"], browser.table(:index, 3).row_values(1))
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_get_rowvalues_with_colspan
|
341
|
+
assert_equal(["R2C1", "R2C2"], browser.table(:index, 3).row_values(2))
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_getrowvalues_with_rowspan
|
345
|
+
assert_equal(["R5C1", "R5C2", "R5C3"], browser.table(:index, 3).row_values(5))
|
346
|
+
assert_equal(["R6C2", "R6C3"], browser.table(:index, 3).row_values(6))
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
class TC_Tables_Complex < Test::Unit::TestCase
|
351
|
+
def setup
|
352
|
+
uses_page "complex_table.html"
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_complex_table_access
|
356
|
+
table = browser.table(:index,1)
|
357
|
+
assert_equal("subtable1 Row 1 Col1",table[1][1].table(:index,1)[1][1].text.strip)
|
358
|
+
assert_equal("subtable1 Row 1 Col2",table[1][1].table(:index,1)[1][2].text.strip)
|
359
|
+
assert_equal("subtable2 Row 1 Col2",table[2][1].table(:index,1)[1][2].text.strip)
|
360
|
+
assert_equal("subtable2 Row 1 Col1",table[2][1].table(:index,1)[1][1].text.strip)
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_each_itterator
|
364
|
+
# for WTR-324: keep Watir::Table.each from crashing when run on nested tables
|
365
|
+
table = browser.table(:index,1)
|
366
|
+
assert_equal(table.row_count, 4)
|
367
|
+
assert_equal(table.row_count_excluding_nested_tables, 2)
|
368
|
+
example_row_count = 0
|
369
|
+
assert_nothing_thrown do
|
370
|
+
table.each do
|
371
|
+
example_row_count += 1
|
372
|
+
end
|
373
|
+
end
|
374
|
+
assert_equal(example_row_count, 2)
|
375
|
+
end
|
376
|
+
end
|