Class: TestCentricity::Elements::Table

Inherits:
UIElement show all
Defined in:
lib/testcentricity_web/web_elements/table.rb

Constant Summary

Constants inherited from UIElement

UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS

Instance Attribute Summary collapse

Attributes inherited from UIElement

#alt_locator, #base_object, #context, #locator, #locator_type, #mru_driver, #mru_locator, #mru_object, #mru_parent, #name, #original_style, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#aria_autocomplete, #aria_busy?, #aria_checked?, #aria_colcount, #aria_controls, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_keyshortcuts, #aria_label, #aria_labelledby, #aria_live, #aria_modal?, #aria_multiline?, #aria_multiselectable?, #aria_orientation, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_roledescription, #aria_rowcount, #aria_selected?, #aria_sort, #aria_valuemax, #aria_valuemin, #aria_valuenow, #aria_valuetext, #clear_alt_locator, #click, #click_at, #content_editable?, #count, #crossorigin, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #draggable?, #enabled?, #exists?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_max, #get_name, #get_native_attribute, #get_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #obscured?, #required?, #reset_mru_cache, #right_click, #role, #scroll_to, #send_keys, #set, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #wait_while_busy, #width, #x, #y

Constructor Details

#initialize(name, parent, locator, context) ⇒ Table

Returns a new instance of Table.



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
44
45
# File 'lib/testcentricity_web/web_elements/table.rb', line 18

def initialize(name, parent, locator, context)
  super
  @type = :table

  table_spec = {
    table_body:    'tbody',
    table_section: nil,
    table_row:     'tr',
    table_column:  'td',
    table_header:  'thead',
    header_row:    'tr',
    header_column: 'th',
    table_footer:  'tfoot',
    footer_row:    'tr',
    footer_column: 'th',
    row_header:    nil
  }

  case @locator_type
  when :xpath
    table_spec[:tree_expand]   = "div/div[contains(@class, 'tree-plus treeclick')]"
    table_spec[:tree_collapse] = "div/div[contains(@class, 'tree-minus treeclick')]"
  when :css
    table_spec[:tree_expand]   = "div > div[class*='tree-plus treeclick']"
    table_spec[:tree_collapse] = "div > div[class*='tree-minus treeclick']"
  end
  define_table_elements(table_spec)
end

Instance Attribute Details

Returns the value of attribute footer_column.



13
14
15
# File 'lib/testcentricity_web/web_elements/table.rb', line 13

def footer_column
  @footer_column
end

Returns the value of attribute footer_row.



12
13
14
# File 'lib/testcentricity_web/web_elements/table.rb', line 12

def footer_row
  @footer_row
end

#header_columnObject

Returns the value of attribute header_column.



10
11
12
# File 'lib/testcentricity_web/web_elements/table.rb', line 10

def header_column
  @header_column
end

#header_rowObject

Returns the value of attribute header_row.



9
10
11
# File 'lib/testcentricity_web/web_elements/table.rb', line 9

def header_row
  @header_row
end

#row_headerObject

Returns the value of attribute row_header.



14
15
16
# File 'lib/testcentricity_web/web_elements/table.rb', line 14

def row_header
  @row_header
end

#table_bodyObject

Returns the value of attribute table_body.



4
5
6
# File 'lib/testcentricity_web/web_elements/table.rb', line 4

def table_body
  @table_body
end

#table_columnObject

Returns the value of attribute table_column.



7
8
9
# File 'lib/testcentricity_web/web_elements/table.rb', line 7

def table_column
  @table_column
end

Returns the value of attribute table_footer.



11
12
13
# File 'lib/testcentricity_web/web_elements/table.rb', line 11

def table_footer
  @table_footer
end

#table_headerObject

Returns the value of attribute table_header.



8
9
10
# File 'lib/testcentricity_web/web_elements/table.rb', line 8

def table_header
  @table_header
end

#table_rowObject

Returns the value of attribute table_row.



6
7
8
# File 'lib/testcentricity_web/web_elements/table.rb', line 6

def table_row
  @table_row
end

#table_sectionObject

Returns the value of attribute table_section.



5
6
7
# File 'lib/testcentricity_web/web_elements/table.rb', line 5

def table_section
  @table_section
end

#tree_collapseObject

Returns the value of attribute tree_collapse.



16
17
18
# File 'lib/testcentricity_web/web_elements/table.rb', line 16

def tree_collapse
  @tree_collapse
end

#tree_expandObject

Returns the value of attribute tree_expand.



15
16
17
# File 'lib/testcentricity_web/web_elements/table.rb', line 15

def tree_expand
  @tree_expand
end

Instance Method Details

#click_header_column(column) ⇒ Object

Click in the specified column header in a table object.

Examples:

list_table.click_header_column(3)

Parameters:

  • column (Integer)

    column number



548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/testcentricity_web/web_elements/table.rb', line 548

def click_header_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{object_ref_message}" if column > column_count
  case @locator_type
  when :xpath
    set_alt_locator("#{@locator}//#{@table_header}/#{@header_row}/#{@header_column}[#{column}]")
  when :css
    set_alt_locator("#{@locator} #{@table_header} > #{@header_row} > #{@header_column}:nth-of-type(#{column})")
  end
  click if exists?
  clear_alt_locator
end

#click_table_cell(row, column) ⇒ Object

Click in the specified cell in a table object.

Examples:

list_table.click_table_cell(3, 5)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



225
226
227
228
229
230
231
232
233
# File 'lib/testcentricity_web/web_elements/table.rb', line 225

def click_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  click
  clear_alt_locator
end

Click the link object embedded within the specified cell in a table object.

Examples:

list_table.click_table_cell_link(3, 1)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/testcentricity_web/web_elements/table.rb', line 259

def click_table_cell_link(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  saved_locator = @alt_locator
  case @locator_type
  when :xpath
    set_alt_locator("#{@alt_locator}//a")
    set_alt_locator("#{saved_locator}//span/a") unless exists?
    # if link not present, check for text entry fields and try to dismiss by tabbing out
    unless exists?
      set_alt_locator("#{saved_locator}//input")
      set_alt_locator("#{saved_locator}//textarea") unless exists?
      send_keys(:tab) if exists?
      set_alt_locator("#{saved_locator}//a")
      set_alt_locator("#{saved_locator}//span/a") unless exists?
      send_keys(:tab) unless exists?
    end
  when :css
    set_alt_locator("#{@alt_locator} a")
    set_alt_locator("#{saved_locator} span > a") unless exists?
    # if link not present, check for text entry fields and try to dismiss by tabbing out
    unless exists?
      set_alt_locator("#{saved_locator} input")
      set_alt_locator("#{saved_locator} textarea") unless exists?
      send_keys(:tab) if exists?
      set_alt_locator("#{saved_locator} a")
      set_alt_locator("#{saved_locator} span > a") unless exists?
      send_keys(:tab) unless exists?
    end
  end
  wait_until_exists(1)
  click
  clear_alt_locator
end

#collapse_table_row(row, column) ⇒ Object



653
654
655
656
657
658
659
660
661
662
663
664
665
# File 'lib/testcentricity_web/web_elements/table.rb', line 653

def collapse_table_row(row, column)
  if is_table_row_expanded?(row, column)
    set_table_cell_locator(row, column)
    case @locator_type
    when :xpath
      set_alt_locator("#{@alt_locator}/#{@tree_collapse}")
    when :css
      set_alt_locator("#{@alt_locator} > #{@tree_collapse}")
    end
    click if exists?
    clear_alt_locator
  end
end

#define_table_elements(element_spec) ⇒ Object



47
48
49
50
51
52
53
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
# File 'lib/testcentricity_web/web_elements/table.rb', line 47

def define_table_elements(element_spec)
  element_spec.each do |element, value|
    case element
    when :table_body
      @table_body = value
    when :table_section
      @table_section = value
    when :table_row
      @table_row = value
    when :table_column
      @table_column = value
    when :table_header
      @table_header = value
    when :header_row
      @header_row = value
    when :header_column
      @header_column = value
    when :table_footer
      @table_footer = value
    when :footer_row
      @footer_row = value
    when :footer_column
      @footer_column = value
    when :row_header
      @row_header = value
    when :tree_expand
      @tree_expand = value
    when :tree_collapse
      @tree_collapse = value
    else
      raise "#{element} is not a recognized table element"
    end
  end
end

#double_click_table_cell(row, column) ⇒ Object

Double-click in the specified cell in a table object.

Examples:

list_table.double_click_table_cell(3, 5)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



242
243
244
245
246
247
248
249
250
# File 'lib/testcentricity_web/web_elements/table.rb', line 242

def double_click_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  double_click
  clear_alt_locator
end

#expand_all_table_rows(column) ⇒ Object



667
668
669
670
671
672
673
674
# File 'lib/testcentricity_web/web_elements/table.rb', line 667

def expand_all_table_rows(column)
  row_count = get_row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  row_count.downto(1) do |row|
    expand_table_row(row, column)
  end
end

#expand_table_row(row, column) ⇒ Object



639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/testcentricity_web/web_elements/table.rb', line 639

def expand_table_row(row, column)
  unless is_table_row_expanded?(row, column)
    set_table_cell_locator(row, column)
    case @locator_type
    when :xpath
      set_alt_locator("#{@alt_locator}/#{@tree_expand}")
    when :css
      set_alt_locator("#{@alt_locator} > #{@tree_expand}")
    end
    click if exists?
    clear_alt_locator
  end
end

#find_in_table_column(column, search_value) ⇒ Integer

Search for the specified text value in the specified column of the table object. Returns the number of the first row that contains the search value.

Examples:

playlist_table.find_in_table_column(1, 'Ashes to Ashes')

Parameters:

  • column (Integer)

    column nummber

  • search_value (String)

    value to be searched for

Returns:

  • (Integer)

    row number of table cell that contains search value



507
508
509
510
511
512
# File 'lib/testcentricity_web/web_elements/table.rb', line 507

def find_in_table_column(column, search_value)
  (1..get_row_count).each do |row|
    return row if get_table_cell(row, column) == search_value
  end
  nil
end

#find_in_table_row(row, search_value) ⇒ Integer

Search for the specified text value in the specified row of the table object. Returns the number of the first column that contains the search value.

Examples:

bom_table.find_in_table_row(4, 'High-speed Framus bolts')

Parameters:

  • row (Integer)

    row nummber

  • search_value (String)

    value to be searched for

Returns:

  • (Integer)

    column number of table cell that contains search value



491
492
493
494
495
496
# File 'lib/testcentricity_web/web_elements/table.rb', line 491

def find_in_table_row(row, search_value)
  (1..get_column_count).each do |column|
    return column if get_table_cell(row, column) == search_value
  end
  nil
end

#find_row_attribute(attrib, search_value) ⇒ Object



475
476
477
478
479
480
# File 'lib/testcentricity_web/web_elements/table.rb', line 475

def find_row_attribute(attrib, search_value)
  (1..get_row_count).each do |row|
    return row if get_row_attribute(row, attrib) == search_value
  end
  nil
end

#get_cell_attribute(row, column, attrib) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/testcentricity_web/web_elements/table.rb', line 434

def get_cell_attribute(row, column, attrib)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  result = get_native_attribute(attrib)
  clear_alt_locator
  unless result.blank?
    if result.is_int?
      result.to_i
    elsif result.is_float?
      result.to_f
    else
      result
    end
  end
end

#get_column_countInteger

Return number of columns in a table object.

Examples:

num_columns = list_table.get_column_count

Returns:

  • (Integer)


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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/testcentricity_web/web_elements/table.rb', line 152

def get_column_count
  row_count = get_row_count
  case @locator_type
  when :xpath
    delimiter = "/"
    index = "[2]"
  when :css
    delimiter = " > "
    index = ":nth-of-type(2)"
  end
  path = if row_count.zero?
           "#{@locator}#{delimiter}#{@table_header}#{delimiter}#{@header_row}#{delimiter}#{@header_column}"
         else
           if @table_section.nil?
             if row_count == 1
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_row}#{delimiter}#{@table_column}"
             else
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_row}#{index}#{delimiter}#{@table_column}"
             end
           else
             if row_count == 1
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_section}#{delimiter}#{@table_row}#{delimiter}#{@table_column}"
             else
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_section}#{index}#{delimiter}#{@table_row}#{delimiter}#{@table_column}"
             end
           end
         end
  if @row_header.nil?
    page.all(@locator_type, path, visible: :all).count
  else
    cols = page.all(@locator_type, path, visible: :all).count

    path = if @table_section.nil?
             if row_count == 1
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_row}#{delimiter}#{@row_header}"
             else
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_row}#{index}#{delimiter}#{@row_header}"
             end
           else
             if row_count == 1
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_section}#{delimiter}#{@table_row}#{delimiter}#{@row_header}"
             else
               "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_section}#{index}#{delimiter}#{@table_row}#{delimiter}#{@row_header}"
             end
           end
    cols + page.all(@locator_type, path, visible: :all).count
  end
end


591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/testcentricity_web/web_elements/table.rb', line 591

def get_footer_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table footer #{object_ref_message}" if column > column_count
  case @locator_type
  when :xpath
    set_alt_locator("#{@locator}//#{@table_footer}/#{@footer_row}/#{@footer_column}[#{column}]")
  when :css
    set_alt_locator("#{@locator} #{@table_footer} > #{@footer_row} > #{@footer_column}:nth-of-type(#{column})")
  end
  value = get_value(:all) if exists?(:all)
  clear_alt_locator
  value
end


605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/testcentricity_web/web_elements/table.rb', line 605

def get_footer_columns
  columns = []
  column_count = get_column_count
  (1..column_count).each do |column|
    case @locator_type
    when :xpath
      set_alt_locator("#{@locator}//#{@table_footer}/#{@footer_row}/#{@footer_column}[#{column}]")
    when :css
      set_alt_locator("#{@locator} #{@table_footer} > #{@footer_row} > #{@footer_column}:nth-of-type(#{column})")
    end
    columns.push(get_value(:all)) if exists?(:all)
  end
  clear_alt_locator
  columns
end

#get_header_column(column) ⇒ Object



561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/testcentricity_web/web_elements/table.rb', line 561

def get_header_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{object_ref_message}" if column > column_count
  case @locator_type
  when :xpath
    set_alt_locator("#{@locator}//#{@table_header}/#{@header_row}/#{@header_column}[#{column}]")
  when :css
    set_alt_locator("#{@locator} #{@table_header} > #{@header_row} > #{@header_column}:nth-of-type(#{column})")
  end
  value = get_value(:all) if exists?(:all)
  clear_alt_locator
  value
end

#get_header_columnsObject



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/testcentricity_web/web_elements/table.rb', line 575

def get_header_columns
  columns = []
  column_count = get_column_count
  (1..column_count).each do |column|
    case @locator_type
    when :xpath
      set_alt_locator("#{@locator}//#{@table_header}/#{@header_row}/#{@header_column}[#{column}]")
    when :css
      set_alt_locator("#{@locator} #{@table_header} > #{@header_row} > #{@header_column}:nth-of-type(#{column})")
    end
    columns.push(get_value(:all)) if exists?(:all)
  end
  clear_alt_locator
  columns
end

#get_row_attribute(row, attrib) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/testcentricity_web/web_elements/table.rb', line 453

def get_row_attribute(row, attrib)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  case @locator_type
  when :xpath
    set_alt_locator("#{@locator}/#{@table_body}/#{@table_row}[#{row}]")
  when :css
    set_alt_locator("#{@locator} > #{@table_body} > #{@table_row}:nth-of-type(#{row})")
  end
  result = get_native_attribute(attrib)
  clear_alt_locator
  unless result.blank?
    if result.is_int?
      result.to_i
    elsif result.is_float?
      result.to_f
    else
      result
    end
  end
end

#get_row_countInteger

Return number of rows in a table object.

Examples:

num_rows = list_table.get_row_count

Returns:

  • (Integer)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/testcentricity_web/web_elements/table.rb', line 88

def get_row_count
  wait_until_exists(5)
  delimiter = case @locator_type
              when :xpath
                "/"
              when :css
                " > "
              end
  path = if @table_section.nil?
           "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_row}"
         else
           "#{@locator}#{delimiter}#{@table_body}#{delimiter}#{@table_section}"
         end
  page.all(@locator_type, path, visible: :all).count
end

#get_row_data(row) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/testcentricity_web/web_elements/table.rb', line 327

def get_row_data(row)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  case @locator_type
  when :xpath
    set_alt_locator("#{@locator}/#{@table_body}/#{@table_row}[#{row}]")
  when :css
    set_alt_locator("#{@locator} > #{@table_body} > #{@table_row}:nth-of-type(#{row})")
  end
  value = get_value if exists?
  clear_alt_locator
  value
end

#get_table_cell(row, column) ⇒ String

Return text contained in specified cell of a table object.

Examples:

list_table.get_table_cell(4, 5)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number

Returns:

  • (String)

    value of table cell



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/testcentricity_web/web_elements/table.rb', line 379

def get_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  saved_locator = @alt_locator
  case @locator_type
  when :xpath
    set_alt_locator("#{saved_locator}//input")
    unless exists?
      set_alt_locator("#{saved_locator}//textarea")
      set_alt_locator(saved_locator) unless exists?
    end
  when :css
    set_alt_locator("#{saved_locator} input")
    unless exists?
      set_alt_locator("#{saved_locator} textarea")
      set_alt_locator(saved_locator) unless exists?
    end
  end
  if exists?
    value = get_value
  else
    puts "Could not find table cell at #{@alt_locator}"
    value = ''
  end
  clear_alt_locator
  value
end

#get_table_cell_locator(row, column) ⇒ Object



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'lib/testcentricity_web/web_elements/table.rb', line 676

def get_table_cell_locator(row, column)
  case @locator_type
  when :xpath
    if @table_section.nil?
      row_spec = "#{@locator}/#{@table_body}/#{@table_row}"
      row_spec = "#{row_spec}[#{row}]"
    else
      row_spec = "#{@locator}/#{@table_body}/#{@table_section}"
      row_spec = "#{row_spec}[#{row}]/#{@table_row}[1]"
    end
    column_spec = if @row_header.nil?
                    "/#{@table_column}[#{column}]"
                  else
                    if column == 1
                      "/#{@row_header}"
                    else
                      "/#{@table_column}[#{column - 1}]"
                    end
                  end
  when :css
    if @table_section.nil?
      row_spec = "#{@locator} > #{@table_body} > #{@table_row}"
      row_spec = "#{row_spec}:nth-of-type(#{row})"
    else
      row_spec = "#{@locator} > #{@table_body} > #{@table_section}"
      row_spec = "#{row_spec}:nth-of-type(#{row}) > #{@table_row}:nth-of-type(1)"
    end

    column_spec = if @row_header.nil?
                    " > #{@table_column}:nth-of-type(#{column})"
                  else
                    if column == 1
                      " > #{@row_header}"
                    else
                      " > #{@table_column}:nth-of-type(#{column - 1})"
                    end
                  end
  end
  "#{row_spec}#{column_spec}"
end

#get_table_column(column) ⇒ Object



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
# File 'lib/testcentricity_web/web_elements/table.rb', line 341

def get_table_column(column)
  rows = []
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  row_count = get_row_count
  (1..row_count).each do |row|
    value = ''
    set_table_cell_locator(row, column)
    saved_locator = @alt_locator
    case @locator_type
    when :xpath
      set_alt_locator("#{saved_locator}//input")
      unless exists?
        set_alt_locator("#{saved_locator}//textarea")
        set_alt_locator(saved_locator) unless exists?
      end
    when :css
      set_alt_locator("#{saved_locator} input")
      unless exists?
        set_alt_locator("#{saved_locator} textarea")
        set_alt_locator(saved_locator) unless exists?
      end
    end
    value = get_value if exists?
    rows.push(value)
  end
  clear_alt_locator
  rows
end

#get_table_row(row) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/testcentricity_web/web_elements/table.rb', line 297

def get_table_row(row)
  columns = []
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  (1..column_count).each do |column|
    value = ''
    set_table_cell_locator(row, column)
    saved_locator = @alt_locator
    case @locator_type
    when :xpath
      set_alt_locator("#{saved_locator}//input")
      unless exists?
        set_alt_locator("#{saved_locator}//textarea")
        set_alt_locator(saved_locator) unless exists?
      end
    when :css
      set_alt_locator("#{saved_locator} input")
      unless exists?
        set_alt_locator("#{saved_locator} textarea")
        set_alt_locator(saved_locator) unless exists?
      end
    end
    value = get_value if exists?
    columns.push(value)
  end
  clear_alt_locator
  columns
end

#hover_table_cell(row, column) ⇒ Object

Hover over the specified cell in a table object.

Examples:

list_table.hover_table_cell(2, 6)

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number



208
209
210
211
212
213
214
215
216
# File 'lib/testcentricity_web/web_elements/table.rb', line 208

def hover_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  hover
  clear_alt_locator
end

#is_table_row_expanded?(row, column) ⇒ Boolean

Returns:

  • (Boolean)


621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/testcentricity_web/web_elements/table.rb', line 621

def is_table_row_expanded?(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{object_ref_message}" if column > column_count
  set_table_cell_locator(row, column)
  case @locator_type
  when :xpath
    set_alt_locator("#{@alt_locator}/#{@tree_expand}")
  when :css
    set_alt_locator("#{@alt_locator} > #{@tree_expand}")
  end
  expanded = true
  expanded = false if exists?
  clear_alt_locator
  expanded
end

#populate_table_row(row, data) ⇒ Object

Populate the specified row of this table object with the associated data from a Hash passed as an argument. Data values must be in the form of a String for textfield and select list controls. For checkbox and radio buttons, data must either be a Boolean or a String that evaluates to a Boolean value (Yes, No, 1, 0, true, false)

Examples:

data = { 1 => 'Dr.',
         2 => 'Evangeline',
         3 => 'Devereaux',
         4 => 'MD',
         5 => 'Family Practice'
       }
clinicians_table.populate_table_row(3, data)

Parameters:

  • data (Hash)

    column numbers and associated data to be entered



529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/testcentricity_web/web_elements/table.rb', line 529

def populate_table_row(row, data)
  wait_until_exists(2)
  data.each do |column, data_param|
    unless data_param.blank?
      if data_param == '!DELETE'
        set_table_cell(row, column, '')
      else
        set_table_cell(row, column, data_param)
      end
    end
  end
end

#set_table_cell(row, column, value) ⇒ Object

Set the value of the specified cell in a table object.

Examples:

list_table.set_table_cell(3, 1, 'Ontario')

Parameters:

  • row (Integer)

    row number

  • column (Integer)

    column number

  • value (String)

    text to set



425
426
427
428
429
430
431
432
# File 'lib/testcentricity_web/web_elements/table.rb', line 425

def set_table_cell(row, column, value)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{object_ref_message}" if row > row_count
  find_table_cell(row, column)
  find_table_cell(row, column) unless exists?
  set(value)
  clear_alt_locator
end

#verify_table_cell(row, column, expected, enqueue = false) ⇒ Object



410
411
412
413
414
415
# File 'lib/testcentricity_web/web_elements/table.rb', line 410

def verify_table_cell(row, column, expected, enqueue = false)
  actual = get_table_cell(row, column)
  enqueue ?
    ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected table #{object_ref_message} row #{row}/column #{column}") :
    assert_equal(expected.strip, actual.strip, "Expected table #{object_ref_message} row #{row}/column #{column} to display '#{expected}' but found '#{actual}'")
end

#wait_until_row_count_changes(seconds = nil, post_exception = true) ⇒ Object

Wait until the table's row count changes to a different value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.

Examples:

list_table.wait_until_row_count_changes(5)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/testcentricity_web/web_elements/table.rb', line 133

def wait_until_row_count_changes(seconds = nil, post_exception = true)
  value = get_row_count
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { get_row_count != value }
rescue
  if post_exception
    raise "Value of Table #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_row_count == value
  else
    get_row_count == value
  end
end

#wait_until_row_count_is(value, seconds = nil, post_exception = true) ⇒ Object

Wait until the table's row count equals the specified value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.

Examples:

list_table.wait_until_row_count_is(10, 15)
  or
list_table.wait_until_row_count_is({ greater_than_or_equal: 1 }, 5)

Parameters:

  • value (Integer or Hash)

    value expected or comparison hash

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/testcentricity_web/web_elements/table.rb', line 114

def wait_until_row_count_is(value, seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { compare(value, get_row_count) }
rescue
  if post_exception
    raise "Value of Table #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_row_count == value
  else
    get_row_count == value
  end
end