Class: TestCentricity::AppElements::AppTable
- Inherits:
-
AppUIElement
- Object
- AppUIElement
- TestCentricity::AppElements::AppTable
- Defined in:
- lib/testcentricity_apps/app_elements/table.rb
Instance Attribute Summary collapse
-
#table_cell ⇒ Object
Returns the value of attribute table_cell.
-
#table_column ⇒ Object
Returns the value of attribute table_column.
-
#table_header ⇒ Object
Returns the value of attribute table_header.
-
#table_header_cell ⇒ Object
Returns the value of attribute table_header_cell.
-
#table_row ⇒ Object
Returns the value of attribute table_row.
-
#table_row_expand ⇒ Object
Returns the value of attribute table_row_expand.
Attributes inherited from AppUIElement
#context, #locator, #mru_app_session, #mru_locator, #mru_object, #mru_parent, #name, #parent, #type
Instance Method Summary collapse
- #define_table_elements(element_spec) ⇒ Object
-
#double_tap_table_cell(row, column) ⇒ Object
Double-tap in the specified cell in a table object.
-
#find_in_table_column(column, search_value) ⇒ Integer
Search for the specified text value in the specified column of the table object.
-
#find_in_table_row(row, search_value) ⇒ Integer
Search for the specified text value in the specified row of the table object.
-
#get_column_count ⇒ Integer
Return number of columns in a table object.
-
#get_header_columns ⇒ Array
Return array of strings of all captions in each cell in the header of a table object.
-
#get_row_count ⇒ Integer
Return number of rows in a table object.
-
#get_table_cell(row, column) ⇒ String
Return text contained in specified cell of a table object.
-
#get_table_column(column) ⇒ Array
Return array of strings of all values in each cell in the specified column of a table object.
-
#get_table_row(row) ⇒ Array
Return array of strings of all values in each cell in the specified row of a table object.
-
#initialize(name, parent, locator, context) ⇒ AppTable
constructor
A new instance of AppTable.
-
#right_click_table_cell(row, column) ⇒ Object
Right click in the specified cell in a table object.
- #row_selected?(row) ⇒ Boolean
-
#tap_table_cell(row, column) ⇒ Object
Tap in the specified cell in a table object.
-
#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.
-
#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.
Methods inherited from AppUIElement
#clear, #click, #count, #disabled?, #double_tap, #drag_and_drop, #drag_by, #element, #enabled?, #exists?, #get_attribute, #get_caption, #get_locator, #get_name, #get_object_type, #get_value, #height, #hidden?, #hover, #id, #identifier, #long_press, #reset_mru_cache, #right_click, #scroll_into_view, #selected?, #send_keys, #set, #swipe_gesture, #tap, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #width, #x_loc, #y_loc
Constructor Details
#initialize(name, parent, locator, context) ⇒ AppTable
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 6 def initialize(name, parent, locator, context) super @type = :table table_spec = if %i[mac ios].include?(Environ.device_os) { table_row: { class: 'XCUIElementTypeTableRow' }, table_column: { class: 'XCUIElementTypeTableColumn' }, table_cell: { class_chain: '**/XCUIElementTypeCell/XCUIElementTypeStaticText' }, table_header: { class: 'XCUIElementTypeGroup' }, table_header_cell: { class: 'XCUIElementTypeButton' }, table_row_expand: { class: 'XCUIElementTypeDisclosureTriangle' }, } else { table_row: nil, table_column: nil, table_cell: nil, table_header: nil, table_header_cell: nil, table_row_expand: nil, } end define_table_elements(table_spec) end |
Instance Attribute Details
#table_cell ⇒ Object
Returns the value of attribute table_cell.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 4 def table_cell @table_cell end |
#table_column ⇒ Object
Returns the value of attribute table_column.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 4 def table_column @table_column end |
#table_header ⇒ Object
Returns the value of attribute table_header.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 4 def table_header @table_header end |
#table_header_cell ⇒ Object
Returns the value of attribute table_header_cell.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 4 def table_header_cell @table_header_cell end |
#table_row ⇒ Object
Returns the value of attribute table_row.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 4 def table_row @table_row end |
#table_row_expand ⇒ Object
Returns the value of attribute table_row_expand.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 4 def @table_row_expand end |
Instance Method Details
#define_table_elements(element_spec) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 31 def define_table_elements(element_spec) element_spec.each do |element, value| case element when :table_row @table_row = value when :table_column @table_column = value when :table_cell @table_cell = value when :table_header @table_header = value when :table_header_cell @table_header_cell = value when :table_row_expand @table_row_expand = value else raise "#{element} is not a recognized table element" end end end |
#double_tap_table_cell(row, column) ⇒ Object
Double-tap in the specified cell in a table object.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 276 def double_tap_table_cell(row, column) cell_obj = find_cell(row, column) raise "Cell [#{row}, #{column}] not found in table #{}" if cell_obj.nil? if Environ.is_macos? Environ.appium_driver.execute_script('macos: doubleClick', { elementId: cell_obj.id }) else driver.action .click_and_hold(cell_obj) .release .pause(duration: 0.2) .click_and_hold(cell_obj) .release .perform 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.
241 242 243 244 245 246 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 241 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.
225 226 227 228 229 230 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 225 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_count ⇒ Integer
Return number of columns in a table object.
72 73 74 75 76 77 78 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 72 def get_column_count obj = element object_not_found_exception(obj) col_loc = get_column_locator items = obj.find_elements(col_loc.keys[0], col_loc.values[0]) items.count end |
#get_header_columns ⇒ Array
Return array of strings of all captions in each cell in the header of a table object.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 200 def get_header_columns header = [] obj = element object_not_found_exception(obj) header_loc = get_header_locator header_obj = obj.find_element(header_loc.keys[0], header_loc.values[0]) raise "Could not find header object for table #{}" if header_obj.nil? header_cell_loc = get_header_cell_locator items = header_obj.find_elements(header_cell_loc.keys[0], header_cell_loc.values[0]) items.each do |item| header.push(item.text) end header end |
#get_row_count ⇒ Integer
Return number of rows in a table object.
58 59 60 61 62 63 64 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 58 def get_row_count obj = element object_not_found_exception(obj) row_loc = get_row_locator items = obj.find_elements(row_loc.keys[0], row_loc.values[0]) items.count end |
#get_table_cell(row, column) ⇒ String
Return text contained in specified cell of a table object.
187 188 189 190 191 192 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 187 def get_table_cell(row, column) cell_obj = find_cell(row, column) value = '' value = cell_obj.text unless cell_obj.nil? value end |
#get_table_column(column) ⇒ Array
Return array of strings of all values in each cell in the specified column of a table object.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 155 def get_table_column(column) row_data = [] column_count = get_column_count raise "Column #{column} exceeds number of columns (#{column_count}) in table #{}" if column > column_count # find table element obj = element object_not_found_exception(obj) # find all rows in table row_loc = get_row_locator rows = obj.find_elements(row_loc.keys[0], row_loc.values[0]) # find all cells in the current row cell_loc = get_cell_locator rows.each do |row| cells = row.find_elements(cell_loc.keys[0], cell_loc.values[0]) # retrieve caption from cell in specified column cell_obj = cells[column - 1] value = '' value = cell_obj.text unless cell_obj.nil? row_data.push(value) end row_data end |
#get_table_row(row) ⇒ Array
Return array of strings of all values in each cell in the specified row of a table object.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 128 def get_table_row(row) columns = [] # find table element obj = element object_not_found_exception(obj) # find all rows in table row_loc = get_row_locator rows = obj.find_elements(row_loc.keys[0], row_loc.values[0]) raise "Row #{row} exceeds number of rows (#{rows.count}) in table #{}" if row > rows.count # find all cells in the desired row row_obj = rows[row - 1] cell_loc = get_cell_locator items = row_obj.find_elements(cell_loc.keys[0], cell_loc.values[0]) # retrieve caption for each cell in table row items.each do |item| columns.push(item.text) end columns end |
#right_click_table_cell(row, column) ⇒ Object
Right click in the specified cell in a table object.
300 301 302 303 304 305 306 307 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 300 def right_click_table_cell(row, column) raise "Right click is not supported for #{Environ.device_os} platforms" unless Environ.is_macos? cell_obj = find_cell(row, column) raise "Cell [#{row}, #{column}] not found in table #{}" if cell_obj.nil? Environ.appium_driver.execute_script('macos: rightClick', { elementId: cell_obj.id }) end |
#row_selected?(row) ⇒ Boolean
309 310 311 312 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 309 def row_selected?(row) cell_obj = find_cell(row, 1) cell_obj.selected? end |
#tap_table_cell(row, column) ⇒ Object
Tap in the specified cell in a table object.
255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 255 def tap_table_cell(row, column) cell_obj = find_cell(row, column) raise "Cell [#{row}, #{column}] not found in table #{}" if cell_obj.nil? if Environ.is_macos? Environ.appium_driver.execute_script('macos: click', { elementId: cell_obj.id }) else driver.action .click_and_hold(cell_obj) .release .perform end 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 Environ.default_max_wait_time.
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 109 def wait_until_row_count_changes(seconds = nil, post_exception = true) value = get_row_count timeout = seconds.nil? ? Environ.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 #{} 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 Environ.default_max_wait_time.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/testcentricity_apps/app_elements/table.rb', line 90 def wait_until_row_count_is(value, seconds = nil, post_exception = true) timeout = seconds.nil? ? Environ.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 #{} failed to equal '#{value}' after #{timeout} seconds" unless get_row_count == value else get_row_count == value end end |