Module: Awetestlib::Regression::Tables
- Included in:
- Runner
- Defined in:
- lib/awetestlib/regression/tables.rb
Instance Method Summary collapse
- #count_data_rows(container, data_index, column_index) ⇒ Object
- #count_rows_with_string(container, table_index, strg) ⇒ Object
- #exercise_sorting(browser, columnList, desc = '') ⇒ Object (also: #validate_sorting)
- #fetch_array_for_table_column(nc_element, table_index, column_index) ⇒ Object
- #fetch_hash_for_table_column(table, column_index, start_row = 2) ⇒ Object
- #get_cell_count(row) ⇒ Object
- #get_cell_text_from_row_with_string(nc_element, table_index, column_index, strg) ⇒ Object
- #get_column_index(table, strg, desc = '', header = false) ⇒ Object
- #get_index_for_column_head(panel, table_index, strg, desc = '') ⇒ Object
- #get_index_for_table_containing_text(browser, strg, ordinal = 1) ⇒ Object
- #get_index_of_last_row(table, pad = 2, every = 1) ⇒ Object (also: #get_index_for_last_row)
- #get_index_of_last_row_with_text(table, strg, column_index = nil) ⇒ Object (also: #get_index_for_last_row_with_text)
- #get_index_of_row_with_text(table, strg, column_index = nil, fail_if_found = false) ⇒ Object
- #get_index_of_row_with_textfield_value(table, strg, how, what, column_index = nil) ⇒ Object
- #get_row_cells_text_as_array(row) ⇒ Object
- #get_table_containing_text(browser, strg, ordinal = 1) ⇒ Object
-
#verify_column_hidden(browser, panel, table_index, column_name) ⇒ Object
TODO unstub.
-
#verify_column_hidden_temp_ff(browser, data_index, row_index, column_name) ⇒ Object
TODO unstub.
- #verify_column_order(browser, table_index, row_index, exp_ary) ⇒ Object
- #verify_column_sort(browser, nc_element, strg, table_index, column_index = nil) ⇒ Object
- #verify_column_sort_temp_ff(browser, strg, table_index, column_index = nil) ⇒ Object
-
#verify_column_visible(browser, panel, table_index, column_name) ⇒ Object
TODO unstub.
-
#verify_column_visible_temp_ff(browser, data_index, row_index, column_name) ⇒ Object
TODO unstub.
Instance Method Details
#count_data_rows(container, data_index, column_index) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/awetestlib/regression/tables.rb', line 297 def count_data_rows(container, data_index, column_index) cnt = 0 # get_objects(container, :tables, true) table = container.tables[data_index] dump_table_and_rows(table) if table table.rows.each do |row| if get_cell_count(row) >= column_index #TODO this assumes column 1 is a number column if row[column_index].text =~ /\d+/ cnt += 1 end end end end sleep_for(2) cnt end |
#count_rows_with_string(container, table_index, strg) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/awetestlib/regression/tables.rb', line 244 def count_rows_with_string(container, table_index, strg) hit = 0 container.tables[table_index].each do |row| if get_cell_count(row) >= 1 # debug_to_log("#{__method__}: #{row.text}") #TODO this assumes column 1 is a number column if row[1].text =~ /\d+/ if row.text =~ /#{strg}/i hit += 1 debug_to_log("#{__method__}: #{row.text}") end end end end debug_to_log("#{__method__}: hit row count: #{hit}") hit end |
#exercise_sorting(browser, columnList, desc = '') ⇒ Object Also known as: validate_sorting
324 325 326 327 328 329 330 331 |
# File 'lib/awetestlib/regression/tables.rb', line 324 def exercise_sorting(browser, columnList, desc = '') #TODO put rescue inside the do loop #parameters: browser and a list of column link text values #example: exercise_sorting(browser,['Division', 'Payee', 'Date'], 'Sortable columns on this page') columnList.each do |column| click(browser, :link, :text, column, desc) end end |
#fetch_array_for_table_column(nc_element, table_index, column_index) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/awetestlib/regression/tables.rb', line 262 def fetch_array_for_table_column(nc_element, table_index, column_index) ary = [] nc_element.tables[table_index].each do |row| if get_cell_count(row) >= column_index #TODO this assumes column 1 is a number column if row[1].text =~ /\d+/ ary << row[column_index].text end end end return ary f end |
#fetch_hash_for_table_column(table, column_index, start_row = 2) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/awetestlib/regression/tables.rb', line 275 def fetch_hash_for_table_column(table, column_index, start_row = 2) hash = Hash.new row_count = 0 table.each do |row| row_count += 1 if get_cell_count(row) >= column_index if row_count >= start_row hash[row_count] = row[column_index].text end end end hash end |
#get_cell_count(row) ⇒ Object
316 317 318 319 320 321 322 |
# File 'lib/awetestlib/regression/tables.rb', line 316 def get_cell_count(row) # if @browserAbbrev == 'IE' or $use_firewatir row.cells.length # else # row.cell_count # end end |
#get_cell_text_from_row_with_string(nc_element, table_index, column_index, strg) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/awetestlib/regression/tables.rb', line 222 def get_cell_text_from_row_with_string(nc_element, table_index, column_index, strg) rgx = Regexp.new(strg) text = '' debug_to_log("strg:'#{strg}', rgx:'#{rgx}', table_index:'#{table_index}', column_index:'#{column_index}'") nc_element.tables[table_index].each do |row| cell_count = get_cell_count(row) if cell_count >= column_index #TODO this assumes column 1 is a number column # debug_to_log("row:'#{row.cells}'") cell_1 = row[1].text if cell_1 =~ /\d+/ row_text = row.text if row_text =~ rgx text = row[column_index].text break end end end end text end |
#get_column_index(table, strg, desc = '', header = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/awetestlib/regression/tables.rb', line 10 def get_column_index(table, strg, desc = '', header = false) msg = "Get index of " msg << " header" if header msg << " column containing #{strg}. " msg << " #{desc}" if desc.length > 0 rgx = Regexp.new(strg) row_idx = 0 index = -1 found = false table.each do |row| row_idx += 1 if row.text =~ rgx col_idx = 1 row.each do |cell| if cell.text =~ rgx index = col_idx found = true break end col_idx += 1 end end break if found or header end if found passed_to_log("#{msg} at index #{index}.") index else failed_to_log("#{msg}") nil end rescue failed_to_log("Unable to #{msg} '#{$!}'") end |
#get_index_for_column_head(panel, table_index, strg, desc = '') ⇒ Object
5 6 7 8 |
# File 'lib/awetestlib/regression/tables.rb', line 5 def get_index_for_column_head(panel, table_index, strg, desc = '') table = panel.tables[table_index] get_column_index(table, strg, desc, true) end |
#get_index_for_table_containing_text(browser, strg, ordinal = 1) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/awetestlib/regression/tables.rb', line 184 def get_index_for_table_containing_text(browser, strg, ordinal = 1) msg = "Get index for table containing text '#{strg}'" index = 0 found = 0 browser.tables.each do |t| index += 1 if t.text =~ /#{strg}/ found += 1 if ordinal > 0 and found == ordinal break end end end if found passed_to_log("#{msg}: #{index}") index else passed_to_log("#{msg}.") nil end rescue failed_to_log("Unable to find index of table containing text '#{strg}' '#{$!}' ") end |
#get_index_of_last_row(table, pad = 2, every = 1) ⇒ Object Also known as: get_index_for_last_row
45 46 47 48 49 50 |
# File 'lib/awetestlib/regression/tables.rb', line 45 def get_index_of_last_row(table, pad = 2, every = 1) index = calc_index(table.row_count, every) index = index.to_s.rjust(pad, '0') #debug_to_log("#{__method__}: index='#{index}' row_count=#{table.row_count} pad=#{pad} every=#{every}") index end |
#get_index_of_last_row_with_text(table, strg, column_index = nil) ⇒ Object Also known as: get_index_for_last_row_with_text
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/awetestlib/regression/tables.rb', line 54 def get_index_of_last_row_with_text(table, strg, column_index = nil) debug_to_log("#{__method__}: #{get_callers(5)}") msg = "Find last row in table :id=#{table.id} with text '#{strg}'" msg << " in column #{column_index}" if column_index dbg = "#{__method__}: #{table.id} text by row " dbg << "in column #{column_index}" if column_index index = 0 found = false at_index = 0 #row_count = table.row_count table.rows.each do |row| cell_count = get_cell_count(row) index += 1 text = '' if column_index col_idx = column_index.to_i if cell_count >= col_idx text = row[col_idx].text end else text = row.text end dbg << "\n#{index}. [#{text}]" if text =~ /#{strg}/ found = true at_index = index end end debug_to_log(dbg) if found passed_to_log("#{msg} at index #{index}.") at_index else failed_to_log("#{msg}") nil end rescue failed_to_log("Unable to #{msg}. '#{$!}'") end |
#get_index_of_row_with_text(table, strg, column_index = nil, fail_if_found = false) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/awetestlib/regression/tables.rb', line 96 def get_index_of_row_with_text(table, strg, column_index = nil, fail_if_found = false) debug_to_log("#{__method__}: #{get_callers(5)}") if fail_if_found msg = 'No ' else msg = 'Find ' end msg << "row in table :id=#{table.id} with text '#{strg}'" msg << " in column #{column_index}" if column_index dbg = "#{__method__}: #{table.id} text by row " dbg << "in column #{column_index}" if column_index index = 0 found = false table.rows.each do |row| cell_count = row.cells.length index += 1 text = '' if column_index col_idx = column_index.to_i if cell_count >= col_idx text = row[col_idx].text end else text = row.text end dbg << "\n#{index}. [#{text}]" if text =~ /#{strg}/ found = true break end end debug_to_log(dbg) if found if fail_if_found failed_to_log("#{msg} at index #{index}.") else passed_to_log("#{msg} at index #{index}.") end index else if fail_if_found passed_to_log("#{msg}") else failed_to_log("#{msg}") end nil end rescue failed_to_log("Unable to #{msg}. '#{$!}'") end |
#get_index_of_row_with_textfield_value(table, strg, how, what, column_index = nil) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/awetestlib/regression/tables.rb', line 147 def get_index_of_row_with_textfield_value(table, strg, how, what, column_index = nil) msg = "Find row in table :id=#{table.id} with value '#{strg}' in text_field #{how}=>'#{what} " msg << " in column #{column_index}" if column_index index = 0 found = false table.rows.each do |row| cell_count = get_cell_count(row) index += 1 text = '' if column_index col_idx = column_index.to_i if cell_count >= col_idx if row[col_idx].text_field(how, what).exists? value = row[col_idx].text_field(how, what).value end end else if row.text_field(how, what).exists? value = row.text_field(how, what).value sleep(0.25) end end if value and value =~ /#{strg}/ found = true break end end if found passed_to_log("#{msg} at index #{index}.") else failed_to_log("#{msg}") end index rescue failed_to_log("Unable to #{msg}. '#{$!}'") end |
#get_row_cells_text_as_array(row) ⇒ Object
289 290 291 292 293 294 295 |
# File 'lib/awetestlib/regression/tables.rb', line 289 def get_row_cells_text_as_array(row) ary = [] row.each do |cell| ary << cell.text end ary end |
#get_table_containing_text(browser, strg, ordinal = 1) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/awetestlib/regression/tables.rb', line 208 def get_table_containing_text(browser, strg, ordinal = 1) msg = "Get table #{ordinal} containing text '#{strg}'" index = get_index_for_table_containing_text(browser, strg, ordinal) if index passed_to_log(msg) browser.tables[index] else failed_to_log(msg) nil end rescue failed_to_log("Unable to find index of table containing text '#{strg}' '#{$!}' ") end |
#verify_column_hidden(browser, panel, table_index, column_name) ⇒ Object
TODO unstub
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/awetestlib/regression/tables.rb', line 411 def verify_column_hidden(browser, panel, table_index, column_name) passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.") return true # id = @column_data_display_ids[column_name] # ok = false # row = panel.tables[2][3] # row.each do |cell| ## strg = cell.to_s ## insp = cell.inspect ## ole = cell.ole_object ## anId = cell.attribute_value(:id) # text = cell.text # if text =~ /#{id}/ # if cell.to_s =~ /hidden/ # passed_to_log( "Column '#{column_name}' is hidden.") # else # failed_to_log( "Column '#{column_name}' is not hidden.") # end # ok = true # end # end # if not ok # failed_to_log( "Column '#{column_name}' not found.") # end # rescue # failed_to_log("Unable to verify column '#{column_name}' is hidden: '#{$!}' (#{__LINE__})") end |
#verify_column_hidden_temp_ff(browser, data_index, row_index, column_name) ⇒ Object
TODO unstub
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/awetestlib/regression/tables.rb', line 442 def verify_column_hidden_temp_ff(browser, data_index, row_index, column_name) passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.") return true row = browser.tables[data_index][row_index] # debug_to_log( "#{row.to_a}") #TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes act_ary = get_row_cells_text_as_array(row) if not act_ary.include?(column_name) passed_to_log("Column '#{column_name}' is hidden.") else failed_to_log("Column '#{column_name}' is not hidden.") end end |
#verify_column_order(browser, table_index, row_index, exp_ary) ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/awetestlib/regression/tables.rb', line 500 def verify_column_order(browser, table_index, row_index, exp_ary) mark_testlevel("Verify Column Order", 2) row = browser.tables[table_index][row_index] act_ary = get_row_cells_text_as_array(row) if exp_ary == act_ary passed_to_log("Column order [#{act_ary.join(', ')}] appeared as expected.") else failed_to_log("Column order [#{act_ary.join(', ')}] not as expected [#{exp_ary.join(', ')}].") end sleep_for(1) end |
#verify_column_sort(browser, nc_element, strg, table_index, column_index = nil) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/awetestlib/regression/tables.rb', line 335 def verify_column_sort(browser, nc_element, strg, table_index, column_index=nil) mark_testlevel("Verify Column Sort '#{strg}'", 3) if not column_index column_index = get_index_for_column_head(nc_element, table_index, strg) end if column_index bfr_ary = fetch_array_for_table_column(nc_element, table_index, column_index) if strg =~ /date/i exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) } else exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') } end if click_text(browser, strg) if column_index sleep_for(2.5) else sleep_for(1) end act_ary = fetch_array_for_table_column(nc_element, table_index, column_index) if exp_ary == act_ary passed_to_log("Click on column '#{strg}' produces expected sorted list.") true else failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.") debug_to_log("Original order ['#{bfr_ary.join("', '")}']") debug_to_log("Expected order ['#{exp_ary.join("', '")}']") debug_to_log(" Actual order ['#{act_ary.join("', '")}']") end end else failed_to_log("Unable to locate column index for '#{strg}' to verify sort.") end rescue failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}") end |
#verify_column_sort_temp_ff(browser, strg, table_index, column_index = nil) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/awetestlib/regression/tables.rb', line 374 def verify_column_sort_temp_ff(browser, strg, table_index, column_index=nil) mark_testlevel("Verify Column Sort '#{strg}'", 3) if not column_index column_index = get_index_for_column_head(browser, table_index, strg) end if column_index bfr_ary = fetch_array_for_table_column(browser, table_index, column_index) if strg =~ /date/i exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) } else exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') } end if click_text(browser, strg) sleep_for(3) act_ary = fetch_array_for_table_column(browser, table_index, column_index) if exp_ary == act_ary passed_to_log("Click on column '#{strg}' produces expected sorted list.") true else failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.") debug_to_log("Original order ['#{bfr_ary.join("', '")}']") debug_to_log("Expected order ['#{exp_ary.join("', '")}']") debug_to_log(" Actual order ['#{act_ary.join("', '")}']") end end else failed_to_log("Unable to locate column index for '#{strg}' to verify sort.") end rescue failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}") end |
#verify_column_visible(browser, panel, table_index, column_name) ⇒ Object
TODO unstub
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/awetestlib/regression/tables.rb', line 475 def verify_column_visible(browser, panel, table_index, column_name) passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.") return true # id = @column_data_display_ids[column_name] # ok = false # row = panel.tables[table_index][1] # row.each do |cell| # if cell.id == id # if not cell.to_s =~ /hidden/ # passed_to_log("Column '#{column_name}' is visible.") # else # failed_to_log("Column '#{column_name}' is not visible.") # end # ok = true # end # end # if not ok # failed_to_log("Column '#{column_name}' not found.") # end rescue failed_to_log("Unable to verify column '#{column_name} is visible': '#{$!}' (#{__LINE__})") end |
#verify_column_visible_temp_ff(browser, data_index, row_index, column_name) ⇒ Object
TODO unstub
459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/awetestlib/regression/tables.rb', line 459 def verify_column_visible_temp_ff(browser, data_index, row_index, column_name) passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.") return true row = browser.tables[data_index][row_index] #TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes act_ary = get_row_cells_text_as_array(row) if act_ary.include?(column_name) passed_to_log("Column '#{column_name}' is visible.") else failed_to_log("Column '#{column_name}' is not visible.") end end |