awetestlib 0.1.29pre3 → 0.1.29pre4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -8
- data/awetestlib.windows.gemspec +42 -41
- data/awetestlib_osx.gemspec +41 -47
- data/bin/awetestlib-android-setup.rb +2 -1
- data/bin/awetestlib-cucumber-setup.rb +2 -1
- data/bin/awetestlib-driver-setup.rb +1 -0
- data/bin/awetestlib-helpers.rb +2 -2
- data/bin/awetestlib-mobile-app-setup.rb +1 -0
- data/bin/awetestlib-netbeans-setup.rb +2 -1
- data/bin/awetestlib-regression-setup.rb +26 -12
- data/bin/awetestlib-rubymine-setup.rb +9 -4
- data/images/netbeans1.jpg +0 -0
- data/images/netbeans2.jpg +0 -0
- data/images/netbeans3.jpg +0 -0
- data/images/netbeans4.jpg +0 -0
- data/images/netbeans5.jpg +0 -0
- data/images/rubymine1.jpg +0 -0
- data/images/rubymine2.jpg +0 -0
- data/images/rubymine3.jpg +0 -0
- data/images/rubymine4.jpg +0 -0
- data/images/scripting1.png +0 -0
- data/images/scripting2.png +0 -0
- data/images/scripting3.png +0 -0
- data/images/scripting4.png +0 -0
- data/lib/awetestlib/logging.rb +6 -6
- data/lib/awetestlib/regression/browser.rb +15 -12
- data/lib/awetestlib/regression/drag_and_drop.rb +421 -421
- data/lib/awetestlib/regression/runner.rb +311 -307
- data/lib/awetestlib/regression/tables.rb +627 -627
- data/lib/awetestlib/regression/user_input.rb +576 -576
- data/lib/awetestlib/regression/utilities.rb +1056 -1046
- data/lib/awetestlib/regression/validations.rb +2 -1
- data/lib/version.rb +2 -2
- data/netbeans_setup.md +30 -30
- data/rubymine_setup.md +24 -24
- data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +303 -25
- metadata +160 -34
- checksums.yaml +0 -7
@@ -1,627 +1,627 @@
|
|
1
|
-
module Awetestlib
|
2
|
-
module Regression
|
3
|
-
# Methods for handling Tables, Rows, and Cells
|
4
|
-
# Rdoc work in progress
|
5
|
-
module Tables
|
6
|
-
|
7
|
-
|
8
|
-
def get_index_for_column_head(panel, table_index, strg, desc = '')
|
9
|
-
table = panel.tables[table_index]
|
10
|
-
get_column_index(table, strg, desc, true)
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_column_index(table, strg, desc = '', header = false)
|
14
|
-
msg1 = " header" if header
|
15
|
-
msg = build_message("Get index of ", msg1, " column containing #{strg}. ", desc)
|
16
|
-
rgx = Regexp.new(strg)
|
17
|
-
row_idx = 0
|
18
|
-
index = -1
|
19
|
-
found = false
|
20
|
-
table.each do |row|
|
21
|
-
row_idx += 1
|
22
|
-
if row.text =~ rgx
|
23
|
-
col_idx = 1
|
24
|
-
row.each do |cell|
|
25
|
-
if cell.text =~ rgx
|
26
|
-
index = col_idx
|
27
|
-
found = true
|
28
|
-
break
|
29
|
-
end
|
30
|
-
col_idx += 1
|
31
|
-
end
|
32
|
-
end
|
33
|
-
break if found or header
|
34
|
-
end
|
35
|
-
if found
|
36
|
-
passed_to_log("#{msg} at index #{index}.")
|
37
|
-
index
|
38
|
-
else
|
39
|
-
failed_to_log("#{msg}")
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
rescue
|
43
|
-
failed_to_log("Unable to #{msg} '#{$!}'")
|
44
|
-
end
|
45
|
-
|
46
|
-
# Return the index of the last row of the specified table.
|
47
|
-
# @param [Watir::Table] table A reference to the table in question.
|
48
|
-
# @param [Fixnum] pad The number of zeroes to prefix the index to allow correct sorting.
|
49
|
-
# @param [Fixnum] every A number indicating which rows in the table actually carry data if
|
50
|
-
# the table is padded with empty rows. 1 = every row, 2 = every other row, 3 = every third
|
51
|
-
# row, and etc.
|
52
|
-
# @return [Fixnum]
|
53
|
-
def get_index_of_last_row(table, pad = 2, every = 1)
|
54
|
-
index = calc_index(table.row_count, every)
|
55
|
-
index = index.to_s.rjust(pad, '0')
|
56
|
-
#debug_to_log("#{__method__}: index='#{index}' row_count=#{table.row_count} pad=#{pad} every=#{every}")
|
57
|
-
index
|
58
|
-
end
|
59
|
-
|
60
|
-
alias get_index_for_last_row get_index_of_last_row
|
61
|
-
|
62
|
-
# Return the index of the last row of the specified table containing *strg*
|
63
|
-
# @param [Watir::Table] table A reference to the table in question.
|
64
|
-
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
65
|
-
# @param [Fixnum] column_index A number indicating which rows the column to focus the search in.
|
66
|
-
# When not supplied, the entire row is searched for *strg*.
|
67
|
-
# @return [Fixnum]
|
68
|
-
def get_index_of_last_row_with_text(table, strg, column_index = nil)
|
69
|
-
debug_to_log("#{__method__}: #{get_callers(5)}")
|
70
|
-
msg1 = " in column #{column_index}" if column_index
|
71
|
-
msg = build_message("Find last row in table :id=#{table.id} with text '#{strg}'", msg1)
|
72
|
-
dbg = build_message("#{__method__}: #{table.id} text by row", msg1)
|
73
|
-
index = 0
|
74
|
-
found = false
|
75
|
-
at_index = 0
|
76
|
-
#row_count = table.row_count
|
77
|
-
table.rows.each do |row|
|
78
|
-
cell_count = get_cell_count(row)
|
79
|
-
index += 1
|
80
|
-
text = ''
|
81
|
-
if column_index
|
82
|
-
col_idx = column_index.to_i
|
83
|
-
if cell_count >= col_idx
|
84
|
-
text = row[col_idx].text
|
85
|
-
end
|
86
|
-
else
|
87
|
-
text = row.text
|
88
|
-
end
|
89
|
-
dbg << "\n#{index}. [#{text}]"
|
90
|
-
if text =~ /#{strg}/
|
91
|
-
found = true
|
92
|
-
at_index = index
|
93
|
-
end
|
94
|
-
end
|
95
|
-
debug_to_log(dbg)
|
96
|
-
if found
|
97
|
-
passed_to_log("#{msg} at index #{index}.")
|
98
|
-
at_index
|
99
|
-
else
|
100
|
-
failed_to_log("#{msg}")
|
101
|
-
nil
|
102
|
-
end
|
103
|
-
rescue
|
104
|
-
failed_to_log("Unable to #{msg}. '#{$!}'")
|
105
|
-
end
|
106
|
-
|
107
|
-
alias get_index_for_last_row_with_text get_index_of_last_row_with_text
|
108
|
-
|
109
|
-
# Return the index of the _first_ row of the specified table containing *strg*
|
110
|
-
# @param [Watir::Table] table A reference to the table in question.
|
111
|
-
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
112
|
-
# @param [Fixnum] column_index A number indicating which rows the column to focus the search in.
|
113
|
-
# When not supplied, the entire row is searched for *strg*.
|
114
|
-
# @param [Boolean] fail_if_found If true log a failure if *strg* _is_ found.
|
115
|
-
# @param [Fixnum] after_index Forces method to accept hit on *strg* only if it occurs
|
116
|
-
# after the row indicated by this argument. When omitted, the first hit is accepted.
|
117
|
-
# @return [Fixnum] the index of the row containing *strg*
|
118
|
-
def get_index_of_row_with_text(table, strg, column_index = nil, fail_if_found = false, after_index = nil)
|
119
|
-
debug_to_log("#{__method__}: #{get_callers(5)}")
|
120
|
-
if fail_if_found
|
121
|
-
msg = 'No '
|
122
|
-
else
|
123
|
-
msg = 'Find '
|
124
|
-
end
|
125
|
-
msg << "row in table :id=#{table.id} with text '#{strg}'"
|
126
|
-
msg << " in column #{column_index}" if column_index
|
127
|
-
dbg = "#{__method__}: #{table.id} text by row "
|
128
|
-
dbg << "in column #{column_index}" if column_index
|
129
|
-
index = 0
|
130
|
-
found = false
|
131
|
-
table.rows.each do |row|
|
132
|
-
cell_count = row.cells.length
|
133
|
-
index += 1
|
134
|
-
text = ''
|
135
|
-
if column_index
|
136
|
-
col_idx = column_index.to_i
|
137
|
-
if cell_count >= col_idx
|
138
|
-
text = row[col_idx].text
|
139
|
-
end
|
140
|
-
else
|
141
|
-
text = row.text
|
142
|
-
end
|
143
|
-
dbg << "\n#{index}. [#{text}]"
|
144
|
-
if text =~ /#{strg}/
|
145
|
-
if after_index and index > after_index
|
146
|
-
found = true
|
147
|
-
break
|
148
|
-
else
|
149
|
-
found = true
|
150
|
-
break
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
debug_to_log(dbg)
|
155
|
-
if found
|
156
|
-
if fail_if_found
|
157
|
-
failed_to_log("#{msg} at index #{index}.")
|
158
|
-
else
|
159
|
-
passed_to_log("#{msg} at index #{index}.")
|
160
|
-
end
|
161
|
-
index
|
162
|
-
else
|
163
|
-
if fail_if_found
|
164
|
-
passed_to_log("#{msg}")
|
165
|
-
else
|
166
|
-
failed_to_log("#{msg}")
|
167
|
-
end
|
168
|
-
nil
|
169
|
-
end
|
170
|
-
rescue
|
171
|
-
failed_to_log("Unable to #{msg}. '#{$!}'")
|
172
|
-
end
|
173
|
-
|
174
|
-
# Return the index of the _first_ row of the specified table containing *strg* in a text field
|
175
|
-
# identified by *how* and *what*.
|
176
|
-
# @param [Watir::Table] table A reference to the table in question.
|
177
|
-
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
178
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
179
|
-
# Valid values depend on the kind of element.
|
180
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
181
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
182
|
-
# @param [Fixnum] column_index A number indicating which rows the column to focus the search in.
|
183
|
-
# When not supplied, the entire row is searched for *strg*.
|
184
|
-
# @return [Fixnum] the index of the row containing *strg*
|
185
|
-
def get_index_of_row_with_textfield_value(table, strg, how, what, column_index = nil)
|
186
|
-
msg = "Find row in table :id=#{table.id} with value '#{strg}' in text_field #{how}=>'#{what} "
|
187
|
-
msg << " in column #{column_index}" if column_index
|
188
|
-
index = 0
|
189
|
-
found = false
|
190
|
-
table.rows.each do |row|
|
191
|
-
cell_count = get_cell_count(row)
|
192
|
-
index += 1
|
193
|
-
text = ''
|
194
|
-
if column_index
|
195
|
-
col_idx = column_index.to_i
|
196
|
-
if cell_count >= col_idx
|
197
|
-
if row[col_idx].text_field(how, what).exists?
|
198
|
-
value = row[col_idx].text_field(how, what).value
|
199
|
-
end
|
200
|
-
end
|
201
|
-
else
|
202
|
-
if row.text_field(how, what).exists?
|
203
|
-
value = row.text_field(how, what).value
|
204
|
-
sleep(0.25)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
if value and value =~ /#{strg}/
|
208
|
-
found = true
|
209
|
-
break
|
210
|
-
end
|
211
|
-
end
|
212
|
-
if found
|
213
|
-
passed_to_log("#{msg} at index #{index}.")
|
214
|
-
else
|
215
|
-
failed_to_log("#{msg}")
|
216
|
-
end
|
217
|
-
index
|
218
|
-
rescue
|
219
|
-
failed_to_log("Unable to #{msg}. '#{$!}'")
|
220
|
-
end
|
221
|
-
|
222
|
-
# Return the index of a table in *browser* containing *strg*. *ordinal* indicates
|
223
|
-
# whether it is the first, second, third, etc. table found with the matching text in *strg*
|
224
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
225
|
-
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
226
|
-
# @param [Fixnum] ordinal A number indicating which matching table will have its index returned.
|
227
|
-
# @return [Fixnum] the index of the table containing *strg*
|
228
|
-
def get_index_for_table_containing_text(browser, strg, ordinal = 1)
|
229
|
-
msg = "Get index for table containing text '#{strg}'"
|
230
|
-
index = 0
|
231
|
-
found = 0
|
232
|
-
browser.tables.each do |t|
|
233
|
-
index += 1
|
234
|
-
if t.text =~ /#{strg}/
|
235
|
-
found += 1
|
236
|
-
if ordinal > 0 and found == ordinal
|
237
|
-
break
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
if found
|
242
|
-
passed_to_log("#{msg}: #{index}")
|
243
|
-
index
|
244
|
-
else
|
245
|
-
passed_to_log("#{msg}.")
|
246
|
-
nil
|
247
|
-
end
|
248
|
-
rescue
|
249
|
-
failed_to_log("Unable to find index of table containing text '#{strg}' '#{$!}' ")
|
250
|
-
end
|
251
|
-
|
252
|
-
# Return a reference to a table in *browser* containing *strg*. *ordinal* indicates
|
253
|
-
# whether it is the first, second, third, etc. table found with the matching text in *strg*
|
254
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
255
|
-
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
256
|
-
# @param [Fixnum] ordinal A number indicating which matching table will have its index returned.
|
257
|
-
# @return [Watir::Table] the table containing *strg*
|
258
|
-
def get_table_containing_text(browser, strg, ordinal = 1)
|
259
|
-
msg = "Get table #{ordinal} containing text '#{strg}'"
|
260
|
-
index = get_index_for_table_containing_text(browser, strg, ordinal)
|
261
|
-
if index
|
262
|
-
passed_to_log(msg)
|
263
|
-
browser.tables[index]
|
264
|
-
else
|
265
|
-
failed_to_log(msg)
|
266
|
-
nil
|
267
|
-
end
|
268
|
-
rescue
|
269
|
-
failed_to_log("Unable to find index of table containing text '#{strg}' '#{$!}' ")
|
270
|
-
end
|
271
|
-
|
272
|
-
def get_cell_text_from_row_with_string(nc_element, table_index, column_index, strg)
|
273
|
-
rgx = Regexp.new(strg)
|
274
|
-
text = ''
|
275
|
-
debug_to_log("strg:'#{strg}', rgx:'#{rgx}', table_index:'#{table_index}', column_index:'#{column_index}'")
|
276
|
-
nc_element.tables[table_index].each do |row|
|
277
|
-
cell_count = get_cell_count(row)
|
278
|
-
if cell_count >= column_index
|
279
|
-
#TODO this assumes column 1 is a number column
|
280
|
-
# debug_to_log("row:'#{row.cells}'")
|
281
|
-
cell_1 = row[1].text
|
282
|
-
if cell_1 =~ /\d+/
|
283
|
-
row_text = row.text
|
284
|
-
if row_text =~ rgx
|
285
|
-
text = row[column_index].text
|
286
|
-
break
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
text
|
292
|
-
end
|
293
|
-
|
294
|
-
# Return a hash containing a cross reference of the header names and indexes (columns) for the specified table.
|
295
|
-
# @example
|
296
|
-
# (need example and usage)
|
297
|
-
# @param [Watir::Table] table A reference to the table.
|
298
|
-
# @param [Fixnum] header_index The index of the row containing the header names.
|
299
|
-
# @return [Hash] Two level hash of hashes. Internal hashes are 'name' which allows look-up of a column index
|
300
|
-
# by the header name, and 'index' which allows look-up of the name by the column index.
|
301
|
-
def get_table_headers(table, header_index = 1)
|
302
|
-
headers = Hash.new
|
303
|
-
headers['index'] = Hash.new
|
304
|
-
headers['name'] = Hash.new
|
305
|
-
count = 1
|
306
|
-
table[header_index].each do |cell|
|
307
|
-
if cell.text.length > 0
|
308
|
-
name = cell.text.gsub(/\s+/, ' ')
|
309
|
-
headers['index'][count] = name
|
310
|
-
headers['name'][name] = count
|
311
|
-
end
|
312
|
-
count += 1
|
313
|
-
end
|
314
|
-
#debug_to_log("#{__method__}: headers:\n#{headers.to_yaml}")
|
315
|
-
headers
|
316
|
-
rescue
|
317
|
-
failed_to_log("Unable to get content headers. '#{$!}'")
|
318
|
-
end
|
319
|
-
|
320
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
321
|
-
def count_rows_with_string(browser, table_index, strg)
|
322
|
-
hit = 0
|
323
|
-
browser.tables[table_index].each do |row|
|
324
|
-
if get_cell_count(row) >= 1
|
325
|
-
# debug_to_log("#{__method__}: #{row.text}")
|
326
|
-
#TODO this assumes column 1 is a number column
|
327
|
-
if row[1].text =~ /\d+/
|
328
|
-
if row.text =~ /#{strg}/i
|
329
|
-
hit += 1
|
330
|
-
debug_to_log("#{__method__}: #{row.text}")
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
335
|
-
debug_to_log("#{__method__}: hit row count: #{hit}")
|
336
|
-
hit
|
337
|
-
end
|
338
|
-
|
339
|
-
def fetch_array_for_table_column(table, column_index, start_row = 2)
|
340
|
-
ary = []
|
341
|
-
row_count = 0
|
342
|
-
table.each do |row|
|
343
|
-
row_count += 1
|
344
|
-
if get_cell_count(row) >= column_index
|
345
|
-
if row_count >= start_row
|
346
|
-
ary << row[column_index].text
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
ary
|
351
|
-
end
|
352
|
-
|
353
|
-
def fetch_hash_for_table_column(table, column_index, start_row = 2)
|
354
|
-
hash = Hash.new
|
355
|
-
row_count = 0
|
356
|
-
table.each do |row|
|
357
|
-
row_count += 1
|
358
|
-
if get_cell_count(row) >= column_index
|
359
|
-
if row_count >= start_row
|
360
|
-
hash[row_count] = row[column_index].text
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
hash
|
365
|
-
end
|
366
|
-
|
367
|
-
def get_row_cells_text_as_array(row)
|
368
|
-
ary = []
|
369
|
-
row.each do |cell|
|
370
|
-
ary << cell.text
|
371
|
-
end
|
372
|
-
ary
|
373
|
-
end
|
374
|
-
|
375
|
-
def count_data_rows(container, data_index, column_index)
|
376
|
-
cnt = 0
|
377
|
-
# get_objects(container, :tables, true)
|
378
|
-
table = container.tables[data_index]
|
379
|
-
dump_table_and_rows(table)
|
380
|
-
if table
|
381
|
-
table.rows.each do |row|
|
382
|
-
if get_cell_count(row) >= column_index
|
383
|
-
#TODO this assumes column 1 is a number column
|
384
|
-
if row[column_index].text =~ /\d+/
|
385
|
-
cnt += 1
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
sleep_for(2)
|
391
|
-
cnt
|
392
|
-
end
|
393
|
-
|
394
|
-
def get_cell_count(row)
|
395
|
-
if $watir_script
|
396
|
-
row.column_count
|
397
|
-
else
|
398
|
-
row.cells.length
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
def exercise_sorting(browser, columnList, desc = '')
|
403
|
-
#TODO put rescue inside the do loop
|
404
|
-
#parameters: browser and a list of column link text values
|
405
|
-
#example: exercise_sorting(browser,['Division', 'Payee', 'Date'], 'Sortable columns on this page')
|
406
|
-
columnList.each do |column|
|
407
|
-
click(browser, :link, :text, column, desc)
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
alias validate_sorting exercise_sorting
|
412
|
-
|
413
|
-
def verify_column_sort(browser, nc_element, strg, table_index, column_index=nil)
|
414
|
-
mark_testlevel("Verify Column Sort '#{strg}'", 3)
|
415
|
-
if not column_index
|
416
|
-
column_index = get_index_for_column_head(nc_element, table_index, strg)
|
417
|
-
end
|
418
|
-
|
419
|
-
if column_index
|
420
|
-
bfr_ary = fetch_array_for_table_column(nc_element, table_index, column_index)
|
421
|
-
if strg =~ /date/i
|
422
|
-
exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) }
|
423
|
-
else
|
424
|
-
exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') }
|
425
|
-
end
|
426
|
-
|
427
|
-
if click_text(browser, strg)
|
428
|
-
if column_index
|
429
|
-
sleep_for(2.5)
|
430
|
-
else
|
431
|
-
sleep_for(1)
|
432
|
-
end
|
433
|
-
act_ary = fetch_array_for_table_column(nc_element, table_index, column_index)
|
434
|
-
|
435
|
-
if exp_ary == act_ary
|
436
|
-
passed_to_log("Click on column '#{strg}' produces expected sorted list.")
|
437
|
-
true
|
438
|
-
else
|
439
|
-
failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.")
|
440
|
-
debug_to_log("Original order ['#{bfr_ary.join("', '")}']")
|
441
|
-
debug_to_log("Expected order ['#{exp_ary.join("', '")}']")
|
442
|
-
debug_to_log(" Actual order ['#{act_ary.join("', '")}']")
|
443
|
-
end
|
444
|
-
end
|
445
|
-
else
|
446
|
-
failed_to_log("Unable to locate column index for '#{strg}' to verify sort.")
|
447
|
-
end
|
448
|
-
rescue
|
449
|
-
failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}")
|
450
|
-
end
|
451
|
-
|
452
|
-
def verify_column_sort_temp_ff(browser, strg, table_index, column_index=nil)
|
453
|
-
mark_testlevel("Verify Column Sort '#{strg}'", 3)
|
454
|
-
|
455
|
-
if not column_index
|
456
|
-
column_index = get_index_for_column_head(browser, table_index, strg)
|
457
|
-
end
|
458
|
-
|
459
|
-
if column_index
|
460
|
-
bfr_ary = fetch_array_for_table_column(browser, table_index, column_index)
|
461
|
-
if strg =~ /date/i
|
462
|
-
exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) }
|
463
|
-
else
|
464
|
-
exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') }
|
465
|
-
end
|
466
|
-
|
467
|
-
if click_text(browser, strg)
|
468
|
-
sleep_for(3)
|
469
|
-
act_ary = fetch_array_for_table_column(browser, table_index, column_index)
|
470
|
-
|
471
|
-
if exp_ary == act_ary
|
472
|
-
passed_to_log("Click on column '#{strg}' produces expected sorted list.")
|
473
|
-
true
|
474
|
-
else
|
475
|
-
failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.")
|
476
|
-
debug_to_log("Original order ['#{bfr_ary.join("', '")}']")
|
477
|
-
debug_to_log("Expected order ['#{exp_ary.join("', '")}']")
|
478
|
-
debug_to_log(" Actual order ['#{act_ary.join("', '")}']")
|
479
|
-
end
|
480
|
-
end
|
481
|
-
else
|
482
|
-
failed_to_log("Unable to locate column index for '#{strg}' to verify sort.")
|
483
|
-
end
|
484
|
-
rescue
|
485
|
-
failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}")
|
486
|
-
end
|
487
|
-
|
488
|
-
# @todo unstub
|
489
|
-
# @private
|
490
|
-
def verify_column_hidden(browser, panel, table_index, column_name)
|
491
|
-
passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.")
|
492
|
-
return true
|
493
|
-
# id = @column_data_display_ids[column_name]
|
494
|
-
# ok = false
|
495
|
-
|
496
|
-
# row = panel.tables[2][3]
|
497
|
-
|
498
|
-
# row.each do |cell|
|
499
|
-
## strg = cell.to_s
|
500
|
-
## insp = cell.inspect
|
501
|
-
## ole = cell.ole_object
|
502
|
-
## anId = cell.attribute_value(:id)
|
503
|
-
# text = cell.text
|
504
|
-
# if text =~ /#{id}/
|
505
|
-
# if cell.to_s =~ /hidden/
|
506
|
-
# passed_to_log( "Column '#{column_name}' is hidden.")
|
507
|
-
# else
|
508
|
-
# failed_to_log( "Column '#{column_name}' is not hidden.")
|
509
|
-
# end
|
510
|
-
# ok = true
|
511
|
-
# end
|
512
|
-
# end
|
513
|
-
# if not ok
|
514
|
-
# failed_to_log( "Column '#{column_name}' not found.")
|
515
|
-
# end
|
516
|
-
# rescue
|
517
|
-
# failed_to_log("Unable to verify column '#{column_name}' is hidden: '#{$!}' (#{__LINE__})")
|
518
|
-
end
|
519
|
-
|
520
|
-
# @todo unstub
|
521
|
-
# @private
|
522
|
-
def verify_column_hidden_temp_ff(browser, data_index, row_index, column_name)
|
523
|
-
passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.")
|
524
|
-
return true
|
525
|
-
|
526
|
-
row = browser.tables[data_index][row_index]
|
527
|
-
# debug_to_log( "#{row.to_a}")
|
528
|
-
#TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes
|
529
|
-
act_ary = get_row_cells_text_as_array(row)
|
530
|
-
|
531
|
-
if not act_ary.include?(column_name)
|
532
|
-
passed_to_log("Column '#{column_name}' is hidden.")
|
533
|
-
else
|
534
|
-
failed_to_log("Column '#{column_name}' is not hidden.")
|
535
|
-
end
|
536
|
-
end
|
537
|
-
|
538
|
-
# @todo unstub
|
539
|
-
# @private
|
540
|
-
def verify_column_visible_temp_ff(browser, data_index, row_index, column_name)
|
541
|
-
passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.")
|
542
|
-
return true
|
543
|
-
|
544
|
-
row = browser.tables[data_index][row_index]
|
545
|
-
#TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes
|
546
|
-
act_ary = get_row_cells_text_as_array(row)
|
547
|
-
|
548
|
-
if act_ary.include?(column_name)
|
549
|
-
passed_to_log("Column '#{column_name}' is visible.")
|
550
|
-
else
|
551
|
-
failed_to_log("Column '#{column_name}' is not visible.")
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
# @todo unstub
|
556
|
-
# @private
|
557
|
-
def verify_column_visible(browser, panel, table_index, column_name)
|
558
|
-
|
559
|
-
passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.")
|
560
|
-
return true
|
561
|
-
|
562
|
-
# id = @column_data_display_ids[column_name]
|
563
|
-
# ok = false
|
564
|
-
# row = panel.tables[table_index][1]
|
565
|
-
# row.each do |cell|
|
566
|
-
# if cell.id == id
|
567
|
-
# if not cell.to_s =~ /hidden/
|
568
|
-
# passed_to_log("Column '#{column_name}' is visible.")
|
569
|
-
# else
|
570
|
-
# failed_to_log("Column '#{column_name}' is not visible.")
|
571
|
-
# end
|
572
|
-
# ok = true
|
573
|
-
# end
|
574
|
-
# end
|
575
|
-
# if not ok
|
576
|
-
# failed_to_log("Column '#{column_name}' not found.")
|
577
|
-
# end
|
578
|
-
rescue
|
579
|
-
failed_to_log("Unable to verify column '#{column_name} is visible': '#{$!}' (#{__LINE__})")
|
580
|
-
end
|
581
|
-
|
582
|
-
# Verify that a table's columns are in the expected order by header names. The table is identified by its *index*
|
583
|
-
# within the container *browser*.
|
584
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
585
|
-
def verify_column_order(browser, table_index, header_index, exp_ary)
|
586
|
-
mark_testlevel("Begin #{__method__.to_s.titleize}", 0)
|
587
|
-
row = browser.tables[table_index][header_index]
|
588
|
-
act_ary = get_row_cells_text_as_array(row)
|
589
|
-
|
590
|
-
if exp_ary == act_ary
|
591
|
-
passed_to_log("Column order [#{act_ary.join(', ')}] appeared as expected.")
|
592
|
-
else
|
593
|
-
failed_to_log("Column order [#{act_ary.join(', ')}] not as expected [#{exp_ary.join(', ')}].")
|
594
|
-
end
|
595
|
-
mark_testlevel("End #{__method__.to_s.titleize}", 0)
|
596
|
-
end
|
597
|
-
|
598
|
-
def text_in_table?(browser, how, what, expected, desc = '')
|
599
|
-
msg = build_message("Table :#{how}=>#{what} contains '#{expected}.", desc)
|
600
|
-
if browser.table(how, what).text =~ expected
|
601
|
-
passed_to_log(msg)
|
602
|
-
true
|
603
|
-
else
|
604
|
-
failed_to_log(msg)
|
605
|
-
end
|
606
|
-
rescue
|
607
|
-
failed_to_log("Unable to verify that #{msg}': '#{$!}'")
|
608
|
-
end
|
609
|
-
|
610
|
-
def text_in_table_row_with_text?(table, text, target, desc = '')
|
611
|
-
#TODO This needs clarification, renaming
|
612
|
-
msg = build_message("Table :id=>#{table.id} row with text '#{text} also contains '#{target}.", desc)
|
613
|
-
index = get_index_of_row_with_text(table, text)
|
614
|
-
if table[index].text =~ target
|
615
|
-
passed_to_log(msg)
|
616
|
-
true
|
617
|
-
else
|
618
|
-
failed_to_log(msg)
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
alias verify_text_in_table_with_text text_in_table_row_with_text?
|
623
|
-
|
624
|
-
end
|
625
|
-
end
|
626
|
-
end
|
627
|
-
|
1
|
+
module Awetestlib
|
2
|
+
module Regression
|
3
|
+
# Methods for handling Tables, Rows, and Cells
|
4
|
+
# Rdoc work in progress
|
5
|
+
module Tables
|
6
|
+
|
7
|
+
|
8
|
+
def get_index_for_column_head(panel, table_index, strg, desc = '')
|
9
|
+
table = panel.tables[table_index]
|
10
|
+
get_column_index(table, strg, desc, true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_column_index(table, strg, desc = '', header = false)
|
14
|
+
msg1 = " header" if header
|
15
|
+
msg = build_message("Get index of ", msg1, " column containing #{strg}. ", desc)
|
16
|
+
rgx = Regexp.new(strg)
|
17
|
+
row_idx = 0
|
18
|
+
index = -1
|
19
|
+
found = false
|
20
|
+
table.each do |row|
|
21
|
+
row_idx += 1
|
22
|
+
if row.text =~ rgx
|
23
|
+
col_idx = 1
|
24
|
+
row.each do |cell|
|
25
|
+
if cell.text =~ rgx
|
26
|
+
index = col_idx
|
27
|
+
found = true
|
28
|
+
break
|
29
|
+
end
|
30
|
+
col_idx += 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
break if found or header
|
34
|
+
end
|
35
|
+
if found
|
36
|
+
passed_to_log("#{msg} at index #{index}.")
|
37
|
+
index
|
38
|
+
else
|
39
|
+
failed_to_log("#{msg}")
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
rescue
|
43
|
+
failed_to_log("Unable to #{msg} '#{$!}'")
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the index of the last row of the specified table.
|
47
|
+
# @param [Watir::Table] table A reference to the table in question.
|
48
|
+
# @param [Fixnum] pad The number of zeroes to prefix the index to allow correct sorting.
|
49
|
+
# @param [Fixnum] every A number indicating which rows in the table actually carry data if
|
50
|
+
# the table is padded with empty rows. 1 = every row, 2 = every other row, 3 = every third
|
51
|
+
# row, and etc.
|
52
|
+
# @return [Fixnum]
|
53
|
+
def get_index_of_last_row(table, pad = 2, every = 1)
|
54
|
+
index = calc_index(table.row_count, every)
|
55
|
+
index = index.to_s.rjust(pad, '0')
|
56
|
+
#debug_to_log("#{__method__}: index='#{index}' row_count=#{table.row_count} pad=#{pad} every=#{every}")
|
57
|
+
index
|
58
|
+
end
|
59
|
+
|
60
|
+
alias get_index_for_last_row get_index_of_last_row
|
61
|
+
|
62
|
+
# Return the index of the last row of the specified table containing *strg*
|
63
|
+
# @param [Watir::Table] table A reference to the table in question.
|
64
|
+
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
65
|
+
# @param [Fixnum] column_index A number indicating which rows the column to focus the search in.
|
66
|
+
# When not supplied, the entire row is searched for *strg*.
|
67
|
+
# @return [Fixnum]
|
68
|
+
def get_index_of_last_row_with_text(table, strg, column_index = nil)
|
69
|
+
debug_to_log("#{__method__}: #{get_callers(5)}")
|
70
|
+
msg1 = " in column #{column_index}" if column_index
|
71
|
+
msg = build_message("Find last row in table :id=#{table.id} with text '#{strg}'", msg1)
|
72
|
+
dbg = build_message("#{__method__}: #{table.id} text by row", msg1)
|
73
|
+
index = 0
|
74
|
+
found = false
|
75
|
+
at_index = 0
|
76
|
+
#row_count = table.row_count
|
77
|
+
table.rows.each do |row|
|
78
|
+
cell_count = get_cell_count(row)
|
79
|
+
index += 1
|
80
|
+
text = ''
|
81
|
+
if column_index
|
82
|
+
col_idx = column_index.to_i
|
83
|
+
if cell_count >= col_idx
|
84
|
+
text = row[col_idx].text
|
85
|
+
end
|
86
|
+
else
|
87
|
+
text = row.text
|
88
|
+
end
|
89
|
+
dbg << "\n#{index}. [#{text}]"
|
90
|
+
if text =~ /#{strg}/
|
91
|
+
found = true
|
92
|
+
at_index = index
|
93
|
+
end
|
94
|
+
end
|
95
|
+
debug_to_log(dbg)
|
96
|
+
if found
|
97
|
+
passed_to_log("#{msg} at index #{index}.")
|
98
|
+
at_index
|
99
|
+
else
|
100
|
+
failed_to_log("#{msg}")
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
rescue
|
104
|
+
failed_to_log("Unable to #{msg}. '#{$!}'")
|
105
|
+
end
|
106
|
+
|
107
|
+
alias get_index_for_last_row_with_text get_index_of_last_row_with_text
|
108
|
+
|
109
|
+
# Return the index of the _first_ row of the specified table containing *strg*
|
110
|
+
# @param [Watir::Table] table A reference to the table in question.
|
111
|
+
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
112
|
+
# @param [Fixnum] column_index A number indicating which rows the column to focus the search in.
|
113
|
+
# When not supplied, the entire row is searched for *strg*.
|
114
|
+
# @param [Boolean] fail_if_found If true log a failure if *strg* _is_ found.
|
115
|
+
# @param [Fixnum] after_index Forces method to accept hit on *strg* only if it occurs
|
116
|
+
# after the row indicated by this argument. When omitted, the first hit is accepted.
|
117
|
+
# @return [Fixnum] the index of the row containing *strg*
|
118
|
+
def get_index_of_row_with_text(table, strg, column_index = nil, fail_if_found = false, after_index = nil)
|
119
|
+
debug_to_log("#{__method__}: #{get_callers(5)}")
|
120
|
+
if fail_if_found
|
121
|
+
msg = 'No '
|
122
|
+
else
|
123
|
+
msg = 'Find '
|
124
|
+
end
|
125
|
+
msg << "row in table :id=#{table.id} with text '#{strg}'"
|
126
|
+
msg << " in column #{column_index}" if column_index
|
127
|
+
dbg = "#{__method__}: #{table.id} text by row "
|
128
|
+
dbg << "in column #{column_index}" if column_index
|
129
|
+
index = 0
|
130
|
+
found = false
|
131
|
+
table.rows.each do |row|
|
132
|
+
cell_count = row.cells.length
|
133
|
+
index += 1
|
134
|
+
text = ''
|
135
|
+
if column_index
|
136
|
+
col_idx = column_index.to_i
|
137
|
+
if cell_count >= col_idx
|
138
|
+
text = row[col_idx].text
|
139
|
+
end
|
140
|
+
else
|
141
|
+
text = row.text
|
142
|
+
end
|
143
|
+
dbg << "\n#{index}. [#{text}]"
|
144
|
+
if text =~ /#{strg}/
|
145
|
+
if after_index and index > after_index
|
146
|
+
found = true
|
147
|
+
break
|
148
|
+
else
|
149
|
+
found = true
|
150
|
+
break
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
debug_to_log(dbg)
|
155
|
+
if found
|
156
|
+
if fail_if_found
|
157
|
+
failed_to_log("#{msg} at index #{index}.")
|
158
|
+
else
|
159
|
+
passed_to_log("#{msg} at index #{index}.")
|
160
|
+
end
|
161
|
+
index
|
162
|
+
else
|
163
|
+
if fail_if_found
|
164
|
+
passed_to_log("#{msg}")
|
165
|
+
else
|
166
|
+
failed_to_log("#{msg}")
|
167
|
+
end
|
168
|
+
nil
|
169
|
+
end
|
170
|
+
rescue
|
171
|
+
failed_to_log("Unable to #{msg}. '#{$!}'")
|
172
|
+
end
|
173
|
+
|
174
|
+
# Return the index of the _first_ row of the specified table containing *strg* in a text field
|
175
|
+
# identified by *how* and *what*.
|
176
|
+
# @param [Watir::Table] table A reference to the table in question.
|
177
|
+
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
178
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
179
|
+
# Valid values depend on the kind of element.
|
180
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
181
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
182
|
+
# @param [Fixnum] column_index A number indicating which rows the column to focus the search in.
|
183
|
+
# When not supplied, the entire row is searched for *strg*.
|
184
|
+
# @return [Fixnum] the index of the row containing *strg*
|
185
|
+
def get_index_of_row_with_textfield_value(table, strg, how, what, column_index = nil)
|
186
|
+
msg = "Find row in table :id=#{table.id} with value '#{strg}' in text_field #{how}=>'#{what} "
|
187
|
+
msg << " in column #{column_index}" if column_index
|
188
|
+
index = 0
|
189
|
+
found = false
|
190
|
+
table.rows.each do |row|
|
191
|
+
cell_count = get_cell_count(row)
|
192
|
+
index += 1
|
193
|
+
text = ''
|
194
|
+
if column_index
|
195
|
+
col_idx = column_index.to_i
|
196
|
+
if cell_count >= col_idx
|
197
|
+
if row[col_idx].text_field(how, what).exists?
|
198
|
+
value = row[col_idx].text_field(how, what).value
|
199
|
+
end
|
200
|
+
end
|
201
|
+
else
|
202
|
+
if row.text_field(how, what).exists?
|
203
|
+
value = row.text_field(how, what).value
|
204
|
+
sleep(0.25)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
if value and value =~ /#{strg}/
|
208
|
+
found = true
|
209
|
+
break
|
210
|
+
end
|
211
|
+
end
|
212
|
+
if found
|
213
|
+
passed_to_log("#{msg} at index #{index}.")
|
214
|
+
else
|
215
|
+
failed_to_log("#{msg}")
|
216
|
+
end
|
217
|
+
index
|
218
|
+
rescue
|
219
|
+
failed_to_log("Unable to #{msg}. '#{$!}'")
|
220
|
+
end
|
221
|
+
|
222
|
+
# Return the index of a table in *browser* containing *strg*. *ordinal* indicates
|
223
|
+
# whether it is the first, second, third, etc. table found with the matching text in *strg*
|
224
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
225
|
+
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
226
|
+
# @param [Fixnum] ordinal A number indicating which matching table will have its index returned.
|
227
|
+
# @return [Fixnum] the index of the table containing *strg*
|
228
|
+
def get_index_for_table_containing_text(browser, strg, ordinal = 1)
|
229
|
+
msg = "Get index for table containing text '#{strg}'"
|
230
|
+
index = 0
|
231
|
+
found = 0
|
232
|
+
browser.tables.each do |t|
|
233
|
+
index += 1
|
234
|
+
if t.text =~ /#{strg}/
|
235
|
+
found += 1
|
236
|
+
if ordinal > 0 and found == ordinal
|
237
|
+
break
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
if found
|
242
|
+
passed_to_log("#{msg}: #{index}")
|
243
|
+
index
|
244
|
+
else
|
245
|
+
passed_to_log("#{msg}.")
|
246
|
+
nil
|
247
|
+
end
|
248
|
+
rescue
|
249
|
+
failed_to_log("Unable to find index of table containing text '#{strg}' '#{$!}' ")
|
250
|
+
end
|
251
|
+
|
252
|
+
# Return a reference to a table in *browser* containing *strg*. *ordinal* indicates
|
253
|
+
# whether it is the first, second, third, etc. table found with the matching text in *strg*
|
254
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
255
|
+
# @param [String, Regexp] strg A string or regular expression to search for in the table..
|
256
|
+
# @param [Fixnum] ordinal A number indicating which matching table will have its index returned.
|
257
|
+
# @return [Watir::Table] the table containing *strg*
|
258
|
+
def get_table_containing_text(browser, strg, ordinal = 1)
|
259
|
+
msg = "Get table #{ordinal} containing text '#{strg}'"
|
260
|
+
index = get_index_for_table_containing_text(browser, strg, ordinal)
|
261
|
+
if index
|
262
|
+
passed_to_log(msg)
|
263
|
+
browser.tables[index]
|
264
|
+
else
|
265
|
+
failed_to_log(msg)
|
266
|
+
nil
|
267
|
+
end
|
268
|
+
rescue
|
269
|
+
failed_to_log("Unable to find index of table containing text '#{strg}' '#{$!}' ")
|
270
|
+
end
|
271
|
+
|
272
|
+
def get_cell_text_from_row_with_string(nc_element, table_index, column_index, strg)
|
273
|
+
rgx = Regexp.new(strg)
|
274
|
+
text = ''
|
275
|
+
debug_to_log("strg:'#{strg}', rgx:'#{rgx}', table_index:'#{table_index}', column_index:'#{column_index}'")
|
276
|
+
nc_element.tables[table_index].each do |row|
|
277
|
+
cell_count = get_cell_count(row)
|
278
|
+
if cell_count >= column_index
|
279
|
+
#TODO this assumes column 1 is a number column
|
280
|
+
# debug_to_log("row:'#{row.cells}'")
|
281
|
+
cell_1 = row[1].text
|
282
|
+
if cell_1 =~ /\d+/
|
283
|
+
row_text = row.text
|
284
|
+
if row_text =~ rgx
|
285
|
+
text = row[column_index].text
|
286
|
+
break
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
text
|
292
|
+
end
|
293
|
+
|
294
|
+
# Return a hash containing a cross reference of the header names and indexes (columns) for the specified table.
|
295
|
+
# @example
|
296
|
+
# (need example and usage)
|
297
|
+
# @param [Watir::Table] table A reference to the table.
|
298
|
+
# @param [Fixnum] header_index The index of the row containing the header names.
|
299
|
+
# @return [Hash] Two level hash of hashes. Internal hashes are 'name' which allows look-up of a column index
|
300
|
+
# by the header name, and 'index' which allows look-up of the name by the column index.
|
301
|
+
def get_table_headers(table, header_index = 1)
|
302
|
+
headers = Hash.new
|
303
|
+
headers['index'] = Hash.new
|
304
|
+
headers['name'] = Hash.new
|
305
|
+
count = 1
|
306
|
+
table[header_index].each do |cell|
|
307
|
+
if cell.text.length > 0
|
308
|
+
name = cell.text.gsub(/\s+/, ' ')
|
309
|
+
headers['index'][count] = name
|
310
|
+
headers['name'][name] = count
|
311
|
+
end
|
312
|
+
count += 1
|
313
|
+
end
|
314
|
+
#debug_to_log("#{__method__}: headers:\n#{headers.to_yaml}")
|
315
|
+
headers
|
316
|
+
rescue
|
317
|
+
failed_to_log("Unable to get content headers. '#{$!}'")
|
318
|
+
end
|
319
|
+
|
320
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
321
|
+
def count_rows_with_string(browser, table_index, strg)
|
322
|
+
hit = 0
|
323
|
+
browser.tables[table_index].each do |row|
|
324
|
+
if get_cell_count(row) >= 1
|
325
|
+
# debug_to_log("#{__method__}: #{row.text}")
|
326
|
+
#TODO this assumes column 1 is a number column
|
327
|
+
if row[1].text =~ /\d+/
|
328
|
+
if row.text =~ /#{strg}/i
|
329
|
+
hit += 1
|
330
|
+
debug_to_log("#{__method__}: #{row.text}")
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
debug_to_log("#{__method__}: hit row count: #{hit}")
|
336
|
+
hit
|
337
|
+
end
|
338
|
+
|
339
|
+
def fetch_array_for_table_column(table, column_index, start_row = 2)
|
340
|
+
ary = []
|
341
|
+
row_count = 0
|
342
|
+
table.each do |row|
|
343
|
+
row_count += 1
|
344
|
+
if get_cell_count(row) >= column_index
|
345
|
+
if row_count >= start_row
|
346
|
+
ary << row[column_index].text
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
ary
|
351
|
+
end
|
352
|
+
|
353
|
+
def fetch_hash_for_table_column(table, column_index, start_row = 2)
|
354
|
+
hash = Hash.new
|
355
|
+
row_count = 0
|
356
|
+
table.each do |row|
|
357
|
+
row_count += 1
|
358
|
+
if get_cell_count(row) >= column_index
|
359
|
+
if row_count >= start_row
|
360
|
+
hash[row_count] = row[column_index].text
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
hash
|
365
|
+
end
|
366
|
+
|
367
|
+
def get_row_cells_text_as_array(row)
|
368
|
+
ary = []
|
369
|
+
row.each do |cell|
|
370
|
+
ary << cell.text
|
371
|
+
end
|
372
|
+
ary
|
373
|
+
end
|
374
|
+
|
375
|
+
def count_data_rows(container, data_index, column_index)
|
376
|
+
cnt = 0
|
377
|
+
# get_objects(container, :tables, true)
|
378
|
+
table = container.tables[data_index]
|
379
|
+
dump_table_and_rows(table)
|
380
|
+
if table
|
381
|
+
table.rows.each do |row|
|
382
|
+
if get_cell_count(row) >= column_index
|
383
|
+
#TODO this assumes column 1 is a number column
|
384
|
+
if row[column_index].text =~ /\d+/
|
385
|
+
cnt += 1
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
sleep_for(2)
|
391
|
+
cnt
|
392
|
+
end
|
393
|
+
|
394
|
+
def get_cell_count(row)
|
395
|
+
if $watir_script
|
396
|
+
row.column_count
|
397
|
+
else
|
398
|
+
row.cells.length
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def exercise_sorting(browser, columnList, desc = '')
|
403
|
+
#TODO put rescue inside the do loop
|
404
|
+
#parameters: browser and a list of column link text values
|
405
|
+
#example: exercise_sorting(browser,['Division', 'Payee', 'Date'], 'Sortable columns on this page')
|
406
|
+
columnList.each do |column|
|
407
|
+
click(browser, :link, :text, column, desc)
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
alias validate_sorting exercise_sorting
|
412
|
+
|
413
|
+
def verify_column_sort(browser, nc_element, strg, table_index, column_index=nil)
|
414
|
+
mark_testlevel("Verify Column Sort '#{strg}'", 3)
|
415
|
+
if not column_index
|
416
|
+
column_index = get_index_for_column_head(nc_element, table_index, strg)
|
417
|
+
end
|
418
|
+
|
419
|
+
if column_index
|
420
|
+
bfr_ary = fetch_array_for_table_column(nc_element, table_index, column_index)
|
421
|
+
if strg =~ /date/i
|
422
|
+
exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) }
|
423
|
+
else
|
424
|
+
exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') }
|
425
|
+
end
|
426
|
+
|
427
|
+
if click_text(browser, strg)
|
428
|
+
if column_index
|
429
|
+
sleep_for(2.5)
|
430
|
+
else
|
431
|
+
sleep_for(1)
|
432
|
+
end
|
433
|
+
act_ary = fetch_array_for_table_column(nc_element, table_index, column_index)
|
434
|
+
|
435
|
+
if exp_ary == act_ary
|
436
|
+
passed_to_log("Click on column '#{strg}' produces expected sorted list.")
|
437
|
+
true
|
438
|
+
else
|
439
|
+
failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.")
|
440
|
+
debug_to_log("Original order ['#{bfr_ary.join("', '")}']")
|
441
|
+
debug_to_log("Expected order ['#{exp_ary.join("', '")}']")
|
442
|
+
debug_to_log(" Actual order ['#{act_ary.join("', '")}']")
|
443
|
+
end
|
444
|
+
end
|
445
|
+
else
|
446
|
+
failed_to_log("Unable to locate column index for '#{strg}' to verify sort.")
|
447
|
+
end
|
448
|
+
rescue
|
449
|
+
failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}")
|
450
|
+
end
|
451
|
+
|
452
|
+
def verify_column_sort_temp_ff(browser, strg, table_index, column_index=nil)
|
453
|
+
mark_testlevel("Verify Column Sort '#{strg}'", 3)
|
454
|
+
|
455
|
+
if not column_index
|
456
|
+
column_index = get_index_for_column_head(browser, table_index, strg)
|
457
|
+
end
|
458
|
+
|
459
|
+
if column_index
|
460
|
+
bfr_ary = fetch_array_for_table_column(browser, table_index, column_index)
|
461
|
+
if strg =~ /date/i
|
462
|
+
exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) }
|
463
|
+
else
|
464
|
+
exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') }
|
465
|
+
end
|
466
|
+
|
467
|
+
if click_text(browser, strg)
|
468
|
+
sleep_for(3)
|
469
|
+
act_ary = fetch_array_for_table_column(browser, table_index, column_index)
|
470
|
+
|
471
|
+
if exp_ary == act_ary
|
472
|
+
passed_to_log("Click on column '#{strg}' produces expected sorted list.")
|
473
|
+
true
|
474
|
+
else
|
475
|
+
failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.")
|
476
|
+
debug_to_log("Original order ['#{bfr_ary.join("', '")}']")
|
477
|
+
debug_to_log("Expected order ['#{exp_ary.join("', '")}']")
|
478
|
+
debug_to_log(" Actual order ['#{act_ary.join("', '")}']")
|
479
|
+
end
|
480
|
+
end
|
481
|
+
else
|
482
|
+
failed_to_log("Unable to locate column index for '#{strg}' to verify sort.")
|
483
|
+
end
|
484
|
+
rescue
|
485
|
+
failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}")
|
486
|
+
end
|
487
|
+
|
488
|
+
# @todo unstub
|
489
|
+
# @private
|
490
|
+
def verify_column_hidden(browser, panel, table_index, column_name)
|
491
|
+
passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.")
|
492
|
+
return true
|
493
|
+
# id = @column_data_display_ids[column_name]
|
494
|
+
# ok = false
|
495
|
+
|
496
|
+
# row = panel.tables[2][3]
|
497
|
+
|
498
|
+
# row.each do |cell|
|
499
|
+
## strg = cell.to_s
|
500
|
+
## insp = cell.inspect
|
501
|
+
## ole = cell.ole_object
|
502
|
+
## anId = cell.attribute_value(:id)
|
503
|
+
# text = cell.text
|
504
|
+
# if text =~ /#{id}/
|
505
|
+
# if cell.to_s =~ /hidden/
|
506
|
+
# passed_to_log( "Column '#{column_name}' is hidden.")
|
507
|
+
# else
|
508
|
+
# failed_to_log( "Column '#{column_name}' is not hidden.")
|
509
|
+
# end
|
510
|
+
# ok = true
|
511
|
+
# end
|
512
|
+
# end
|
513
|
+
# if not ok
|
514
|
+
# failed_to_log( "Column '#{column_name}' not found.")
|
515
|
+
# end
|
516
|
+
# rescue
|
517
|
+
# failed_to_log("Unable to verify column '#{column_name}' is hidden: '#{$!}' (#{__LINE__})")
|
518
|
+
end
|
519
|
+
|
520
|
+
# @todo unstub
|
521
|
+
# @private
|
522
|
+
def verify_column_hidden_temp_ff(browser, data_index, row_index, column_name)
|
523
|
+
passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.")
|
524
|
+
return true
|
525
|
+
|
526
|
+
row = browser.tables[data_index][row_index]
|
527
|
+
# debug_to_log( "#{row.to_a}")
|
528
|
+
#TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes
|
529
|
+
act_ary = get_row_cells_text_as_array(row)
|
530
|
+
|
531
|
+
if not act_ary.include?(column_name)
|
532
|
+
passed_to_log("Column '#{column_name}' is hidden.")
|
533
|
+
else
|
534
|
+
failed_to_log("Column '#{column_name}' is not hidden.")
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
# @todo unstub
|
539
|
+
# @private
|
540
|
+
def verify_column_visible_temp_ff(browser, data_index, row_index, column_name)
|
541
|
+
passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.")
|
542
|
+
return true
|
543
|
+
|
544
|
+
row = browser.tables[data_index][row_index]
|
545
|
+
#TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes
|
546
|
+
act_ary = get_row_cells_text_as_array(row)
|
547
|
+
|
548
|
+
if act_ary.include?(column_name)
|
549
|
+
passed_to_log("Column '#{column_name}' is visible.")
|
550
|
+
else
|
551
|
+
failed_to_log("Column '#{column_name}' is not visible.")
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
# @todo unstub
|
556
|
+
# @private
|
557
|
+
def verify_column_visible(browser, panel, table_index, column_name)
|
558
|
+
|
559
|
+
passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.")
|
560
|
+
return true
|
561
|
+
|
562
|
+
# id = @column_data_display_ids[column_name]
|
563
|
+
# ok = false
|
564
|
+
# row = panel.tables[table_index][1]
|
565
|
+
# row.each do |cell|
|
566
|
+
# if cell.id == id
|
567
|
+
# if not cell.to_s =~ /hidden/
|
568
|
+
# passed_to_log("Column '#{column_name}' is visible.")
|
569
|
+
# else
|
570
|
+
# failed_to_log("Column '#{column_name}' is not visible.")
|
571
|
+
# end
|
572
|
+
# ok = true
|
573
|
+
# end
|
574
|
+
# end
|
575
|
+
# if not ok
|
576
|
+
# failed_to_log("Column '#{column_name}' not found.")
|
577
|
+
# end
|
578
|
+
rescue
|
579
|
+
failed_to_log("Unable to verify column '#{column_name} is visible': '#{$!}' (#{__LINE__})")
|
580
|
+
end
|
581
|
+
|
582
|
+
# Verify that a table's columns are in the expected order by header names. The table is identified by its *index*
|
583
|
+
# within the container *browser*.
|
584
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
585
|
+
def verify_column_order(browser, table_index, header_index, exp_ary)
|
586
|
+
mark_testlevel("Begin #{__method__.to_s.titleize}", 0)
|
587
|
+
row = browser.tables[table_index][header_index]
|
588
|
+
act_ary = get_row_cells_text_as_array(row)
|
589
|
+
|
590
|
+
if exp_ary == act_ary
|
591
|
+
passed_to_log("Column order [#{act_ary.join(', ')}] appeared as expected.")
|
592
|
+
else
|
593
|
+
failed_to_log("Column order [#{act_ary.join(', ')}] not as expected [#{exp_ary.join(', ')}].")
|
594
|
+
end
|
595
|
+
mark_testlevel("End #{__method__.to_s.titleize}", 0)
|
596
|
+
end
|
597
|
+
|
598
|
+
def text_in_table?(browser, how, what, expected, desc = '')
|
599
|
+
msg = build_message("Table :#{how}=>#{what} contains '#{expected}.", desc)
|
600
|
+
if browser.table(how, what).text =~ expected
|
601
|
+
passed_to_log(msg)
|
602
|
+
true
|
603
|
+
else
|
604
|
+
failed_to_log(msg)
|
605
|
+
end
|
606
|
+
rescue
|
607
|
+
failed_to_log("Unable to verify that #{msg}': '#{$!}'")
|
608
|
+
end
|
609
|
+
|
610
|
+
def text_in_table_row_with_text?(table, text, target, desc = '')
|
611
|
+
#TODO This needs clarification, renaming
|
612
|
+
msg = build_message("Table :id=>#{table.id} row with text '#{text} also contains '#{target}.", desc)
|
613
|
+
index = get_index_of_row_with_text(table, text)
|
614
|
+
if table[index].text =~ target
|
615
|
+
passed_to_log(msg)
|
616
|
+
true
|
617
|
+
else
|
618
|
+
failed_to_log(msg)
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
alias verify_text_in_table_with_text text_in_table_row_with_text?
|
623
|
+
|
624
|
+
end
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|