@sap_oss/wdio-qmate-service 2.18.3 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Table = void 0;
7
7
  const verboseLogger_1 = require("../../helper/verboseLogger");
8
8
  const errorHandler_1 = __importDefault(require("../../helper/errorHandler"));
9
+ const tableHelper_1 = require("../../helper/tableHelper");
9
10
  /**
10
11
  * @class table
11
12
  * @memberof ui5
@@ -142,7 +143,7 @@ class Table {
142
143
  await ui5.userInteraction.click(selector);
143
144
  }
144
145
  }
145
- // =================================== OPERATIONS ===================================
146
+ // =================================== GET OPERATIONS ===================================
146
147
  /**
147
148
  * @function getTotalNumberOfRows
148
149
  * @memberOf ui5.table
@@ -160,13 +161,13 @@ class Table {
160
161
  */
161
162
  async getTotalNumberOfRows(tableSelectorOrId) {
162
163
  this.vlf.initLog(this.getTotalNumberOfRows);
163
- const ancestorSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
164
+ const ancestorSelector = await Table._resolveTableSelectorOrId(tableSelectorOrId);
164
165
  const tableTitleSelector = {
165
166
  elementProperties: {
166
167
  metadata: "sap.m.Title"
167
168
  },
168
169
  parentProperties: {
169
- metadata: "sap.m.OverflowToolbar",
170
+ metadata: "sap.m.*Toolbar",
170
171
  ancestorProperties: ancestorSelector.elementProperties
171
172
  }
172
173
  };
@@ -191,101 +192,17 @@ class Table {
191
192
  * const numberOfRows = await ui5.table.getTotalNumberOfRowsByValues(selector, ["value1", "value2"]);
192
193
  * const numberOfRows = await ui5.table.getTotalNumberOfRowsByValues(selector, "value");
193
194
  **/
194
- async getTotalNumberOfRowsByValues(tableSelectorOrId, values) {
195
+ async getTotalNumberOfRowsByValues(tableSelectorOrId, values, enableHighlighting) {
195
196
  this.vlf.initLog(this.getTotalNumberOfRowsByValues);
196
- const rowSelectors = await this.getSelectorsForRowsByValues(tableSelectorOrId, values);
197
+ const rowSelectors = await this.getSelectorsForRowsByValues(tableSelectorOrId, values, enableHighlighting);
197
198
  return rowSelectors.length;
198
199
  }
199
- /**
200
- * @function selectRowByIndex
201
- * @memberOf ui5.table
202
- * @description Selects a row in the table by its index.
203
- * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
204
- * @param {Number} index - The index of the row to select.
205
- * @example await ui5.table.selectRowByIndex("application-ReportingTask-run-component---ReportList--ReportingTable", 0);
206
- * @example const selector = {
207
- * elementProperties: {
208
- * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
209
- * metadata: "sap.ui.comp.smarttable.SmartTable",
210
- * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
211
- * }
212
- * };
213
- * await ui5.table.selectRowByIndex(selector, 0);
214
- */
215
- async selectRowByIndex(tableSelectorOrId, index) {
216
- this.vlf.initLog(this.selectRowByIndex);
217
- const ancestorSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
218
- const checkBoxSelector = {
219
- elementProperties: {
220
- metadata: "sap.m.CheckBox"
221
- },
222
- parentProperties: {
223
- metadata: Table.COLUMN_LIST_ITEM_METADATA,
224
- ancestorProperties: ancestorSelector.elementProperties
225
- }
226
- };
227
- await ui5.userInteraction.check(checkBoxSelector, index);
228
- }
229
- /**
230
- * @function openItemByIndex
231
- * @memberOf ui5.table
232
- * @description Opens the item in the table by its index.
233
- * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
234
- * @param {Number} index - The index of the item to open.
235
- * @example const selector = {
236
- * elementProperties: {
237
- * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
238
- * metadata: "sap.ui.comp.smarttable.SmartTable",
239
- * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
240
- * }
241
- * };
242
- * await ui5.table.openItemByIndex(selector, 0);
243
- * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable";
244
- * await ui5.table.openItemByIndex(id, 0);
245
- */
246
- async openItemByIndex(tableSelectorOrId, index) {
247
- this.vlf.initLog(this.openItemByIndex);
248
- const rowSelector = await this.getSelectorForRowByIndex(tableSelectorOrId, index);
249
- await ui5.userInteraction.click(rowSelector);
250
- }
251
- /**
252
- * @function openItemByValues
253
- * @memberOf ui5.table
254
- * @description Opens the item in the table containing the given values. If multiple items match, it opens the index-th item.
255
- * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
256
- * @param {String | Array<String>} values - The value(s) to match in the table rows.
257
- * @param {Number} [index=0] - The index of the matching row to consider.
258
- * @example const selector = {
259
- * elementProperties: {
260
- * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
261
- * metadata: "sap.ui.comp.smarttable.SmartTable",
262
- * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
263
- * }
264
- * };
265
- * await ui5.table.openItemByValues(selector, ["value1", "value2"]);
266
- * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable";
267
- * await ui5.table.openItemByValues(id, "value");
268
- */
269
- async openItemByValues(tableSelectorOrId, values, index = 0) {
270
- this.vlf.initLog(this.openItemByValues);
271
- const rowSelectors = await this.getSelectorsForRowsByValues(tableSelectorOrId, values);
272
- if (rowSelectors.length === 0) {
273
- return this.ErrorHandler.logException(new Error(`No items found with the provided values: ${values}.`));
274
- }
275
- else if (rowSelectors.length <= index) {
276
- return this.ErrorHandler.logException(new Error(`The index ${index} is out of bounds. The number of matching items is ${rowSelectors.length}.`));
277
- }
278
- else {
279
- const rowSelector = rowSelectors[index];
280
- await ui5.userInteraction.click(rowSelector);
281
- }
282
- }
283
200
  /**
284
201
  * @function getSelectorsForRowsByValues
285
202
  * @memberOf ui5.table
286
203
  * @description Gets the selectors of rows in the table that contain the given values. If multiple values are provided, it only returns the selectors of rows that contain all of them.
287
204
  * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
288
- * @param {string} values - The value(s) to match in the table rows.
205
+ * @param {String | Array<String>} values - The value(s) to match in the table rows.
289
206
  * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable"
290
207
  * await ui5.table.getSelectorsForRowsByValues(id, "February");
291
208
  * @example const selector = {
@@ -297,7 +214,7 @@ class Table {
297
214
  * };
298
215
  * await ui5.table.getSelectorsForRowsByValues(selector, ["January", "2022"]);
299
216
  */
300
- async getSelectorsForRowsByValues(tableSelector, values) {
217
+ async getSelectorsForRowsByValues(tableSelectorOrId, values, enableHighlighting = true) {
301
218
  this.vlf.initLog(this.getSelectorsForRowsByValues);
302
219
  if (typeof values === "string") {
303
220
  values = [values];
@@ -305,44 +222,26 @@ class Table {
305
222
  else if (!Array.isArray(values)) {
306
223
  this.ErrorHandler.logException(new Error("Invalid values provided. It should be either a string or an array of strings."));
307
224
  }
308
- const constructedTableSelector = await this._constructTableSelector(tableSelector);
309
- let filteredRowIds;
225
+ const constructedTableSelector = await this._constructTableSelector(tableSelectorOrId);
226
+ const tableMetadata = constructedTableSelector.elementProperties.metadata;
227
+ const classCode = tableHelper_1.TableHelper.serializeClass();
228
+ let filteredRowIds = null;
310
229
  try {
311
230
  // =========================== BROWSER COMMAND ===========================
312
- filteredRowIds = await util.browser.executeScript((constructedTableSelector, values, tableMetadata, smartTableMetadata) => {
313
- const table = sap.ui.getCore().getElementById(constructedTableSelector.elementProperties?.id);
314
- let items = [];
315
- if (tableMetadata === constructedTableSelector.elementProperties.metadata && table.getItems !== undefined) {
316
- items = table.getItems();
317
- }
318
- else if (tableMetadata === constructedTableSelector.elementProperties.metadata && table.getRows !== undefined) {
319
- items = table.getRows();
320
- }
321
- else if (smartTableMetadata === constructedTableSelector.elementProperties.metadata && table.getTable !== undefined && table.getTable().getItems !== undefined) {
322
- items = table.getTable().getItems();
323
- }
324
- else {
325
- return undefined;
326
- }
327
- return items.filter((item) => values.every((val) => Object.values(item.getBindingContext().getObject()).includes(val))).map((filteredItems) => filteredItems.getId());
328
- }, constructedTableSelector, values, Table.TABLE_METADATA, Table.SMART_TABLE_METADATA);
231
+ const browserCommand = `
232
+ ${classCode}
233
+ const table = TableHelper.filterTableByMetadata("${constructedTableSelector.elementProperties.id}", "${tableMetadata}", ${JSON.stringify(Table.SUPPORTED_TABLES_METADATA)});
234
+ const items = TableHelper.getItems(table);
235
+ return await TableHelper.getIdsForItemsByCellValues(items, ${JSON.stringify(values)}, ${enableHighlighting});
236
+ `;
237
+ filteredRowIds = await util.browser.executeScript(browserCommand);
329
238
  // ========================================================================
330
239
  }
331
240
  catch (error) {
332
241
  return this.ErrorHandler.logException(new Error(`Error while executing browser command: ${error}`));
333
242
  }
334
243
  if (filteredRowIds && filteredRowIds.length > 0) {
335
- const rowsSelectors = [];
336
- for (const id of filteredRowIds) {
337
- const columnListItemSelector = {
338
- elementProperties: {
339
- metadata: Table.COLUMN_LIST_ITEM_METADATA,
340
- id: id
341
- }
342
- };
343
- rowsSelectors.push(columnListItemSelector);
344
- }
345
- return rowsSelectors;
244
+ return this._constructRowSelector(filteredRowIds, tableMetadata);
346
245
  }
347
246
  else {
348
247
  return [];
@@ -365,46 +264,89 @@ class Table {
365
264
  * @example id = "application-ReportingTask-run-component---ReportList--ReportingTable"
366
265
  * const rowSelector = await ui5.table.getSelectorForRowByIndex(id, 0);
367
266
  */
368
- async getSelectorForRowByIndex(tableSelector, index) {
267
+ async getSelectorForRowByIndex(tableSelectorOrId, index) {
369
268
  this.vlf.initLog(this.getSelectorForRowByIndex);
370
- const constructedTableSelector = await this._constructTableSelector(tableSelector);
371
- let columnListItemId;
269
+ const constructedTableSelector = await this._constructTableSelector(tableSelectorOrId);
270
+ let filteredRowId;
271
+ const tableMetadata = constructedTableSelector.elementProperties.metadata;
272
+ const classCode = tableHelper_1.TableHelper.serializeClass();
372
273
  try {
373
274
  // =========================== BROWSER COMMAND ===========================
374
- columnListItemId = await util.browser.executeScript((constructedTableSelector, index, tableMetadata, smartTableMetadata) => {
375
- const table = sap.ui.getCore().getElementById(constructedTableSelector.elementProperties?.id);
376
- let items = [];
377
- if (tableMetadata === constructedTableSelector.elementProperties.metadata && table.getItems !== undefined) {
378
- items = table.getItems();
379
- }
380
- else if (tableMetadata === constructedTableSelector.elementProperties.metadata && table.getRows !== undefined) {
381
- items = table.getRows();
382
- }
383
- else if (smartTableMetadata === constructedTableSelector.elementProperties.metadata && table.getTable !== undefined && table.getTable().getItems !== undefined) {
384
- items = table.getTable().getItems();
385
- }
386
- if (!items || !items[index])
387
- return undefined;
388
- // Filter items with undefined or empty title since titles in rows/columnListItems are only used for dividers of grouped items
389
- const filteredItems = items.filter((item) => item.getTitle === undefined || item.getTitle() === "");
390
- const item = filteredItems[index];
391
- return item?.getId?.();
392
- }, constructedTableSelector, index, Table.TABLE_METADATA, Table.SMART_TABLE_METADATA);
275
+ const browserCommand = `
276
+ ${classCode}
277
+ const table = TableHelper.filterTableByMetadata("${constructedTableSelector.elementProperties.id}", "${tableMetadata}", ${JSON.stringify(Table.SUPPORTED_TABLES_METADATA)});
278
+ const items = TableHelper.getItems(table);
279
+
280
+ if (!items || !items[${index}]) return null;
281
+
282
+ const filteredItems = TableHelper.filterItemsWithoutTitle(items);
283
+ const item = filteredItems[${index}];
284
+
285
+ return item?.getId?.();
286
+ `;
287
+ filteredRowId = await util.browser.executeScript(browserCommand);
393
288
  // ========================================================================
394
289
  }
395
290
  catch (error) {
396
291
  return this.ErrorHandler.logException(new Error(`Error while executing browser command: ${error}`));
397
292
  }
398
- if (!columnListItemId) {
293
+ if (!filteredRowId) {
399
294
  return this.ErrorHandler.logException(new Error(`No item found with index ${index}.`));
400
295
  }
401
- const columnListItemSelector = {
296
+ const rowSelector = this._constructRowSelector([filteredRowId], tableMetadata);
297
+ return rowSelector[0]; // Return the first selector as we expect only one row to match the index
298
+ }
299
+ async getAllColumnValuesByName(tableSelectorOrId, columnName, scrollingEnabled) {
300
+ this.vlf.initLog(this.getAllColumnValuesByName);
301
+ const constructedTableSelector = await Table._resolveTableSelectorOrId(tableSelectorOrId);
302
+ const tableMetadata = constructedTableSelector.elementProperties.metadata;
303
+ const classCode = tableHelper_1.TableHelper.serializeClass();
304
+ let values = [];
305
+ try {
306
+ // =========================== BROWSER COMMAND ===========================
307
+ const browserCommand = `
308
+ ${classCode}
309
+ const table = TableHelper.filterTableByMetadata("${constructedTableSelector.elementProperties.id}", "${tableMetadata}", ${JSON.stringify(Table.SUPPORTED_TABLES_METADATA)});
310
+ return await TableHelper.getAllColumnValuesByScrolling(table, "${columnName}", ${scrollingEnabled});
311
+ `;
312
+ values = await util.browser.executeScript(browserCommand);
313
+ // ========================================================================
314
+ }
315
+ catch (error) {
316
+ return this.ErrorHandler.logException(new Error(`Error while executing browser command: ${error}`));
317
+ }
318
+ return values;
319
+ }
320
+ // =================================== SELECT OPERATIONS ===================================
321
+ /**
322
+ * @function selectRowByIndex
323
+ * @memberOf ui5.table
324
+ * @description Selects a row in the table by its index.
325
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
326
+ * @param {Number} index - The index of the row to select.
327
+ * @example await ui5.table.selectRowByIndex("application-ReportingTask-run-component---ReportList--ReportingTable", 0);
328
+ * @example const selector = {
329
+ * elementProperties: {
330
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
331
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
332
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
333
+ * }
334
+ * };
335
+ * await ui5.table.selectRowByIndex(selector, 0);
336
+ */
337
+ async selectRowByIndex(tableSelectorOrId, index) {
338
+ this.vlf.initLog(this.selectRowByIndex);
339
+ const ancestorSelector = await Table._resolveTableSelectorOrId(tableSelectorOrId);
340
+ const checkBoxSelector = {
402
341
  elementProperties: {
342
+ metadata: Table.CHECKBOX_METADATA
343
+ },
344
+ parentProperties: {
403
345
  metadata: Table.COLUMN_LIST_ITEM_METADATA,
404
- id: columnListItemId
346
+ ancestorProperties: ancestorSelector.elementProperties
405
347
  }
406
348
  };
407
- return columnListItemSelector;
349
+ await ui5.userInteraction.check(checkBoxSelector, index);
408
350
  }
409
351
  /**
410
352
  * @function selectAllRows
@@ -416,10 +358,10 @@ class Table {
416
358
  */
417
359
  async selectAllRows(tableSelectorOrId) {
418
360
  this.vlf.initLog(this.selectAllRows);
419
- const parentSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
361
+ const parentSelector = await Table._resolveTableSelectorOrId(tableSelectorOrId);
420
362
  const checkBoxSelector = {
421
363
  elementProperties: {
422
- metadata: "sap.m.CheckBox"
364
+ metadata: Table.CHECKBOX_METADATA
423
365
  },
424
366
  parentProperties: parentSelector.elementProperties
425
367
  };
@@ -443,13 +385,13 @@ class Table {
443
385
  */
444
386
  async deselectRowByIndex(tableSelectorOrId, index) {
445
387
  this.vlf.initLog(this.selectRowByIndex);
446
- const ancestorSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
388
+ const ancestorSelector = await Table._resolveTableSelectorOrId(tableSelectorOrId);
447
389
  const checkBoxSelector = {
448
390
  elementProperties: {
449
- metadata: "sap.m.CheckBox"
391
+ metadata: Table.CHECKBOX_METADATA
450
392
  },
451
393
  parentProperties: {
452
- metadata: "sap.m.ColumnListItem",
394
+ metadata: Table.COLUMN_LIST_ITEM_METADATA,
453
395
  ancestorProperties: ancestorSelector.elementProperties
454
396
  }
455
397
  };
@@ -472,17 +414,115 @@ class Table {
472
414
  */
473
415
  async deselectAllRows(tableSelectorOrId) {
474
416
  this.vlf.initLog(this.selectAllRows);
475
- const parentSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
417
+ const parentSelector = await Table._resolveTableSelectorOrId(tableSelectorOrId);
476
418
  const checkBoxSelector = {
477
419
  elementProperties: {
478
- metadata: "sap.m.CheckBox"
420
+ metadata: Table.CHECKBOX_METADATA
479
421
  },
480
422
  parentProperties: parentSelector.elementProperties
481
423
  };
482
424
  await ui5.userInteraction.uncheck(checkBoxSelector);
483
425
  }
426
+ /**
427
+ * @function selectRowByValues
428
+ * @memberOf ui5.table
429
+ * @description Selects a row in the table by matching value(s). If multiple rows match, selects the one at the given global index (across all pages).
430
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table.
431
+ * @param {String | Array<String>} values - The value(s) to match in the table rows.
432
+ * @param {Number} [index=0] - The global index of the matching row to select (across all pages).
433
+ * @example const selector = {
434
+ * elementProperties: {
435
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
436
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
437
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
438
+ * }
439
+ * };
440
+ * await ui5.table.selectRowByValues(selector, ["value1", "value2"]);
441
+ * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable";
442
+ * await ui5.table.selectRowByValues(id, "value", 1);
443
+ */
444
+ async selectRowByValues(tableSelectorOrId, values, index = 0) {
445
+ const vl = this.vlf.initLog(this.selectRowByValues);
446
+ if (typeof values === "string")
447
+ values = [values];
448
+ const constructedTableSelector = await this._constructTableSelector(tableSelectorOrId);
449
+ const visibleRowSelectors = await this.getSelectorsForRowsByValues(constructedTableSelector, values);
450
+ if (visibleRowSelectors.length === 0) {
451
+ return this.ErrorHandler.logException(new Error(`No row found with the provided values: ${values} at global index ${index}.`));
452
+ }
453
+ const selectorType = await this._getSelectorTypeForRowSelection(visibleRowSelectors[index]);
454
+ const selectionSelector = this._buildRowSelectionSelector(selectorType, visibleRowSelectors[index]);
455
+ switch (selectorType) {
456
+ case "ui5CheckBox":
457
+ case "ui5RadioButton":
458
+ await ui5.element.waitForAll(visibleRowSelectors[index]);
459
+ await ui5.userInteraction.check(selectionSelector);
460
+ break;
461
+ case "cssItem":
462
+ await nonUi5.element.waitForAll(selectionSelector);
463
+ await this._checkCssItem(selectionSelector);
464
+ break;
465
+ default:
466
+ throw new Error("No selectable element found for the row.");
467
+ }
468
+ }
469
+ // =================================== OPEN OPERATIONS ===================================
470
+ /**
471
+ * @function openItemByIndex
472
+ * @memberOf ui5.table
473
+ * @description Opens the item in the table by its index.
474
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
475
+ * @param {Number} index - The index of the item to open.
476
+ * @example const selector = {
477
+ * elementProperties: {
478
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
479
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
480
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
481
+ * }
482
+ * };
483
+ * await ui5.table.openItemByIndex(selector, 0);
484
+ * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable";
485
+ * await ui5.table.openItemByIndex(id, 0);
486
+ */
487
+ async openItemByIndex(tableSelectorOrId, index) {
488
+ this.vlf.initLog(this.openItemByIndex);
489
+ const rowSelector = await this.getSelectorForRowByIndex(tableSelectorOrId, index);
490
+ await ui5.userInteraction.click(rowSelector);
491
+ }
492
+ /**
493
+ * @function openItemByValues
494
+ * @memberOf ui5.table
495
+ * @description Opens the item in the table containing the given values. If multiple items match, it opens the index-th item.
496
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
497
+ * @param {String | Array<String>} values - The value(s) to match in the table rows.
498
+ * @param {Number} [index=0] - The index of the matching row to consider.
499
+ * @example const selector = {
500
+ * elementProperties: {
501
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
502
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
503
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
504
+ * }
505
+ * };
506
+ * await ui5.table.openItemByValues(selector, ["value1", "value2"]);
507
+ * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable";
508
+ * await ui5.table.openItemByValues(id, "value");
509
+ */
510
+ async openItemByValues(tableSelectorOrId, values, index = 0, enableHighlighting) {
511
+ this.vlf.initLog(this.openItemByValues);
512
+ const rowSelectors = await this.getSelectorsForRowsByValues(tableSelectorOrId, values, enableHighlighting);
513
+ if (rowSelectors.length === 0) {
514
+ return this.ErrorHandler.logException(new Error(`No items found with the provided values: ${values}.`));
515
+ }
516
+ else if (rowSelectors.length <= index) {
517
+ return this.ErrorHandler.logException(new Error(`The index ${index} is out of bounds. The number of matching items is ${rowSelectors.length}.`));
518
+ }
519
+ else {
520
+ const rowSelector = rowSelectors[index];
521
+ await ui5.userInteraction.click(rowSelector);
522
+ }
523
+ }
484
524
  // =================================== HELPER ===================================
485
- async _resolveTableSelectorOrId(tableSelectorOrId) {
525
+ static async _resolveTableSelectorOrId(tableSelectorOrId) {
486
526
  if (typeof tableSelectorOrId === "string") {
487
527
  const selectors = [
488
528
  {
@@ -496,6 +536,12 @@ class Table {
496
536
  metadata: Table.TABLE_METADATA,
497
537
  id: tableSelectorOrId
498
538
  }
539
+ },
540
+ {
541
+ elementProperties: {
542
+ metadata: Table.UI_TABLE_METADATA,
543
+ id: tableSelectorOrId
544
+ }
499
545
  }
500
546
  ];
501
547
  try {
@@ -509,52 +555,73 @@ class Table {
509
555
  }
510
556
  }
511
557
  else if (typeof tableSelectorOrId === "object" && "elementProperties" in tableSelectorOrId) {
512
- if (tableSelectorOrId.elementProperties.metadata === Table.TABLE_METADATA || tableSelectorOrId.elementProperties.metadata === Table.SMART_TABLE_METADATA) {
558
+ if (tableSelectorOrId.elementProperties.metadata === Table.TABLE_METADATA || tableSelectorOrId.elementProperties.metadata === Table.SMART_TABLE_METADATA || tableSelectorOrId.elementProperties.metadata === Table.UI_TABLE_METADATA) {
513
559
  return tableSelectorOrId;
514
560
  }
515
561
  }
516
562
  throw new Error(`The provided table selector "${tableSelectorOrId}" is not valid. Please provide a valid selector or ID for control type 'SmartTable' or 'Table'.`);
517
563
  }
518
- async _getId(tableSelectorOrId) {
519
- this.vlf.initLog(this._getId);
564
+ static async _getId(tableSelectorOrId) {
520
565
  if (typeof tableSelectorOrId === "string") {
521
566
  return tableSelectorOrId;
522
567
  }
523
568
  else {
524
- const resolvedTableSelectorOrId = await this._resolveTableSelectorOrId(tableSelectorOrId);
569
+ const resolvedTableSelectorOrId = await Table._resolveTableSelectorOrId(tableSelectorOrId);
525
570
  return await ui5.element.getId(resolvedTableSelectorOrId);
526
571
  }
527
572
  }
528
573
  async _getTableMetadata(tableId) {
529
- const vl = this.vlf.initLog(this._getTableMetadata);
530
- vl.log(`The table selector is a string: ${tableId}`);
531
- let browserCommand;
532
574
  try {
533
- browserCommand = `
534
- return (function () {
535
- const table = sap.ui.getCore().getElementById("${tableId}");
536
- return table.getMetadata().getName();
537
- })();
538
- `;
539
- const tableMetadata = await util.browser.executeScript(browserCommand);
575
+ // =========================== BROWSER COMMAND ===========================
576
+ const classCode = tableHelper_1.TableHelper.serializeClass();
577
+ const tableMetadata = await util.browser.executeScript(`
578
+ ${classCode}
579
+ return TableHelper.getTableMetadata("${tableId}");
580
+ `);
540
581
  return tableMetadata;
541
582
  }
542
583
  catch (error) {
543
- throw new Error(`Browser Command: ${browserCommand} failed with: ${error}`);
584
+ throw new Error(`Error while executing browser command: ${error}`);
544
585
  }
545
586
  }
546
587
  async _constructTableSelector(tableSelector) {
547
588
  this.vlf.initLog(this._constructTableSelector);
548
- const tableId = await this._getId(tableSelector);
549
- const tableMetaData = await this._getTableMetadata(tableId);
589
+ const tableId = await Table._getId(tableSelector);
550
590
  const selector = {
551
591
  elementProperties: {
552
- metadata: tableMetaData,
553
592
  id: tableId
554
593
  }
555
594
  };
556
595
  await ui5.element.waitForAll(selector);
557
- return selector;
596
+ const tableMetadata = await this._getTableMetadata(tableId);
597
+ return {
598
+ elementProperties: {
599
+ ...selector.elementProperties,
600
+ metadata: tableMetadata
601
+ }
602
+ };
603
+ }
604
+ _constructRowSelector(filteredRowIds, tableMetadata) {
605
+ const rowsSelectors = [];
606
+ const rowMetadata = this._getRowMetadataByTableMetadata(tableMetadata);
607
+ for (const id of filteredRowIds) {
608
+ const columnListItemSelector = {
609
+ elementProperties: {
610
+ metadata: rowMetadata,
611
+ id: id
612
+ }
613
+ };
614
+ rowsSelectors.push(columnListItemSelector);
615
+ }
616
+ return rowsSelectors;
617
+ }
618
+ _getRowMetadataByTableMetadata(tableMetadata) {
619
+ if (tableMetadata === Table.TABLE_METADATA || tableMetadata === Table.SMART_TABLE_METADATA) {
620
+ return Table.COLUMN_LIST_ITEM_METADATA;
621
+ }
622
+ else {
623
+ return Table.TABLE_ROW_METADATA;
624
+ }
558
625
  }
559
626
  _extractRowCountFromTitle(title) {
560
627
  const vl = this.vlf.initLog(this._extractRowCountFromTitle);
@@ -647,11 +714,74 @@ class Table {
647
714
  }
648
715
  return selector;
649
716
  }
717
+ async _getSelectorTypeForRowSelection(rowSelector) {
718
+ const vl = this.vlf.initLog(this._getSelectorTypeForRowSelection);
719
+ return await util.browser.executeScript((rowSelector) => {
720
+ const id = rowSelector.elementProperties.id;
721
+ const selectorChecks = [
722
+ {
723
+ type: "ui5CheckBox",
724
+ selector: `tr[id='${id}'] [data-sap-ui*='selectMulti'][role='checkbox']`
725
+ },
726
+ {
727
+ type: "ui5RadioButton",
728
+ selector: `tr[id='${id}'] [data-sap-ui*='selectSingle'][role='radio']`
729
+ },
730
+ {
731
+ type: "cssItem",
732
+ selector: `[data-sap-ui-related='${id}'][role='row'] [role='gridcell']`
733
+ }
734
+ ];
735
+ for (const check of selectorChecks) {
736
+ // Note: Following command slows down the execution and might be used after refactoring service
737
+ // const isPresent = await nonUi5.element.isPresentByCss(check.selector);
738
+ if (window.document.querySelector(check.selector)) {
739
+ return check.type;
740
+ }
741
+ }
742
+ return "none";
743
+ }, rowSelector);
744
+ }
745
+ _buildRowSelectionSelector(selectorType, rowSelector) {
746
+ const vl = this.vlf.initLog(this._buildRowSelectionSelector);
747
+ switch (selectorType) {
748
+ case "ui5CheckBox":
749
+ return {
750
+ elementProperties: {
751
+ metadata: Table.CHECKBOX_METADATA
752
+ },
753
+ parentProperties: rowSelector.elementProperties
754
+ };
755
+ case "ui5RadioButton":
756
+ return {
757
+ elementProperties: {
758
+ metadata: "sap.m.RadioButton"
759
+ },
760
+ parentProperties: rowSelector.elementProperties
761
+ };
762
+ case "cssItem":
763
+ return `[data-sap-ui-related = '${rowSelector.elementProperties.id}'] [role='gridcell']`;
764
+ case "none":
765
+ throw new Error("No selectable CheckBox, RadioButton, or Css element found for the row.");
766
+ }
767
+ }
768
+ // TODO: Move to separate public function under nonUi5.userInteraction.check
769
+ async _checkCssItem(selectionSelector) {
770
+ const element = await nonUi5.element.getByCss(selectionSelector);
771
+ const isSelected = await nonUi5.element.getAttributeValue(element, "aria-selected");
772
+ if (isSelected === "false") {
773
+ await nonUi5.userInteraction.click(element);
774
+ }
775
+ }
650
776
  }
651
777
  exports.Table = Table;
652
778
  // =================================== CONSTANTS ===================================
653
779
  Table.SMART_TABLE_METADATA = "sap.ui.comp.smarttable.SmartTable";
654
780
  Table.TABLE_METADATA = "sap.m.Table";
781
+ Table.UI_TABLE_METADATA = "sap.ui.table.Table";
655
782
  Table.COLUMN_LIST_ITEM_METADATA = "sap.m.ColumnListItem";
783
+ Table.TABLE_ROW_METADATA = "sap.ui.table.Row";
784
+ Table.CHECKBOX_METADATA = "sap.m.CheckBox";
785
+ Table.SUPPORTED_TABLES_METADATA = [Table.SMART_TABLE_METADATA, Table.TABLE_METADATA, Table.UI_TABLE_METADATA];
656
786
  exports.default = new Table();
657
787
  //# sourceMappingURL=table.js.map