@sap_oss/wdio-qmate-service 1.0.0 → 1.0.2

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 (144) hide show
  1. package/README.md +2 -1
  2. package/{test/core/package-lock.json → docs/bestPractices/spec.md} +0 -0
  3. package/docs/doc.md +176 -353
  4. package/docs/gettingStarted/setup.md +2 -2
  5. package/docs/index.md +1 -1
  6. package/docs/sections/bestPractices/authentication.md +151 -0
  7. package/docs/sections/bestPractices/dataHandling.md +61 -0
  8. package/docs/sections/bestPractices/selectors.md +44 -0
  9. package/docs/{contact.md → sections/contact.md} +0 -0
  10. package/docs/sections/features/advancedDataHandling.md +252 -0
  11. package/docs/sections/features/config.md +171 -0
  12. package/docs/sections/features/dataHandling.md +83 -0
  13. package/docs/{gettingStarted → sections/features}/selectors.md +0 -0
  14. package/docs/sections/features/spec.md +0 -0
  15. package/docs/sections/gettingStarted/config.md +18 -0
  16. package/docs/sections/gettingStarted/execution.md +7 -0
  17. package/docs/sections/gettingStarted/setup.md +9 -0
  18. package/docs/sections/gettingStarted/spec.md +31 -0
  19. package/docs/sections/gettingStarted/specs.md +19 -0
  20. package/docs/sections/support/bugReporting.md +19 -0
  21. package/docs/sections/support/knownIssuesAndLimitations.md +0 -0
  22. package/docs/sections/support/troubleshooting.md +16 -0
  23. package/docs/sources/images/fiori_form.PNG +0 -0
  24. package/docs/sources/images/sapCloud_form.PNG +0 -0
  25. package/lib/index.js +59 -82
  26. package/lib/index.js.map +1 -1
  27. package/lib/reuse/authenticator/authHandler.js +12 -23
  28. package/lib/reuse/authenticator/authHandler.js.map +1 -1
  29. package/lib/reuse/authenticator/basicUrlAuthenticator.js +21 -32
  30. package/lib/reuse/authenticator/basicUrlAuthenticator.js.map +1 -1
  31. package/lib/reuse/authenticator/customAuthenticator.js +42 -55
  32. package/lib/reuse/authenticator/customAuthenticator.js.map +1 -1
  33. package/lib/reuse/authenticator/formAuthenticator.js +37 -50
  34. package/lib/reuse/authenticator/formAuthenticator.js.map +1 -1
  35. package/lib/reuse/authenticator/plainAuthenticator.js +5 -16
  36. package/lib/reuse/authenticator/plainAuthenticator.js.map +1 -1
  37. package/lib/reuse/helper/jsDocGen.js +4 -12
  38. package/lib/reuse/helper/jsDocGen.js.map +1 -1
  39. package/lib/reuse/index.js +20 -5
  40. package/lib/reuse/index.js.map +1 -1
  41. package/lib/reuse/modules/common/navigation.js +10 -23
  42. package/lib/reuse/modules/common/navigation.js.map +1 -1
  43. package/lib/reuse/modules/common/userInteraction.js +40 -73
  44. package/lib/reuse/modules/common/userInteraction.js.map +1 -1
  45. package/lib/reuse/modules/nonUi5/assertion.js +31 -52
  46. package/lib/reuse/modules/nonUi5/assertion.js.map +1 -1
  47. package/lib/reuse/modules/nonUi5/element.js +266 -331
  48. package/lib/reuse/modules/nonUi5/element.js.map +1 -1
  49. package/lib/reuse/modules/nonUi5/navigation.js +10 -21
  50. package/lib/reuse/modules/nonUi5/navigation.js.map +1 -1
  51. package/lib/reuse/modules/nonUi5/userInteraction.js +176 -215
  52. package/lib/reuse/modules/nonUi5/userInteraction.js.map +1 -1
  53. package/lib/reuse/modules/service/odata.d.ts +106 -94
  54. package/lib/reuse/modules/service/odata.js +209 -204
  55. package/lib/reuse/modules/service/odata.js.map +1 -1
  56. package/lib/reuse/modules/service/rest.js +64 -81
  57. package/lib/reuse/modules/service/rest.js.map +1 -1
  58. package/lib/reuse/modules/ui5/assertion.js +217 -268
  59. package/lib/reuse/modules/ui5/assertion.js.map +1 -1
  60. package/lib/reuse/modules/ui5/confirmationDialog.js +17 -42
  61. package/lib/reuse/modules/ui5/confirmationDialog.js.map +1 -1
  62. package/lib/reuse/modules/ui5/control.js +12 -33
  63. package/lib/reuse/modules/ui5/control.js.map +1 -1
  64. package/lib/reuse/modules/ui5/date.js +70 -89
  65. package/lib/reuse/modules/ui5/date.js.map +1 -1
  66. package/lib/reuse/modules/ui5/element.js +121 -156
  67. package/lib/reuse/modules/ui5/element.js.map +1 -1
  68. package/lib/reuse/modules/ui5/errorDialog.js +4 -17
  69. package/lib/reuse/modules/ui5/errorDialog.js.map +1 -1
  70. package/lib/reuse/modules/ui5/footerBar.js +28 -63
  71. package/lib/reuse/modules/ui5/footerBar.js.map +1 -1
  72. package/lib/reuse/modules/ui5/mockserver.js +390 -427
  73. package/lib/reuse/modules/ui5/mockserver.js.map +1 -1
  74. package/lib/reuse/modules/ui5/navigation.js +105 -132
  75. package/lib/reuse/modules/ui5/navigation.js.map +1 -1
  76. package/lib/reuse/modules/ui5/navigationBar.js +58 -77
  77. package/lib/reuse/modules/ui5/navigationBar.js.map +1 -1
  78. package/lib/reuse/modules/ui5/qunit.js +16 -27
  79. package/lib/reuse/modules/ui5/qunit.js.map +1 -1
  80. package/lib/reuse/modules/ui5/session.js +200 -236
  81. package/lib/reuse/modules/ui5/session.js.map +1 -1
  82. package/lib/reuse/modules/ui5/table.js +79 -98
  83. package/lib/reuse/modules/ui5/table.js.map +1 -1
  84. package/lib/reuse/modules/ui5/userInteraction.js +264 -335
  85. package/lib/reuse/modules/ui5/userInteraction.js.map +1 -1
  86. package/lib/reuse/modules/util/browser.js +131 -178
  87. package/lib/reuse/modules/util/browser.js.map +1 -1
  88. package/lib/reuse/modules/util/data.js +3 -2
  89. package/lib/reuse/modules/util/data.js.map +1 -1
  90. package/lib/reuse/modules/util/file.js +71 -90
  91. package/lib/reuse/modules/util/file.js.map +1 -1
  92. package/lib/reuse/modules/util/function.js +68 -87
  93. package/lib/reuse/modules/util/function.js.map +1 -1
  94. package/lib/reuse/modules/util/system.js +22 -33
  95. package/lib/reuse/modules/util/system.js.map +1 -1
  96. package/lib/scripts/dataExchange/dataExchange.js +145 -160
  97. package/lib/scripts/dataExchange/dataExchange.js.map +1 -1
  98. package/lib/scripts/dataExchange/dataExchangeUtil.js +93 -114
  99. package/lib/scripts/dataExchange/dataExchangeUtil.js.map +1 -1
  100. package/lib/scripts/hooks/after.js +3 -14
  101. package/lib/scripts/hooks/after.js.map +1 -1
  102. package/lib/scripts/hooks/before.js +9 -20
  103. package/lib/scripts/hooks/before.js.map +1 -1
  104. package/lib/scripts/hooks/beforeSession.js +7 -18
  105. package/lib/scripts/hooks/beforeSession.js.map +1 -1
  106. package/lib/scripts/hooks/onComplete.js +2 -13
  107. package/lib/scripts/hooks/onComplete.js.map +1 -1
  108. package/lib/scripts/hooks/onPrepare.js +9 -20
  109. package/lib/scripts/hooks/onPrepare.js.map +1 -1
  110. package/lib/scripts/hooks/utils/addLocatorCommands.js +109 -172
  111. package/lib/scripts/hooks/utils/addLocatorCommands.js.map +1 -1
  112. package/lib/scripts/hooks/utils/browserLog.js +18 -31
  113. package/lib/scripts/hooks/utils/browserLog.js.map +1 -1
  114. package/lib/scripts/hooks/utils/dataExchangeCommands.js +13 -24
  115. package/lib/scripts/hooks/utils/dataExchangeCommands.js.map +1 -1
  116. package/lib/scripts/hooks/utils/decryption.d.ts +1 -1
  117. package/lib/scripts/hooks/utils/decryption.js +33 -14
  118. package/lib/scripts/hooks/utils/decryption.js.map +1 -1
  119. package/lib/scripts/hooks/utils/lib.js +249 -272
  120. package/lib/scripts/hooks/utils/lib.js.map +1 -1
  121. package/lib/scripts/hooks/utils/locatorCommands.js +154 -183
  122. package/lib/scripts/hooks/utils/locatorCommands.js.map +1 -1
  123. package/mkdocs.yml +16 -3
  124. package/package.json +14 -11
  125. package/test/authenticator/staticLogin/specs/custom.spec.js +30 -1
  126. package/test/reuse/nonUi5/element/getById.spec.js +17 -0
  127. package/test/reuse/service/odata/get.spec.js +61 -0
  128. package/test/reuse/service/odata/getEntitySet.spec.js +87 -0
  129. package/test/reuse/service/odata/test.odata.conf.js +15 -0
  130. package/test/reuse/ui5/confirmationDialog/clickButton.spec.js +87 -0
  131. package/test/reuse/ui5/confirmationDialog/test.confirmationDialog.conf.js +2 -1
  132. package/test/reuse/ui5/element/test.element.conf.js +2 -1
  133. package/test/reuse/ui5/element/waitForAll.spec.js +46 -0
  134. package/test/reuse/ui5/userInteraction/clearAndFillSmartFieldInputAndRetry.spec.js +28 -0
  135. package/test/reuse/ui5/userInteraction/test.userInteraction.conf.js +1 -0
  136. package/test/reuse/util/browser/switchToNewWindow.spec.js +2 -2
  137. package/test/reuse/util/console/console.spec.js +27 -0
  138. package/test/reuse/util/console/test.console.conf.js +12 -0
  139. package/test/reuse/util/data/data/test.secure.json +7 -3
  140. package/test/reuse/util/data/getSecureData.spec.js +9 -3
  141. package/test/reuse/util/file/pdfParser.spec.js +33 -8
  142. package/test/reuse/util/system/system.spec.js +16 -0
  143. package/test/reuse/util/system/test.system.conf.js +12 -0
  144. package/tsconfig.json +1 -1
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ElementModule = void 0;
13
4
  /**
@@ -24,15 +15,13 @@ class ElementModule {
24
15
  * @param {Number} [timeout=30000] - The timeout to wait (ms).
25
16
  * @example await nonUi5.element.waitForAll(".inputField");
26
17
  */
27
- waitForAll(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- try {
30
- yield this._waitForStabilization(selector, timeout, includeHidden);
31
- }
32
- catch (error) {
33
- throw new Error(`Function 'waitForAll' failed: ${error}`);
34
- }
35
- });
18
+ async waitForAll(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
19
+ try {
20
+ await this._waitForStabilization(selector, timeout, includeHidden);
21
+ }
22
+ catch (error) {
23
+ throw new Error(`Function 'waitForAll' failed: ${error}`);
24
+ }
36
25
  }
37
26
  /**
38
27
  * @function waitToBePresent
@@ -44,15 +33,13 @@ class ElementModule {
44
33
  * @example await nonUi5.element.waitToBePresent("#button12");
45
34
  * @example await nonUi5.element.waitToBePresent("p:first-child");
46
35
  */
47
- waitToBePresent(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- try {
50
- yield $(selector).waitForExist({ timeout: timeout });
51
- }
52
- catch (error) {
53
- throw new Error(`Function 'waitToBePresent' failed: ${error}`);
54
- }
55
- });
36
+ async waitToBePresent(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
37
+ try {
38
+ await $(selector).waitForExist({ timeout: timeout });
39
+ }
40
+ catch (error) {
41
+ throw new Error(`Function 'waitToBePresent' failed: ${error}`);
42
+ }
56
43
  }
57
44
  /**
58
45
  * @function waitToBeVisible
@@ -64,15 +51,13 @@ class ElementModule {
64
51
  * @example await nonUi5.element.waitToBeVisible("#button12");
65
52
  * @example await nonUi5.element.waitToBeVisible("p:first-child");
66
53
  */
67
- waitToBeVisible(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- try {
70
- yield $(selector).waitForDisplayed({ timeout: timeout });
71
- }
72
- catch (error) {
73
- throw new Error(`Function 'waitToBeVisible' failed: ${error}`);
74
- }
75
- });
54
+ async waitToBeVisible(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
55
+ try {
56
+ await $(selector).waitForDisplayed({ timeout: timeout });
57
+ }
58
+ catch (error) {
59
+ throw new Error(`Function 'waitToBeVisible' failed: ${error}`);
60
+ }
76
61
  }
77
62
  /**
78
63
  * @function waitToBeClickable
@@ -84,15 +69,13 @@ class ElementModule {
84
69
  * @example await nonUi5.element.waitToBeClickable("#button12");
85
70
  * @example await nonUi5.element.waitToBeClickable("p:first-child");
86
71
  */
87
- waitToBeClickable(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- try {
90
- yield $(selector).waitForClickable({ timeout: timeout });
91
- }
92
- catch (error) {
93
- throw new Error(`Function 'waitToBeClickable' failed: ${error}`);
94
- }
95
- });
72
+ async waitToBeClickable(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
73
+ try {
74
+ await $(selector).waitForClickable({ timeout: timeout });
75
+ }
76
+ catch (error) {
77
+ throw new Error(`Function 'waitToBeClickable' failed: ${error}`);
78
+ }
96
79
  }
97
80
  // =================================== GET ELEMENTS ===================================
98
81
  /**
@@ -104,17 +87,15 @@ class ElementModule {
104
87
  * @returns {Object[]} The array of elements.
105
88
  * @example await nonUi5.element.getAllDisplayed(".inputField");
106
89
  */
107
- getAllDisplayed(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- try {
110
- yield this.waitForAll(selector, timeout);
111
- const elems = yield $$(selector);
112
- return yield this._filterDisplayed(elems);
113
- }
114
- catch (error) {
115
- throw new Error(`Function 'getAllDisplayed' failed. No visible element(s) found for selector '${selector}' after ${+timeout / 1000}s. ` + error);
116
- }
117
- });
90
+ async getAllDisplayed(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
91
+ try {
92
+ await this.waitForAll(selector, timeout);
93
+ const elems = await $$(selector);
94
+ return await this._filterDisplayed(elems);
95
+ }
96
+ catch (error) {
97
+ throw new Error(`Function 'getAllDisplayed' failed. No visible element(s) found for selector '${selector}' after ${+timeout / 1000}s. ` + error);
98
+ }
118
99
  }
119
100
  /**
120
101
  * @function getAll
@@ -126,16 +107,14 @@ class ElementModule {
126
107
  * const isPresent = await nonUi5.element.isPresent(hiddenElements[0]);
127
108
  * await common.assertion.expectTrue(isPresent);
128
109
  */
129
- getAll(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- try {
132
- yield this.waitForAll(selector, timeout, true);
133
- return yield $$(selector);
134
- }
135
- catch (error) {
136
- throw new Error(`Function 'getAll' failed. No element(s) found for selector '${selector}' after ${+timeout / 1000}s. ` + error);
137
- }
138
- });
110
+ async getAll(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
111
+ try {
112
+ await this.waitForAll(selector, timeout, true);
113
+ return await $$(selector);
114
+ }
115
+ catch (error) {
116
+ throw new Error(`Function 'getAll' failed. No element(s) found for selector '${selector}' after ${+timeout / 1000}s. ` + error);
117
+ }
139
118
  }
140
119
  /**
141
120
  * @function getByCss
@@ -148,15 +127,13 @@ class ElementModule {
148
127
  * @returns {Object} The found element.
149
128
  * @example const elem = await nonUi5.element.getByCss(".button01");
150
129
  */
151
- getByCss(selector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- try {
154
- return yield this._getAndFilterElementBySelector(selector, index, timeout, includeHidden);
155
- }
156
- catch (error) {
157
- throw new Error(`Function 'getByCss' failed. Element with CSS '${selector}' not found. ${error}`);
158
- }
159
- });
130
+ async getByCss(selector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
131
+ try {
132
+ return await this._getAndFilterElementBySelector(selector, index, timeout, includeHidden);
133
+ }
134
+ catch (error) {
135
+ throw new Error(`Function 'getByCss' failed. Element with CSS '${selector}' not found. ${error}`);
136
+ }
160
137
  }
161
138
  /**
162
139
  * @function getByCssContainingText
@@ -171,24 +148,22 @@ class ElementModule {
171
148
  * @returns {Object} The found element.
172
149
  * @example const elem = await nonUi5.element.getByCssContainingText(".input01", "Jack Jackson");
173
150
  */
174
- getByCssContainingText(selector, text = "", index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false, strict = false) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- try {
177
- yield this.waitForAll(selector, timeout);
178
- const elems = yield $$(selector);
179
- const filteredElems = yield this._filterByText(elems, text, strict);
180
- if (includeHidden) {
181
- return filteredElems[index];
182
- }
183
- else {
184
- const visibleElems = yield this._filterDisplayed(filteredElems);
185
- return visibleElems[index];
186
- }
151
+ async getByCssContainingText(selector, text = "", index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false, strict = false) {
152
+ try {
153
+ await this.waitForAll(selector, timeout);
154
+ const elems = await $$(selector);
155
+ const filteredElems = await this._filterByText(elems, text, strict);
156
+ if (includeHidden) {
157
+ return filteredElems[index];
187
158
  }
188
- catch (error) {
189
- throw new Error(`Function 'getByCssContainingText' failed. Element with CSS '${selector}' and text '${text}' not found. ${error}`);
159
+ else {
160
+ const visibleElems = await this._filterDisplayed(filteredElems);
161
+ return visibleElems[index];
190
162
  }
191
- });
163
+ }
164
+ catch (error) {
165
+ throw new Error(`Function 'getByCssContainingText' failed. Element with CSS '${selector}' and text '${text}' not found. ${error}`);
166
+ }
192
167
  }
193
168
  /**
194
169
  * @function getById
@@ -200,23 +175,21 @@ class ElementModule {
200
175
  * @returns {Object} The found element.
201
176
  * @example const elem = await nonUi5.element.getById("button01");
202
177
  */
203
- getById(id, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- try {
206
- const selector = `[id='${id}']`;
207
- if (includeHidden) {
208
- yield this.waitToBePresent(selector, timeout);
209
- return yield $(selector);
210
- }
211
- else {
212
- yield this.waitToBeVisible(selector, timeout);
213
- return yield $(selector);
214
- }
178
+ async getById(id, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
179
+ try {
180
+ const selector = `[id='${id}']`;
181
+ if (includeHidden) {
182
+ await this.waitToBePresent(selector, timeout);
183
+ return await $(selector);
215
184
  }
216
- catch (error) {
217
- throw new Error(`Function 'getById' failed. Element with id '${id}' not found. ${error}`);
185
+ else {
186
+ await this.waitToBeVisible(selector, timeout);
187
+ return await $(selector);
218
188
  }
219
- });
189
+ }
190
+ catch (error) {
191
+ throw new Error(`Function 'getById' failed. Element with id '${id}' not found. ${error}`);
192
+ }
220
193
  }
221
194
  /**
222
195
  * @function getByClass
@@ -230,16 +203,14 @@ class ElementModule {
230
203
  * @example const elem = await nonUi5.element.getByClass("button01");
231
204
  * const elem = await nonUi5.element.getByClass("sapMIBar sapMTB sapMTBNewFlex sapContrastPlus");
232
205
  */
233
- getByClass(elemClass, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
234
- return __awaiter(this, void 0, void 0, function* () {
235
- try {
236
- const selector = `[class*='${elemClass}']`;
237
- return yield this._getAndFilterElementBySelector(selector, index, timeout, includeHidden);
238
- }
239
- catch (error) {
240
- throw new Error(`Function 'getByClass' failed. Element with id '${elemClass}' not found. ${error}`);
241
- }
242
- });
206
+ async getByClass(elemClass, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
207
+ try {
208
+ const selector = `[class*='${elemClass}']`;
209
+ return await this._getAndFilterElementBySelector(selector, index, timeout, includeHidden);
210
+ }
211
+ catch (error) {
212
+ throw new Error(`Function 'getByClass' failed. Element with id '${elemClass}' not found. ${error}`);
213
+ }
243
214
  }
244
215
  /**
245
216
  * @function getByName
@@ -252,16 +223,14 @@ class ElementModule {
252
223
  * @returns {Object} The found element.
253
224
  * @example const elem = await nonUi5.element.getByName(".button01");
254
225
  */
255
- getByName(name, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- try {
258
- const selector = `[name='${name}']`;
259
- return yield this._getAndFilterElementBySelector(selector, index, timeout, includeHidden);
260
- }
261
- catch (error) {
262
- throw new Error(`Function 'getByName' failed. Element with name '${name}' not found. ${error}`);
263
- }
264
- });
226
+ async getByName(name, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
227
+ try {
228
+ const selector = `[name='${name}']`;
229
+ return await this._getAndFilterElementBySelector(selector, index, timeout, includeHidden);
230
+ }
231
+ catch (error) {
232
+ throw new Error(`Function 'getByName' failed. Element with name '${name}' not found. ${error}`);
233
+ }
265
234
  }
266
235
  /**
267
236
  * @function getByXPath
@@ -274,15 +243,13 @@ class ElementModule {
274
243
  * @returns {Object} The found element.
275
244
  * @example const elem = await nonUi5.element.getByXPath("//ul/li/a");
276
245
  */
277
- getByXPath(xpath, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
278
- return __awaiter(this, void 0, void 0, function* () {
279
- try {
280
- return yield this.getByCss(xpath, index, timeout, includeHidden);
281
- }
282
- catch (error) {
283
- throw new Error(`Function 'getByXPath' failed. Element with XPath '${xpath}' not found. ${error}`);
284
- }
285
- });
246
+ async getByXPath(xpath, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
247
+ try {
248
+ return await this.getByCss(xpath, index, timeout, includeHidden);
249
+ }
250
+ catch (error) {
251
+ throw new Error(`Function 'getByXPath' failed. Element with XPath '${xpath}' not found. ${error}`);
252
+ }
286
253
  }
287
254
  /**
288
255
  * @function getByChild
@@ -296,30 +263,28 @@ class ElementModule {
296
263
  * @returns {Object} The found element.
297
264
  * @example const elem = await nonUi5.element.getByChild(".form01", ".input01");
298
265
  */
299
- getByChild(elementSelector, childSelector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- let elems;
302
- try {
303
- elems = includeHidden ? yield this.getAll(elementSelector, timeout) : yield this.getAllDisplayed(elementSelector, timeout);
304
- }
305
- catch (error) {
306
- throw new Error(`Function 'getByChild' failed. No element found for selector: "${elementSelector}".`);
307
- }
308
- const elementsWithChild = [];
309
- for (const element of elems) {
310
- const elem = yield element.$(childSelector);
311
- const toBeIncluded = includeHidden ? yield elem.isExisting() : yield elem.isDisplayed();
312
- if (toBeIncluded) {
313
- elementsWithChild.push(element);
314
- }
315
- }
316
- if (elementsWithChild.length === 0) {
317
- throw new Error(`Function 'getByChild' failed. The found element(s) with the given selector do(es) not have any child with selector ${childSelector}.`);
318
- }
319
- else {
320
- return elementsWithChild[index];
321
- }
322
- });
266
+ async getByChild(elementSelector, childSelector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
267
+ let elems;
268
+ try {
269
+ elems = includeHidden ? await this.getAll(elementSelector, timeout) : await this.getAllDisplayed(elementSelector, timeout);
270
+ }
271
+ catch (error) {
272
+ throw new Error(`Function 'getByChild' failed. No element found for selector: "${elementSelector}".`);
273
+ }
274
+ const elementsWithChild = [];
275
+ for (const element of elems) {
276
+ const elem = await element.$(childSelector);
277
+ const toBeIncluded = includeHidden ? await elem.isExisting() : await elem.isDisplayed();
278
+ if (toBeIncluded) {
279
+ elementsWithChild.push(element);
280
+ }
281
+ }
282
+ if (elementsWithChild.length === 0) {
283
+ throw new Error(`Function 'getByChild' failed. The found element(s) with the given selector do(es) not have any child with selector ${childSelector}.`);
284
+ }
285
+ else {
286
+ return elementsWithChild[index];
287
+ }
323
288
  }
324
289
  /**
325
290
  * @function getByParent
@@ -333,30 +298,28 @@ class ElementModule {
333
298
  * @returns {Object} The found element.
334
299
  * @example const elem = await nonUi5.element.getByParent(".form01", ".input01");
335
300
  */
336
- getByParent(elementSelector, parentSelector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
337
- return __awaiter(this, void 0, void 0, function* () {
338
- let parentElems = [];
339
- try {
340
- parentElems = includeHidden ? yield this.getAll(parentSelector, timeout) : yield this.getAllDisplayed(parentSelector, timeout);
341
- }
342
- catch (error) {
343
- throw new Error(`Function 'getByParent' failed. No parent element found for selector: ${parentSelector}: ${error}`);
344
- }
345
- const elementsWithParent = [];
346
- for (const parentElement of parentElems) {
347
- const elem = yield parentElement.$(elementSelector);
348
- const toBeIncluded = includeHidden ? yield elem.isExisting() : yield elem.isDisplayed();
349
- if (toBeIncluded) {
350
- elementsWithParent.push(elem);
351
- }
352
- }
353
- if (elementsWithParent.length === 0) {
354
- throw new Error(`Function 'getByParent' failed. No visible elements found for selector '${elementSelector}' and parent selector '${parentSelector}'`);
355
- }
356
- else {
357
- return elementsWithParent[index];
358
- }
359
- });
301
+ async getByParent(elementSelector, parentSelector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
302
+ let parentElems = [];
303
+ try {
304
+ parentElems = includeHidden ? await this.getAll(parentSelector, timeout) : await this.getAllDisplayed(parentSelector, timeout);
305
+ }
306
+ catch (error) {
307
+ throw new Error(`Function 'getByParent' failed. No parent element found for selector: ${parentSelector}: ${error}`);
308
+ }
309
+ const elementsWithParent = [];
310
+ for (const parentElement of parentElems) {
311
+ const elem = await parentElement.$(elementSelector);
312
+ const toBeIncluded = includeHidden ? await elem.isExisting() : await elem.isDisplayed();
313
+ if (toBeIncluded) {
314
+ elementsWithParent.push(elem);
315
+ }
316
+ }
317
+ if (elementsWithParent.length === 0) {
318
+ throw new Error(`Function 'getByParent' failed. No visible elements found for selector '${elementSelector}' and parent selector '${parentSelector}'`);
319
+ }
320
+ else {
321
+ return elementsWithParent[index];
322
+ }
360
323
  }
361
324
  // =================================== GET VALUES ===================================
362
325
  /**
@@ -370,20 +333,18 @@ class ElementModule {
370
333
  * @example const elem = await nonUi5.element.getById("button01");
371
334
  * await nonUi5.element.isVisible(elem);
372
335
  */
373
- isVisible(element, strict = true) {
374
- return __awaiter(this, void 0, void 0, function* () {
375
- try {
376
- if (strict) {
377
- return element.isDisplayedInViewport();
378
- }
379
- else {
380
- return element.isDisplayed();
381
- }
336
+ async isVisible(element, strict = true) {
337
+ try {
338
+ if (strict) {
339
+ return element.isDisplayedInViewport();
382
340
  }
383
- catch (error) {
384
- throw new Error(`Function 'isVisible' failed: ${error}`);
341
+ else {
342
+ return element.isDisplayed();
385
343
  }
386
- });
344
+ }
345
+ catch (error) {
346
+ throw new Error(`Function 'isVisible' failed: ${error}`);
347
+ }
387
348
  }
388
349
  /**
389
350
  * @function isPresent
@@ -394,10 +355,8 @@ class ElementModule {
394
355
  * @example const elem = await nonUi5.element.getById("button01");
395
356
  * await nonUi5.element.isPresent(elem);
396
357
  */
397
- isPresent(elem) {
398
- return __awaiter(this, void 0, void 0, function* () {
399
- return elem.isExisting();
400
- });
358
+ async isPresent(elem) {
359
+ return elem.isExisting();
401
360
  }
402
361
  /**
403
362
  * @function isPresentByCss
@@ -409,16 +368,14 @@ class ElementModule {
409
368
  * @returns {boolean} Returns true or false.
410
369
  * @example await nonUi5.element.isPresentByCss(".button01");
411
370
  */
412
- isPresentByCss(css, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
413
- return __awaiter(this, void 0, void 0, function* () {
414
- try {
415
- const elems = yield this.getAll(css, timeout);
416
- return elems[index].isExisting();
417
- }
418
- catch (error) {
419
- return false;
420
- }
421
- });
371
+ async isPresentByCss(css, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
372
+ try {
373
+ const elems = await this.getAll(css, timeout);
374
+ return elems[index].isExisting();
375
+ }
376
+ catch (error) {
377
+ return false;
378
+ }
422
379
  }
423
380
  /**
424
381
  * @function isPresentByXPath
@@ -430,10 +387,8 @@ class ElementModule {
430
387
  * @returns {boolean}
431
388
  * @example await nonUi5.element.isPresentByXPath(".//*[text()='Create']");
432
389
  */
433
- isPresentByXPath(xpath, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
434
- return __awaiter(this, void 0, void 0, function* () {
435
- return this.isPresentByCss(xpath, index, timeout);
436
- });
390
+ async isPresentByXPath(xpath, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
391
+ return this.isPresentByCss(xpath, index, timeout);
437
392
  }
438
393
  /**
439
394
  * @function getAttributeValue
@@ -447,30 +402,28 @@ class ElementModule {
447
402
  * @example const elem = await nonUi5.element.getById("elem02");
448
403
  * const innerHTML = await nonUi5.element.getAttributeValue(elem);
449
404
  */
450
- getAttributeValue(elem, attribute) {
451
- return __awaiter(this, void 0, void 0, function* () {
452
- if (typeof elem === "object" && elem !== null) {
453
- const tagName = yield elem.getTagName();
454
- if (attribute === "value" && (tagName === "input" || tagName === "textarea")) {
455
- return elem.getValue();
456
- }
457
- else if (attribute && attribute !== "textContent") {
458
- return elem.getAttribute(attribute);
459
- }
460
- else {
461
- if (attribute === "textContent") {
462
- const attributeValue = yield elem.getAttribute(attribute);
463
- if (attributeValue !== null)
464
- return attributeValue;
465
- }
466
- const [value, text] = yield Promise.all([elem.getValue(), elem.getText()]);
467
- return value || text;
468
- }
405
+ async getAttributeValue(elem, attribute) {
406
+ if (typeof elem === "object" && elem !== null) {
407
+ const tagName = await elem.getTagName();
408
+ if (attribute === "value" && (tagName === "input" || tagName === "textarea")) {
409
+ return elem.getValue();
410
+ }
411
+ else if (attribute && attribute !== "textContent") {
412
+ return elem.getAttribute(attribute);
469
413
  }
470
414
  else {
471
- throw new Error(`Function 'getAttributeValue' failed. Please provide an element as first argument (must be of type 'object').`);
415
+ if (attribute === "textContent") {
416
+ const attributeValue = await elem.getAttribute(attribute);
417
+ if (attributeValue !== null)
418
+ return attributeValue;
419
+ }
420
+ const [value, text] = await Promise.all([elem.getValue(), elem.getText()]);
421
+ return value || text;
472
422
  }
473
- });
423
+ }
424
+ else {
425
+ throw new Error(`Function 'getAttributeValue' failed. Please provide an element as first argument (must be of type 'object').`);
426
+ }
474
427
  }
475
428
  /**
476
429
  * @function getValue
@@ -481,16 +434,14 @@ class ElementModule {
481
434
  * @example const elem = await nonUi5.element.getById("elem02");
482
435
  * const innerHTML = await nonUi5.element.getValue(elem);
483
436
  */
484
- getValue(elem) {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- try {
487
- const [value, text] = yield Promise.all([elem.getValue(), elem.getText()]);
488
- return value || text;
489
- }
490
- catch (error) {
491
- throw new Error(`Function 'getValue' failed: ${error}`);
492
- }
493
- });
437
+ async getValue(elem) {
438
+ try {
439
+ const [value, text] = await Promise.all([elem.getValue(), elem.getText()]);
440
+ return value || text;
441
+ }
442
+ catch (error) {
443
+ throw new Error(`Function 'getValue' failed: ${error}`);
444
+ }
494
445
  }
495
446
  // =================================== SET VALUES ===================================
496
447
  /**
@@ -503,10 +454,8 @@ class ElementModule {
503
454
  * @example const elem = await nonUi5.element.getById("text-editor");
504
455
  * await nonUi5.element.setInnerHTML(elem, "Hello World!");
505
456
  */
506
- setInnerHTML(elem, value) {
507
- return __awaiter(this, void 0, void 0, function* () {
508
- yield browser.executeScript(`arguments[0].innerHTML = '${value}'`, [elem]);
509
- });
457
+ async setInnerHTML(elem, value) {
458
+ await browser.executeScript(`arguments[0].innerHTML = '${value}'`, [elem]);
510
459
  }
511
460
  // =================================== ACTIONS ===================================
512
461
  /**
@@ -521,12 +470,10 @@ class ElementModule {
521
470
  * @example const elem = await nonUi5.element.getById("text01");
522
471
  * await nonUi5.element.highlight(elem, 3000, "green");
523
472
  */
524
- highlight(elem, duration = 2000, color = "red") {
525
- return __awaiter(this, void 0, void 0, function* () {
526
- yield browser.executeScript(`arguments[0].style.boxShadow = 'inset 0px 0px 0px 2px ${color}'`, [elem]);
527
- yield browser.pause(duration);
528
- return browser.executeScript("arguments[0].style.boxShadow = 'inherit'", [elem]);
529
- });
473
+ async highlight(elem, duration = 2000, color = "red") {
474
+ await browser.executeScript(`arguments[0].style.boxShadow = 'inset 0px 0px 0px 2px ${color}'`, [elem]);
475
+ await browser.pause(duration);
476
+ return browser.executeScript("arguments[0].style.boxShadow = 'inherit'", [elem]);
530
477
  }
531
478
  // =================================== FRAMES (Deprecated) ===================================
532
479
  /**
@@ -538,11 +485,9 @@ class ElementModule {
538
485
  * @deprecated please use util.browser.switchToIframe
539
486
  * @see [util.browser.switchToIframe]{@link util.browser.switchToIframe}
540
487
  */
541
- switchToIframe(selector) {
542
- return __awaiter(this, void 0, void 0, function* () {
543
- util.console.warn(`⚠ "nonUi5.element.switchToIframe" is deprecated. Please use "util.browser.switchToIframe" instead.`);
544
- yield util.browser.switchToIframe(selector);
545
- });
488
+ async switchToIframe(selector) {
489
+ util.console.warn(`⚠ "nonUi5.element.switchToIframe" is deprecated. Please use "util.browser.switchToIframe" instead.`);
490
+ await util.browser.switchToIframe(selector);
546
491
  }
547
492
  /**
548
493
  * @function switchToDefaultContent
@@ -552,86 +497,76 @@ class ElementModule {
552
497
  * @deprecated please use util.browser.switchToDefaultContent
553
498
  * @see [util.browser.switchToDefaultContent]{@link util.browser.switchToDefaultContent}
554
499
  */
555
- switchToDefaultContent() {
556
- return __awaiter(this, void 0, void 0, function* () {
557
- util.console.warn(`⚠ "nonUi5.element.switchToDefaultContent" is deprecated. Please use "util.browser.switchToDefaultContent" instead.`);
558
- yield util.browser.switchToDefaultContent();
559
- });
500
+ async switchToDefaultContent() {
501
+ util.console.warn(`⚠ "nonUi5.element.switchToDefaultContent" is deprecated. Please use "util.browser.switchToDefaultContent" instead.`);
502
+ await util.browser.switchToDefaultContent();
560
503
  }
561
504
  // =================================== HELPER ===================================
562
- _waitForStabilization(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false, stableIterationsRequired = 3) {
563
- return __awaiter(this, void 0, void 0, function* () {
564
- let elemsCount = 0;
565
- let stableIterations = 0;
566
- yield browser.waitUntil(() => __awaiter(this, void 0, void 0, function* () {
567
- let currentElems = yield $$(selector);
568
- if (!includeHidden) {
569
- currentElems = yield this._filterDisplayed(currentElems);
570
- }
571
- const currentElemsCount = currentElems.length;
572
- if (currentElemsCount === elemsCount) {
573
- stableIterations++;
574
- }
575
- else {
576
- stableIterations = 0;
577
- }
578
- elemsCount = currentElemsCount;
579
- if (elemsCount !== 0 && stableIterations === stableIterationsRequired) {
580
- return true;
581
- }
582
- }), {
583
- timeout: timeout,
584
- timeoutMsg: elemsCount === 0 ? `Timeout reached. No element with passed selector found after ${+timeout / 1000}s.` : `Timeout reached. Page is still loading after ${+timeout / 1000}s.`,
585
- });
586
- });
587
- }
588
- _getAndFilterElementBySelector(selector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
589
- return __awaiter(this, void 0, void 0, function* () {
590
- yield this.waitForAll(selector, timeout, includeHidden);
591
- const elems = yield $$(selector);
592
- if (includeHidden) {
593
- return elems[index];
505
+ async _waitForStabilization(selector, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false, stableIterationsRequired = 3) {
506
+ let elemsCount = 0;
507
+ let stableIterations = 0;
508
+ await browser.waitUntil(async () => {
509
+ let currentElems = await $$(selector);
510
+ if (!includeHidden) {
511
+ currentElems = await this._filterDisplayed(currentElems);
512
+ }
513
+ const currentElemsCount = currentElems.length;
514
+ if (currentElemsCount === elemsCount) {
515
+ stableIterations++;
594
516
  }
595
517
  else {
596
- const visibleElems = yield this._filterDisplayed(elems);
597
- return visibleElems[index];
518
+ stableIterations = 0;
598
519
  }
599
- });
600
- }
601
- _filterByText(elems, text, strict = false) {
602
- return __awaiter(this, void 0, void 0, function* () {
603
- const filteredElems = [];
604
- for (const elem of elems) {
605
- const elementText = yield elem.getText();
606
- const strictEquasion = strict && elementText === text;
607
- const nonStrictEquasion = !strict && elementText.includes(text.trim());
608
- if (strictEquasion || nonStrictEquasion) {
609
- filteredElems.push(elem);
610
- }
611
- }
612
- if (filteredElems.length > 0) {
613
- return filteredElems;
614
- }
615
- else {
616
- throw new Error(`No element with text ${text} found.`);
520
+ elemsCount = currentElemsCount;
521
+ if (elemsCount !== 0 && stableIterations === stableIterationsRequired) {
522
+ return true;
617
523
  }
524
+ }, {
525
+ timeout: timeout,
526
+ timeoutMsg: elemsCount === 0 ? `Timeout reached. No element with passed selector found after ${+timeout / 1000}s.` : `Timeout reached. Page is still loading after ${+timeout / 1000}s.`,
618
527
  });
619
528
  }
620
- _filterDisplayed(elems) {
621
- return __awaiter(this, void 0, void 0, function* () {
622
- const filteredElems = [];
623
- for (const elem of elems) {
624
- if (yield elem.isDisplayed()) {
625
- filteredElems.push(elem);
626
- }
627
- }
628
- if (filteredElems.length > 0) {
629
- return filteredElems;
630
- }
631
- else {
632
- throw new Error(`No displayed element found.`);
633
- }
634
- });
529
+ async _getAndFilterElementBySelector(selector, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, includeHidden = false) {
530
+ await this.waitForAll(selector, timeout, includeHidden);
531
+ const elems = await $$(selector);
532
+ if (includeHidden) {
533
+ return elems[index];
534
+ }
535
+ else {
536
+ const visibleElems = await this._filterDisplayed(elems);
537
+ return visibleElems[index];
538
+ }
539
+ }
540
+ async _filterByText(elems, text, strict = false) {
541
+ const filteredElems = [];
542
+ for (const elem of elems) {
543
+ const elementText = await elem.getText();
544
+ const strictEquasion = strict && elementText === text;
545
+ const nonStrictEquasion = !strict && elementText.includes(text.trim());
546
+ if (strictEquasion || nonStrictEquasion) {
547
+ filteredElems.push(elem);
548
+ }
549
+ }
550
+ if (filteredElems.length > 0) {
551
+ return filteredElems;
552
+ }
553
+ else {
554
+ throw new Error(`No element with text ${text} found.`);
555
+ }
556
+ }
557
+ async _filterDisplayed(elems) {
558
+ const filteredElems = [];
559
+ for (const elem of elems) {
560
+ if (await elem.isDisplayed()) {
561
+ filteredElems.push(elem);
562
+ }
563
+ }
564
+ if (filteredElems.length > 0) {
565
+ return filteredElems;
566
+ }
567
+ else {
568
+ throw new Error(`No displayed element found.`);
569
+ }
635
570
  }
636
571
  }
637
572
  exports.ElementModule = ElementModule;