Class: TestCentricity::Table

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

Instance Attribute Summary

Attributes inherited from UIElement

#alt_locator, #context, #locator, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#clear_alt_locator, #click, #click_at, #disabled?, #double_click, #drag_by, #enabled?, #exists?, #get_list_items, #get_locator, #get_object_type, #get_siebel_object_type, #get_value, #hidden?, #hover, #invoke_siebel_dialog, #send_keys, #set, #set_alt_locator, #verify_value, #visible?, #wait_until_exists, #wait_until_gone, #wait_until_value_changes, #wait_until_value_is

Constructor Details

#initialize(parent, locator, context) ⇒ Table

Returns a new instance of Table.



3
4
5
6
7
8
9
# File 'lib/testcentricity_web/elements/table.rb', line 3

def initialize(parent, locator, context)
  @parent  = parent
  @locator = locator
  @context = context
  @type    = :table
  @alt_locator = nil
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



260
261
262
263
264
265
266
267
268
# File 'lib/testcentricity_web/elements/table.rb', line 260

def click_header_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{@locator}" if column > column_count
  (column > 1) ?
      set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
      set_alt_locator("#{@locator}/thead/tr/th")
  click
  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



47
48
49
50
51
52
53
54
55
# File 'lib/testcentricity_web/elements/table.rb', line 47

def click_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" 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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/testcentricity_web/elements/table.rb', line 81

def click_table_cell_link(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  saved_locator = @alt_locator
  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
  wait_until_exists(1)
  click
  clear_alt_locator
end

#collapse_table_row(row, column) ⇒ Object



317
318
319
320
321
322
323
324
# File 'lib/testcentricity_web/elements/table.rb', line 317

def collapse_table_row(row, column)
  if is_table_row_expanded?(row, column)
    set_table_cell_locator(row, column)
    set_alt_locator("#{@alt_locator}/div/div[contains(@class, 'tree-minus treeclick')]")
    click if exists?
    clear_alt_locator
  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



64
65
66
67
68
69
70
71
72
# File 'lib/testcentricity_web/elements/table.rb', line 64

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

#expand_all_table_rows(column) ⇒ Object



326
327
328
329
330
331
332
333
# File 'lib/testcentricity_web/elements/table.rb', line 326

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 #{@locator}" if column > column_count
  row_count.downto(1) do |row|
    expand_table_row(row, column)
  end
end

#expand_table_row(row, column) ⇒ Object



308
309
310
311
312
313
314
315
# File 'lib/testcentricity_web/elements/table.rb', line 308

def expand_table_row(row, column)
  unless is_table_row_expanded?(row, column)
    set_table_cell_locator(row, column)
    set_alt_locator("#{@alt_locator}/div/div[contains(@class, 'tree-plus treeclick')]")
    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:

list_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



219
220
221
222
223
224
# File 'lib/testcentricity_web/elements/table.rb', line 219

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:

list_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



203
204
205
206
207
208
# File 'lib/testcentricity_web/elements/table.rb', line 203

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

#get_column_countInteger

Return number of columns in a table object.

Examples:

num_columns = list_table.get_column_count

Returns:

  • (Integer)


29
30
31
32
33
34
35
36
37
38
# File 'lib/testcentricity_web/elements/table.rb', line 29

def get_column_count
  row_count = get_row_count
  if row_count == 0
    page.all(:xpath, "#{@locator}/thead/tr/th", :visible => :all).count
  else
    (row_count == 1) ?
        page.all(:xpath, "#{@locator}/tbody/tr/td", :visible => :all).count :
        page.all(:xpath, "#{@locator}/tbody/tr[2]/td", :visible => :all).count
  end
end

#get_header_column(column) ⇒ Object



270
271
272
273
274
275
276
277
278
279
# File 'lib/testcentricity_web/elements/table.rb', line 270

def get_header_column(column)
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table header #{@locator}" if column > column_count
  (column > 1) ?
      set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
      set_alt_locator("#{@locator}/thead/tr/th")
  value = get_value
  clear_alt_locator
  value
end

#get_header_columnsObject



281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/testcentricity_web/elements/table.rb', line 281

def get_header_columns
  columns = []
  column_count = get_column_count
  (1..column_count).each do |column|
    (column > 1) ?
        set_alt_locator("#{@locator}/thead/tr/th[#{column}]") :
        set_alt_locator("#{@locator}/thead/tr/th")
    columns.push(get_value)
  end
  clear_alt_locator
  columns
end

#get_row_countInteger

Return number of rows in a table object.

Examples:

num_rows = list_table.get_row_count

Returns:

  • (Integer)


17
18
19
20
21
# File 'lib/testcentricity_web/elements/table.rb', line 17

def get_row_count
  wait_until_exists(5)
  row_count = page.all(:xpath, "#{@locator}/tbody/tr", :visible => :all).count
  row_count
end

#get_row_data(row) ⇒ Object



127
128
129
130
131
132
133
134
135
136
# File 'lib/testcentricity_web/elements/table.rb', line 127

def get_row_data(row)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  (row > 1) ?
      set_alt_locator("#{@locator}/tbody/tr[#{row}]") :
      set_alt_locator("#{@locator}/tbody/tr")
  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



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/testcentricity_web/elements/table.rb', line 146

def get_table_cell(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  saved_locator = @alt_locator
  set_alt_locator("#{saved_locator}/input")
  unless exists?
    set_alt_locator("#{saved_locator}/textarea")
    unless exists?
      set_alt_locator(saved_locator)
    end
  end
  value = get_value if exists?
  clear_alt_locator
  value
end

#get_table_row(row) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/testcentricity_web/elements/table.rb', line 104

def get_table_row(row)
  columns = []
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" 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
    set_alt_locator("#{saved_locator}/input")
    unless exists?
      set_alt_locator("#{saved_locator}/textarea")
      unless exists?
        set_alt_locator(saved_locator)
      end
    end
    value = get_value if exists?
    columns.push(value)
  end
  clear_alt_locator
  columns
end

#is_table_row_expanded?(row, column) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/testcentricity_web/elements/table.rb', line 295

def is_table_row_expanded?(row, column)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  column_count = get_column_count
  raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  set_alt_locator("#{@alt_locator}/div/div[contains(@class, 'tree-plus treeclick')]")
  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'
       }
clinician_table.populate_table_row(3, data)

Parameters:

  • data (Hash)

    column numbers and associated data to be entered



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

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



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/testcentricity_web/elements/table.rb', line 180

def set_table_cell(row, column, value)
  row_count = get_row_count
  raise "Row #{row} exceeds number of rows (#{row_count}) in table #{@locator}" if row > row_count
  # column_count = get_column_count
  # raise "Column #{column} exceeds number of columns (#{column_count}) in table #{@locator}" if column > column_count
  set_table_cell_locator(row, column)
  click if exists?
  saved_locator = @alt_locator
  set_alt_locator("#{saved_locator}/input")
  set_alt_locator("#{saved_locator}/textarea") unless exists?
  set(value)
  clear_alt_locator
end

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



165
166
167
168
169
170
# File 'lib/testcentricity_web/elements/table.rb', line 165

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 #{@locator} row #{row}/column #{column}") :
      assert_equal(expected.strip, actual.strip, "Expected #{@locator} row #{row}/column #{column} to display '#{expected}' but found '#{actual}'")
end