@sap_oss/wdio-qmate-service 2.16.3 → 2.18.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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/lib/reuse/helper/errorHandler.js.map +1 -1
  3. package/lib/reuse/modules/nonUi5/assertion.d.ts +10 -0
  4. package/lib/reuse/modules/nonUi5/assertion.js +15 -0
  5. package/lib/reuse/modules/nonUi5/assertion.js.map +1 -1
  6. package/lib/reuse/modules/nonUi5/element.d.ts +10 -0
  7. package/lib/reuse/modules/nonUi5/element.js +13 -0
  8. package/lib/reuse/modules/nonUi5/element.js.map +1 -1
  9. package/lib/reuse/modules/ui5/navigationBar.js +12 -7
  10. package/lib/reuse/modules/ui5/navigationBar.js.map +1 -1
  11. package/lib/reuse/modules/ui5/table.d.ts +184 -7
  12. package/lib/reuse/modules/ui5/table.js +471 -43
  13. package/lib/reuse/modules/ui5/table.js.map +1 -1
  14. package/lib/reuse/modules/ui5/types/ui5.types.d.ts +20 -10
  15. package/lib/reuse/modules/util/browser.d.ts +2 -2
  16. package/lib/reuse/modules/util/browser.js +3 -3
  17. package/lib/reuse/modules/util/browser.js.map +1 -1
  18. package/package.json +1 -1
  19. package/test/helper/configurations/base.conf.js +1 -0
  20. package/test/reuse/nonUi5/assertion/expectTextToBe.spec.js +63 -0
  21. package/test/reuse/nonUi5/assertion/test.assertion.conf.js +2 -1
  22. package/test/reuse/nonUi5/element/isEnabled.spec.js +49 -0
  23. package/test/reuse/nonUi5/element/test.element.conf.js +1 -0
  24. package/test/reuse/ui5/navigationBar/clickSapLogo.spec.js +27 -0
  25. package/test/reuse/ui5/navigationBar/test.navigationBar.conf.js +2 -1
  26. package/test/reuse/ui5/table/deselectAllRows.spec.js +71 -0
  27. package/test/reuse/ui5/table/deselectRowByIndex.spec.js +86 -0
  28. package/test/reuse/ui5/table/getSelectorForRowByIndex.spec.js +78 -0
  29. package/test/reuse/ui5/table/getSelectorsForRowsByValues.spec.js +152 -0
  30. package/test/reuse/ui5/table/getTotalNumberOfRows.spec.js +144 -0
  31. package/test/reuse/ui5/table/getTotalNumberOfRowsByValues.spec.js +115 -0
  32. package/test/reuse/ui5/table/openItemByIndex.spec.js +84 -0
  33. package/test/reuse/ui5/table/openItemByValues.spec.js +102 -0
  34. package/test/reuse/ui5/table/selectAllRows.spec.js +64 -0
  35. package/test/reuse/ui5/table/selectRowByIndex.spec.js +89 -0
  36. package/test/reuse/ui5/table/test.table.conf.js +12 -2
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Table = void 0;
4
7
  const verboseLogger_1 = require("../../helper/verboseLogger");
8
+ const errorHandler_1 = __importDefault(require("../../helper/errorHandler"));
5
9
  /**
6
10
  * @class table
7
11
  * @memberof ui5
@@ -9,6 +13,7 @@ const verboseLogger_1 = require("../../helper/verboseLogger");
9
13
  class Table {
10
14
  constructor() {
11
15
  this.vlf = new verboseLogger_1.VerboseLoggerFactory("ui5", "table");
16
+ this.ErrorHandler = new errorHandler_1.default();
12
17
  }
13
18
  // =================================== SORTING ===================================
14
19
  /**
@@ -16,7 +21,7 @@ class Table {
16
21
  * @memberOf ui5.table
17
22
  * @description Sorts the given column "Ascending".
18
23
  * @param {String} columnName - The name of the column to sort.
19
- * @param {Object} [tableSelector] - The selector describing the table element (in case there are more then one).
24
+ * @param {Ui5Selector} tableSelector - The selector describing the table element (in case there are more then one).
20
25
  * @example await ui5.table.sortColumnAscending("Supplier");
21
26
  * @example const glAccountItemsTable = {
22
27
  * "elementProperties": {
@@ -29,27 +34,27 @@ class Table {
29
34
  */
30
35
  async sortColumnAscending(columnName, tableSelector) {
31
36
  const oldSortButtonSelector = {
32
- "elementProperties": {
33
- "metadata": "sap.m.Button",
34
- "icon": "sap-icon://sort-ascending"
37
+ elementProperties: {
38
+ metadata: "sap.m.Button",
39
+ icon: "sap-icon://sort-ascending"
35
40
  },
36
- "ancestorProperties": {
37
- "metadata": "sap.m.Toolbar"
41
+ ancestorProperties: {
42
+ metadata: "sap.m.Toolbar"
38
43
  }
39
44
  };
40
45
  const newSortButtonSelector = {
41
- "elementProperties": {
42
- "metadata": "sap.m.ToggleButton",
43
- "text": "Ascending"
46
+ elementProperties: {
47
+ metadata: "sap.m.ToggleButton",
48
+ text: "Ascending"
44
49
  }
45
50
  };
46
51
  const newerSortButtonSelector = {
47
- "elementProperties": {
48
- "metadata": "sap.ui.core.Icon",
49
- "src": "sap-icon://sort-ascending"
52
+ elementProperties: {
53
+ metadata: "sap.ui.core.Icon",
54
+ src: "sap-icon://sort-ascending"
50
55
  },
51
- "ancestorProperties": {
52
- "metadata": "sap.m.InputListItem"
56
+ ancestorProperties: {
57
+ metadata: "sap.m.InputListItem"
53
58
  }
54
59
  };
55
60
  const sort = await this._getSortIndicatorValue(columnName, tableSelector);
@@ -63,7 +68,7 @@ class Table {
63
68
  * @memberOf ui5.table
64
69
  * @description Sorts the given column "Descending".
65
70
  * @param {String} columnName The name of the column to sort.
66
- * @param {Object} [tableSelector] - The selector describing the table element (in case there are more then one).
71
+ * @param {Ui5Selector} tableSelector - The selector describing the table element (in case there are more then one).
67
72
  * @example await ui5.table.sortColumnDescending("Supplier");
68
73
  * @example const glAccountItemsTable = {
69
74
  * "elementProperties": {
@@ -76,27 +81,27 @@ class Table {
76
81
  */
77
82
  async sortColumnDescending(columnName, tableSelector) {
78
83
  const oldSortButtonSelector = {
79
- "elementProperties": {
80
- "metadata": "sap.m.Button",
81
- "icon": "sap-icon://sort-descending"
84
+ elementProperties: {
85
+ metadata: "sap.m.Button",
86
+ icon: "sap-icon://sort-descending"
82
87
  },
83
- "ancestorProperties": {
84
- "metadata": "sap.m.Toolbar"
88
+ ancestorProperties: {
89
+ metadata: "sap.m.Toolbar"
85
90
  }
86
91
  };
87
92
  const newSortButtonSelector = {
88
- "elementProperties": {
89
- "metadata": "sap.m.ToggleButton",
90
- "text": "Descending"
93
+ elementProperties: {
94
+ metadata: "sap.m.ToggleButton",
95
+ text: "Descending"
91
96
  }
92
97
  };
93
98
  const newerSortButtonSelector = {
94
- "elementProperties": {
95
- "metadata": "sap.ui.core.Icon",
96
- "src": "sap-icon://sort-descending"
99
+ elementProperties: {
100
+ metadata: "sap.ui.core.Icon",
101
+ src: "sap-icon://sort-descending"
97
102
  },
98
- "ancestorProperties": {
99
- "metadata": "sap.m.InputListItem"
103
+ ancestorProperties: {
104
+ metadata: "sap.m.InputListItem"
100
105
  }
101
106
  };
102
107
  const sort = await this._getSortIndicatorValue(columnName, tableSelector);
@@ -105,11 +110,12 @@ class Table {
105
110
  await Promise.any([ui5.userInteraction.click(oldSortButtonSelector), ui5.userInteraction.click(newSortButtonSelector), ui5.userInteraction.click(newerSortButtonSelector)]);
106
111
  }
107
112
  }
113
+ // =================================== SETTINGS ===================================
108
114
  /**
109
115
  * @function clickSettingsButton
110
116
  * @memberOf ui5.table
111
117
  * @description Opens the user Settings.
112
- * @param {Object} [tableSelector] - The selector describing the table element (in case there are more then one).
118
+ * @param {Ui5Selector} tableSelector - The selector describing the table element (in case there are more then one).
113
119
  * @example await ui5.table.clickSettingsButton();
114
120
  * @example const glAccountItemsTable = {
115
121
  * "elementProperties": {
@@ -121,7 +127,7 @@ class Table {
121
127
  * await ui5.table.clickSettingsButton(glAccountItemsTable);
122
128
  */
123
129
  async clickSettingsButton(tableSelector) {
124
- const vl = this.vlf.initLog(this.clickSettingsButton);
130
+ this.vlf.initLog(this.clickSettingsButton);
125
131
  const settingsButtonSelector = {
126
132
  elementProperties: {
127
133
  metadata: "sap.m.OverflowToolbarButton",
@@ -136,7 +142,431 @@ class Table {
136
142
  await ui5.userInteraction.click(selector);
137
143
  }
138
144
  }
145
+ // =================================== OPERATIONS ===================================
146
+ /**
147
+ * @function getTotalNumberOfRows
148
+ * @memberOf ui5.table
149
+ * @description Returns the total number of rows in the table.
150
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
151
+ * @returns {Number} The total number of rows in the table.
152
+ * @example const selector = {
153
+ * elementProperties: {
154
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
155
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
156
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
157
+ * }
158
+ * };
159
+ * const numberOfRows = await ui5.table.getTotalNumberOfRows(selector);
160
+ */
161
+ async getTotalNumberOfRows(tableSelectorOrId) {
162
+ this.vlf.initLog(this.getTotalNumberOfRows);
163
+ const ancestorSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
164
+ const tableTitleSelector = {
165
+ elementProperties: {
166
+ metadata: "sap.m.Title"
167
+ },
168
+ parentProperties: {
169
+ metadata: "sap.m.OverflowToolbar",
170
+ ancestorProperties: ancestorSelector.elementProperties
171
+ }
172
+ };
173
+ const tableTitleText = await ui5.element.getPropertyValue(tableTitleSelector, "text");
174
+ return this._extractRowCountFromTitle(tableTitleText);
175
+ }
176
+ /**
177
+ * @function getTotalNumberOfRowsByValues
178
+ * @memberOf ui5.table
179
+ * @description Returns the total number of rows in the table that match the given values.
180
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
181
+ * @param {String | Array<String>} values - The value(s) to match in the table rows.
182
+ * @param {Number} [index=0] - The index of the matching row to consider.
183
+ * @returns {Number} The total number of matching rows in the table.
184
+ * @example const selector = {
185
+ * elementProperties: {
186
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
187
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
188
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
189
+ * }
190
+ * };
191
+ * const numberOfRows = await ui5.table.getTotalNumberOfRowsByValues(selector, ["value1", "value2"]);
192
+ * const numberOfRows = await ui5.table.getTotalNumberOfRowsByValues(selector, "value");
193
+ **/
194
+ async getTotalNumberOfRowsByValues(tableSelectorOrId, values) {
195
+ this.vlf.initLog(this.getTotalNumberOfRowsByValues);
196
+ const rowSelectors = await this.getSelectorsForRowsByValues(tableSelectorOrId, values);
197
+ return rowSelectors.length;
198
+ }
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
+ /**
284
+ * @function getSelectorsForRowsByValues
285
+ * @memberOf ui5.table
286
+ * @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
+ * @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.
289
+ * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable"
290
+ * await ui5.table.getSelectorsForRowsByValues(id, "February");
291
+ * @example const selector = {
292
+ * elementProperties: {
293
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
294
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
295
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
296
+ * }
297
+ * };
298
+ * await ui5.table.getSelectorsForRowsByValues(selector, ["January", "2022"]);
299
+ */
300
+ async getSelectorsForRowsByValues(tableSelector, values) {
301
+ this.vlf.initLog(this.getSelectorsForRowsByValues);
302
+ if (typeof values === "string") {
303
+ values = [values];
304
+ }
305
+ else if (!Array.isArray(values)) {
306
+ this.ErrorHandler.logException(new Error("Invalid values provided. It should be either a string or an array of strings."));
307
+ }
308
+ const constructedTableSelector = await this._constructTableSelector(tableSelector);
309
+ let filteredRowIds;
310
+ try {
311
+ // =========================== 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);
329
+ // ========================================================================
330
+ }
331
+ catch (error) {
332
+ return this.ErrorHandler.logException(new Error(`Error while executing browser command: ${error}`));
333
+ }
334
+ 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;
346
+ }
347
+ else {
348
+ return [];
349
+ }
350
+ }
351
+ /**
352
+ * @function getSelectorForRowByIndex
353
+ * @memberOf ui5.table
354
+ * @description Gets the selector of a row in the table by its index.
355
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
356
+ * @param {Number} index - The index of the item to open.
357
+ * @example const selector = {
358
+ * elementProperties: {
359
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
360
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
361
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
362
+ * }
363
+ * };
364
+ * const rowSelector = await ui5.table.getSelectorForRowByIndex(selector, 0);
365
+ * @example id = "application-ReportingTask-run-component---ReportList--ReportingTable"
366
+ * const rowSelector = await ui5.table.getSelectorForRowByIndex(id, 0);
367
+ */
368
+ async getSelectorForRowByIndex(tableSelector, index) {
369
+ this.vlf.initLog(this.getSelectorForRowByIndex);
370
+ const constructedTableSelector = await this._constructTableSelector(tableSelector);
371
+ let columnListItemId;
372
+ try {
373
+ // =========================== 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);
393
+ // ========================================================================
394
+ }
395
+ catch (error) {
396
+ return this.ErrorHandler.logException(new Error(`Error while executing browser command: ${error}`));
397
+ }
398
+ if (!columnListItemId) {
399
+ return this.ErrorHandler.logException(new Error(`No item found with index ${index}.`));
400
+ }
401
+ const columnListItemSelector = {
402
+ elementProperties: {
403
+ metadata: Table.COLUMN_LIST_ITEM_METADATA,
404
+ id: columnListItemId
405
+ }
406
+ };
407
+ return columnListItemSelector;
408
+ }
409
+ /**
410
+ * @function selectAllRows
411
+ * @memberOf ui5.table
412
+ * @description Selects all rows in the table.
413
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
414
+ * @example await ui5.table.selectAllRows("application-ReportingTask-run-component---ReportList--ReportingTable");
415
+ * await ui5.table.selectAllRows(selector);
416
+ */
417
+ async selectAllRows(tableSelectorOrId) {
418
+ this.vlf.initLog(this.selectAllRows);
419
+ const parentSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
420
+ const checkBoxSelector = {
421
+ elementProperties: {
422
+ metadata: "sap.m.CheckBox"
423
+ },
424
+ parentProperties: parentSelector.elementProperties
425
+ };
426
+ await ui5.userInteraction.check(checkBoxSelector);
427
+ }
428
+ /**
429
+ * @function deselectRowByIndex
430
+ * @memberOf ui5.table
431
+ * @description Deselects a row in the table by its index.
432
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
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.deselectRowByIndex(selector, 0);
441
+ * @example const id = "application-ReportingTask-run-component---ReportList--ReportingTable";
442
+ * await ui5.table.deselectRowByIndex(id, 0);
443
+ */
444
+ async deselectRowByIndex(tableSelectorOrId, index) {
445
+ this.vlf.initLog(this.selectRowByIndex);
446
+ const ancestorSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
447
+ const checkBoxSelector = {
448
+ elementProperties: {
449
+ metadata: "sap.m.CheckBox"
450
+ },
451
+ parentProperties: {
452
+ metadata: "sap.m.ColumnListItem",
453
+ ancestorProperties: ancestorSelector.elementProperties
454
+ }
455
+ };
456
+ await ui5.userInteraction.uncheck(checkBoxSelector, index);
457
+ }
458
+ /**
459
+ * @function deselectAllRows
460
+ * @memberOf ui5.table
461
+ * @description Deselects all rows in the table.
462
+ * @param {Ui5Selector | String} tableSelectorOrId - The selector or ID describing the table (sap.m.Table | sap.ui.comp.smarttable.SmartTable).
463
+ * @example await ui5.table.deselectAllRows("application-ReportingTask-run-component---ReportList--ReportingTable");
464
+ * @example const selector = {
465
+ * elementProperties: {
466
+ * viewName: "gs.fin.runstatutoryreports.s1.view.ReportList",
467
+ * metadata: "sap.ui.comp.smarttable.SmartTable",
468
+ * id: "application-ReportingTask-run-component---ReportList--ReportingTable"
469
+ * }
470
+ * };
471
+ * await ui5.table.deselectAllRows(selector);
472
+ */
473
+ async deselectAllRows(tableSelectorOrId) {
474
+ this.vlf.initLog(this.selectAllRows);
475
+ const parentSelector = await this._resolveTableSelectorOrId(tableSelectorOrId);
476
+ const checkBoxSelector = {
477
+ elementProperties: {
478
+ metadata: "sap.m.CheckBox"
479
+ },
480
+ parentProperties: parentSelector.elementProperties
481
+ };
482
+ await ui5.userInteraction.uncheck(checkBoxSelector);
483
+ }
139
484
  // =================================== HELPER ===================================
485
+ async _resolveTableSelectorOrId(tableSelectorOrId) {
486
+ if (typeof tableSelectorOrId === "string") {
487
+ const selectors = [
488
+ {
489
+ elementProperties: {
490
+ metadata: Table.SMART_TABLE_METADATA,
491
+ id: tableSelectorOrId
492
+ }
493
+ },
494
+ {
495
+ elementProperties: {
496
+ metadata: Table.TABLE_METADATA,
497
+ id: tableSelectorOrId
498
+ }
499
+ }
500
+ ];
501
+ try {
502
+ const index = await Promise.any(selectors.map(async (selectors, index) => {
503
+ return await ui5.element.getDisplayed(selectors).then(() => index);
504
+ }));
505
+ return selectors[index];
506
+ }
507
+ catch (error) {
508
+ // Intentionally left empty, as the error is handled below
509
+ }
510
+ }
511
+ else if (typeof tableSelectorOrId === "object" && "elementProperties" in tableSelectorOrId) {
512
+ if (tableSelectorOrId.elementProperties.metadata === Table.TABLE_METADATA || tableSelectorOrId.elementProperties.metadata === Table.SMART_TABLE_METADATA) {
513
+ return tableSelectorOrId;
514
+ }
515
+ }
516
+ 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
+ }
518
+ async _getId(tableSelectorOrId) {
519
+ this.vlf.initLog(this._getId);
520
+ if (typeof tableSelectorOrId === "string") {
521
+ return tableSelectorOrId;
522
+ }
523
+ else {
524
+ const resolvedTableSelectorOrId = await this._resolveTableSelectorOrId(tableSelectorOrId);
525
+ return await ui5.element.getId(resolvedTableSelectorOrId);
526
+ }
527
+ }
528
+ 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
+ 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);
540
+ return tableMetadata;
541
+ }
542
+ catch (error) {
543
+ throw new Error(`Browser Command: ${browserCommand} failed with: ${error}`);
544
+ }
545
+ }
546
+ async _constructTableSelector(tableSelector) {
547
+ this.vlf.initLog(this._constructTableSelector);
548
+ const tableId = await this._getId(tableSelector);
549
+ const tableMetaData = await this._getTableMetadata(tableId);
550
+ const selector = {
551
+ elementProperties: {
552
+ metadata: tableMetaData,
553
+ id: tableId
554
+ }
555
+ };
556
+ await ui5.element.waitForAll(selector);
557
+ return selector;
558
+ }
559
+ _extractRowCountFromTitle(title) {
560
+ const vl = this.vlf.initLog(this._extractRowCountFromTitle);
561
+ const match = title.match(/\((\d+)\)/);
562
+ if (match) {
563
+ return parseInt(match[1], 10);
564
+ }
565
+ else {
566
+ vl.log(`Extracting row count from title was not successful, returning 0.`);
567
+ return 0;
568
+ }
569
+ }
140
570
  async _clickColumn(name, tableSelector) {
141
571
  const vl = this.vlf.initLog(this._clickColumn);
142
572
  const tableColumnSelector = {
@@ -156,20 +586,17 @@ class Table {
156
586
  }
157
587
  };
158
588
  if (!tableSelector) {
159
- await Promise.any([ui5.userInteraction.click(tableColumnSelector),
160
- ui5.userInteraction.click(tableGridColumnSelector)]);
589
+ await Promise.any([ui5.userInteraction.click(tableColumnSelector), ui5.userInteraction.click(tableGridColumnSelector)]);
161
590
  }
162
591
  if (typeof tableSelector == "number") {
163
592
  util.console.warn(`Usage of argument 'index' in function ${arguments.callee.caller.name} is deprecated. Please pass a valid table selector instead.`);
164
- await Promise.any([ui5.userInteraction.click(tableColumnSelector, tableSelector),
165
- ui5.userInteraction.click(tableGridColumnSelector, tableSelector)]);
593
+ await Promise.any([ui5.userInteraction.click(tableColumnSelector, tableSelector), ui5.userInteraction.click(tableGridColumnSelector, tableSelector)]);
166
594
  }
167
595
  else if (typeof tableSelector === "object") {
168
- await Promise.any([ui5.userInteraction.click(this._prepareAncestorSelector(tableColumnSelector, tableSelector)),
169
- ui5.userInteraction.click(this._prepareAncestorSelector(tableGridColumnSelector, tableSelector))]);
596
+ await Promise.any([ui5.userInteraction.click(this._prepareAncestorSelector(tableColumnSelector, tableSelector)), ui5.userInteraction.click(this._prepareAncestorSelector(tableGridColumnSelector, tableSelector))]);
170
597
  }
171
598
  }
172
- async _getSortValudGridTable(selector, ancestor) {
599
+ async _getSortValueGridTable(selector, ancestor) {
173
600
  const sortOrder = await ui5.element.getPropertyValue(selector, "sortOrder", ancestor);
174
601
  const sorted = await ui5.element.getPropertyValue(selector, "sorted", ancestor);
175
602
  return sorted ? sortOrder : "";
@@ -193,18 +620,15 @@ class Table {
193
620
  }
194
621
  };
195
622
  if (!tableSelector) {
196
- return Promise.any([ui5.element.getPropertyValue(tableColumnSelector, "sortIndicator"),
197
- this._getSortValudGridTable(tableGridColumnSelector)]);
623
+ return Promise.any([ui5.element.getPropertyValue(tableColumnSelector, "sortIndicator"), this._getSortValueGridTable(tableGridColumnSelector)]);
198
624
  }
199
625
  if (typeof tableSelector == "number") {
200
626
  util.console.warn(`The usage of argument 'index' in function ${arguments.callee.caller.name} is deprecated. Please pass a valid table selector instead.`);
201
- return Promise.any([ui5.element.getPropertyValue(tableColumnSelector, "sortIndicator", tableSelector),
202
- this._getSortValudGridTable(tableGridColumnSelector, tableSelector)]);
627
+ return Promise.any([ui5.element.getPropertyValue(tableColumnSelector, "sortIndicator", tableSelector), this._getSortValueGridTable(tableGridColumnSelector, tableSelector)]);
203
628
  }
204
629
  else if (typeof tableSelector === "object") {
205
630
  const selector = this._prepareAncestorSelector(tableColumnSelector, tableSelector);
206
- return Promise.any([ui5.element.getPropertyValue(this._prepareAncestorSelector(tableColumnSelector, tableSelector), "sortIndicator"),
207
- this._getSortValudGridTable(this._prepareAncestorSelector(tableGridColumnSelector, tableSelector))]);
631
+ return Promise.any([ui5.element.getPropertyValue(this._prepareAncestorSelector(tableColumnSelector, tableSelector), "sortIndicator"), this._getSortValueGridTable(this._prepareAncestorSelector(tableGridColumnSelector, tableSelector))]);
208
632
  }
209
633
  }
210
634
  _prepareAncestorSelector(selector, ancestorSelector) {
@@ -225,5 +649,9 @@ class Table {
225
649
  }
226
650
  }
227
651
  exports.Table = Table;
652
+ // =================================== CONSTANTS ===================================
653
+ Table.SMART_TABLE_METADATA = "sap.ui.comp.smarttable.SmartTable";
654
+ Table.TABLE_METADATA = "sap.m.Table";
655
+ Table.COLUMN_LIST_ITEM_METADATA = "sap.m.ColumnListItem";
228
656
  exports.default = new Table();
229
657
  //# sourceMappingURL=table.js.map