@playq/core 0.2.77

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 (225) hide show
  1. package/README.md +41 -0
  2. package/bin/playq.js +175 -0
  3. package/cucumber.js +10 -0
  4. package/dist/exec/featureFileCache.d.ts +21 -0
  5. package/dist/exec/featureFileCache.js +124 -0
  6. package/dist/exec/featureFilePreProcess.d.ts +12 -0
  7. package/dist/exec/featureFilePreProcess.js +208 -0
  8. package/dist/exec/preLoader.d.ts +1 -0
  9. package/dist/exec/preLoader.js +72 -0
  10. package/dist/exec/preProcessEntry.d.ts +1 -0
  11. package/dist/exec/preProcessEntry.js +83 -0
  12. package/dist/exec/preProcess_old_todelete.d.ts +1 -0
  13. package/dist/exec/preProcess_old_todelete.js +258 -0
  14. package/dist/exec/runner.d.ts +1 -0
  15. package/dist/exec/runner.js +221 -0
  16. package/dist/exec/runner_orchestrator.d.ts +1 -0
  17. package/dist/exec/runner_orchestrator.js +85 -0
  18. package/dist/exec/sgGenerator.d.ts +11 -0
  19. package/dist/exec/sgGenerator.js +310 -0
  20. package/dist/global.d.ts +15 -0
  21. package/dist/global.js +185 -0
  22. package/dist/helper/actions/api/apiRequestActions.d.ts +117 -0
  23. package/dist/helper/actions/api/apiRequestActions.js +374 -0
  24. package/dist/helper/actions/api/apiValidationActions.d.ts +119 -0
  25. package/dist/helper/actions/api/apiValidationActions.js +615 -0
  26. package/dist/helper/actions/apiActions.d.ts +18 -0
  27. package/dist/helper/actions/apiActions.js +34 -0
  28. package/dist/helper/actions/apiStepDefs.d.ts +1 -0
  29. package/dist/helper/actions/apiStepDefs.js +64 -0
  30. package/dist/helper/actions/comm/commonActions.d.ts +58 -0
  31. package/dist/helper/actions/comm/commonActions.js +198 -0
  32. package/dist/helper/actions/comm/utilityActions.d.ts +131 -0
  33. package/dist/helper/actions/comm/utilityActions.js +351 -0
  34. package/dist/helper/actions/commActions.d.ts +18 -0
  35. package/dist/helper/actions/commActions.js +34 -0
  36. package/dist/helper/actions/commStepDefs.d.ts +1 -0
  37. package/dist/helper/actions/commStepDefs.js +57 -0
  38. package/dist/helper/actions/stepGroupStepDefs.d.ts +1 -0
  39. package/dist/helper/actions/stepGroupStepDefs.js +15 -0
  40. package/dist/helper/actions/web/alertActions.d.ts +61 -0
  41. package/dist/helper/actions/web/alertActions.js +224 -0
  42. package/dist/helper/actions/web/cookieActions.d.ts +45 -0
  43. package/dist/helper/actions/web/cookieActions.js +186 -0
  44. package/dist/helper/actions/web/downloadActions.d.ts +40 -0
  45. package/dist/helper/actions/web/downloadActions.js +153 -0
  46. package/dist/helper/actions/web/elementReaderActions.d.ts +95 -0
  47. package/dist/helper/actions/web/elementReaderActions.js +326 -0
  48. package/dist/helper/actions/web/formActions.d.ts +122 -0
  49. package/dist/helper/actions/web/formActions.js +423 -0
  50. package/dist/helper/actions/web/iframeActions.d.ts +23 -0
  51. package/dist/helper/actions/web/iframeActions.js +108 -0
  52. package/dist/helper/actions/web/javascriptActions.d.ts +14 -0
  53. package/dist/helper/actions/web/javascriptActions.js +77 -0
  54. package/dist/helper/actions/web/keyboardActions.d.ts +35 -0
  55. package/dist/helper/actions/web/keyboardActions.js +118 -0
  56. package/dist/helper/actions/web/localStorageActions.d.ts +51 -0
  57. package/dist/helper/actions/web/localStorageActions.js +163 -0
  58. package/dist/helper/actions/web/mouseActions.d.ts +240 -0
  59. package/dist/helper/actions/web/mouseActions.js +609 -0
  60. package/dist/helper/actions/web/reportingActions.d.ts +34 -0
  61. package/dist/helper/actions/web/reportingActions.js +58 -0
  62. package/dist/helper/actions/web/screenshotActions.d.ts +34 -0
  63. package/dist/helper/actions/web/screenshotActions.js +151 -0
  64. package/dist/helper/actions/web/testDataActions.d.ts +21 -0
  65. package/dist/helper/actions/web/testDataActions.js +211 -0
  66. package/dist/helper/actions/web/validationActions.d.ts +547 -0
  67. package/dist/helper/actions/web/validationActions.js +1754 -0
  68. package/dist/helper/actions/web/waitActions.d.ts +191 -0
  69. package/dist/helper/actions/web/waitActions.js +589 -0
  70. package/dist/helper/actions/web/webNavigation.d.ts +104 -0
  71. package/dist/helper/actions/web/webNavigation.js +288 -0
  72. package/dist/helper/actions/webActions.d.ts +32 -0
  73. package/dist/helper/actions/webActions.js +48 -0
  74. package/dist/helper/actions/webStepDefs.d.ts +1 -0
  75. package/dist/helper/actions/webStepDefs.js +455 -0
  76. package/dist/helper/browsers/browserManager.d.ts +1 -0
  77. package/dist/helper/browsers/browserManager.js +56 -0
  78. package/dist/helper/bundle/defaultEntries.d.ts +6 -0
  79. package/dist/helper/bundle/defaultEntries.js +200 -0
  80. package/dist/helper/bundle/env.d.ts +1 -0
  81. package/dist/helper/bundle/env.js +157 -0
  82. package/dist/helper/bundle/vars.d.ts +9 -0
  83. package/dist/helper/bundle/vars.js +375 -0
  84. package/dist/helper/faker/customFaker.d.ts +55 -0
  85. package/dist/helper/faker/customFaker.js +45 -0
  86. package/dist/helper/faker/modules/data/postcodes_valid_sg.json +17 -0
  87. package/dist/helper/faker/modules/dateTime.d.ts +18 -0
  88. package/dist/helper/faker/modules/dateTime.js +106 -0
  89. package/dist/helper/faker/modules/mobile.d.ts +4 -0
  90. package/dist/helper/faker/modules/mobile.js +59 -0
  91. package/dist/helper/faker/modules/nric.d.ts +32 -0
  92. package/dist/helper/faker/modules/nric.js +84 -0
  93. package/dist/helper/faker/modules/passport.d.ts +3 -0
  94. package/dist/helper/faker/modules/passport.js +36 -0
  95. package/dist/helper/faker/modules/person.d.ts +14 -0
  96. package/dist/helper/faker/modules/person.js +73 -0
  97. package/dist/helper/faker/modules/postcode.d.ts +6 -0
  98. package/dist/helper/faker/modules/postcode.js +47 -0
  99. package/dist/helper/fixtures/locAggregate.d.ts +7 -0
  100. package/dist/helper/fixtures/locAggregate.js +94 -0
  101. package/dist/helper/fixtures/logFixture.d.ts +8 -0
  102. package/dist/helper/fixtures/logFixture.js +56 -0
  103. package/dist/helper/fixtures/webFixture.d.ts +19 -0
  104. package/dist/helper/fixtures/webFixture.js +186 -0
  105. package/dist/helper/fixtures/webLocFixture.d.ts +2 -0
  106. package/dist/helper/fixtures/webLocFixture.js +144 -0
  107. package/dist/helper/report/allureStepLogger.d.ts +0 -0
  108. package/dist/helper/report/allureStepLogger.js +25 -0
  109. package/dist/helper/report/customiseReport.d.ts +1 -0
  110. package/dist/helper/report/customiseReport.js +55 -0
  111. package/dist/helper/report/init.d.ts +1 -0
  112. package/dist/helper/report/init.js +14 -0
  113. package/dist/helper/report/report.d.ts +1 -0
  114. package/dist/helper/report/report.js +102 -0
  115. package/dist/helper/util/dataLoader.d.ts +10 -0
  116. package/dist/helper/util/dataLoader.js +73 -0
  117. package/dist/helper/util/logger.d.ts +4 -0
  118. package/dist/helper/util/logger.js +61 -0
  119. package/dist/helper/util/session/sessionUtil.d.ts +26 -0
  120. package/dist/helper/util/session/sessionUtil.js +729 -0
  121. package/dist/helper/util/stepHelpers.d.ts +2 -0
  122. package/dist/helper/util/stepHelpers.js +16 -0
  123. package/dist/helper/util/test-data/dataLoader.d.ts +7 -0
  124. package/dist/helper/util/test-data/dataLoader.js +145 -0
  125. package/dist/helper/util/test-data/dataTest.d.ts +10 -0
  126. package/dist/helper/util/test-data/dataTest.js +216 -0
  127. package/dist/helper/util/totp/totpHelper.d.ts +38 -0
  128. package/dist/helper/util/totp/totpHelper.js +117 -0
  129. package/dist/helper/util/utilities/cryptoUtil.d.ts +2 -0
  130. package/dist/helper/util/utilities/cryptoUtil.js +53 -0
  131. package/dist/helper/util/utilities/schemaGeneratorUtil.d.ts +2 -0
  132. package/dist/helper/util/utilities/schemaGeneratorUtil.js +129 -0
  133. package/dist/helper/util/utils.d.ts +2 -0
  134. package/dist/helper/util/utils.js +22 -0
  135. package/dist/helper/wrapper/PlaywrightWrappers.d.ts +8 -0
  136. package/dist/helper/wrapper/PlaywrightWrappers.js +26 -0
  137. package/dist/helper/wrapper/assert.d.ts +9 -0
  138. package/dist/helper/wrapper/assert.js +23 -0
  139. package/dist/index.d.ts +7 -0
  140. package/dist/index.js +57 -0
  141. package/dist/scripts/get-versions.d.ts +1 -0
  142. package/dist/scripts/get-versions.js +98 -0
  143. package/dist/scripts/posttest.d.ts +1 -0
  144. package/dist/scripts/posttest.js +29 -0
  145. package/dist/scripts/pretest.d.ts +1 -0
  146. package/dist/scripts/pretest.js +57 -0
  147. package/dist/scripts/util.d.ts +1 -0
  148. package/dist/scripts/util.js +376 -0
  149. package/package.json +68 -0
  150. package/src/exec/featureFileCache.ts +80 -0
  151. package/src/exec/featureFilePreProcess.ts +239 -0
  152. package/src/exec/preLoader.ts +72 -0
  153. package/src/exec/preProcessEntry.ts +59 -0
  154. package/src/exec/preProcess_old_todelete.ts +289 -0
  155. package/src/exec/runner.ts +241 -0
  156. package/src/exec/runnerCuke.js +90 -0
  157. package/src/exec/runner_orchestrator.ts +91 -0
  158. package/src/exec/sgGenerator.ts +373 -0
  159. package/src/global.ts +130 -0
  160. package/src/helper/actions/api/apiRequestActions.ts +362 -0
  161. package/src/helper/actions/api/apiValidationActions.ts +594 -0
  162. package/src/helper/actions/apiActions.ts +18 -0
  163. package/src/helper/actions/apiStepDefs.ts +80 -0
  164. package/src/helper/actions/comm/commonActions.ts +165 -0
  165. package/src/helper/actions/comm/utilityActions.ts +344 -0
  166. package/src/helper/actions/commActions.ts +18 -0
  167. package/src/helper/actions/commStepDefs.ts +72 -0
  168. package/src/helper/actions/stepGroupStepDefs.ts +17 -0
  169. package/src/helper/actions/web/alertActions.ts +179 -0
  170. package/src/helper/actions/web/cookieActions.ts +124 -0
  171. package/src/helper/actions/web/downloadActions.ts +129 -0
  172. package/src/helper/actions/web/elementReaderActions.ts +323 -0
  173. package/src/helper/actions/web/formActions.ts +469 -0
  174. package/src/helper/actions/web/iframeActions.ts +67 -0
  175. package/src/helper/actions/web/javascriptActions.ts +38 -0
  176. package/src/helper/actions/web/keyboardActions.ts +101 -0
  177. package/src/helper/actions/web/localStorageActions.ts +109 -0
  178. package/src/helper/actions/web/mouseActions.ts +864 -0
  179. package/src/helper/actions/web/reportingActions.ts +53 -0
  180. package/src/helper/actions/web/screenshotActions.ts +124 -0
  181. package/src/helper/actions/web/testDataActions.ts +162 -0
  182. package/src/helper/actions/web/validationActions.ts +2287 -0
  183. package/src/helper/actions/web/waitActions.ts +757 -0
  184. package/src/helper/actions/web/webNavigation.ts +313 -0
  185. package/src/helper/actions/webActions.ts +33 -0
  186. package/src/helper/actions/webStepDefs.ts +505 -0
  187. package/src/helper/browsers/browserManager.ts +23 -0
  188. package/src/helper/bundle/defaultEntries.ts +208 -0
  189. package/src/helper/bundle/env.ts +119 -0
  190. package/src/helper/bundle/vars.ts +368 -0
  191. package/src/helper/faker/customFaker.ts +107 -0
  192. package/src/helper/faker/modules/data/postcodes_valid_sg.json +17 -0
  193. package/src/helper/faker/modules/dateTime.ts +121 -0
  194. package/src/helper/faker/modules/mobile.ts +58 -0
  195. package/src/helper/faker/modules/nric.ts +109 -0
  196. package/src/helper/faker/modules/passport.ts +34 -0
  197. package/src/helper/faker/modules/person.ts +93 -0
  198. package/src/helper/faker/modules/postcode.ts +57 -0
  199. package/src/helper/fixtures/locAggregate.ts +61 -0
  200. package/src/helper/fixtures/logFixture.ts +57 -0
  201. package/src/helper/fixtures/webFixture.ts +206 -0
  202. package/src/helper/fixtures/webLocFixture.ts +143 -0
  203. package/src/helper/report/allureStepLogger.ts +26 -0
  204. package/src/helper/report/customiseReport.ts +61 -0
  205. package/src/helper/report/init.ts +18 -0
  206. package/src/helper/report/report.ts +72 -0
  207. package/src/helper/util/dataLoader.ts +42 -0
  208. package/src/helper/util/logger.ts +32 -0
  209. package/src/helper/util/session/sessionUtil.ts +839 -0
  210. package/src/helper/util/stepHelpers.ts +14 -0
  211. package/src/helper/util/test-data/dataLoader.ts +108 -0
  212. package/src/helper/util/test-data/dataTest.ts +191 -0
  213. package/src/helper/util/test-data/registerUser.json +7 -0
  214. package/src/helper/util/totp/totpHelper.ts +102 -0
  215. package/src/helper/util/utilities/cryptoUtil.ts +53 -0
  216. package/src/helper/util/utilities/schemaGeneratorUtil.ts +143 -0
  217. package/src/helper/util/utils.ts +28 -0
  218. package/src/helper/wrapper/PlaywrightWrappers.ts +28 -0
  219. package/src/helper/wrapper/assert.ts +25 -0
  220. package/src/index.ts +17 -0
  221. package/src/scripts/get-versions.ts +68 -0
  222. package/src/scripts/posttest.ts +32 -0
  223. package/src/scripts/pretest.ts +48 -0
  224. package/src/scripts/util.ts +406 -0
  225. package/tsconfig.json +30 -0
@@ -0,0 +1,589 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.wait = wait;
37
+ exports.waitForCondition = waitForCondition;
38
+ exports.waitForPageToLoad = waitForPageToLoad;
39
+ exports.waitForEnabled = waitForEnabled;
40
+ exports.waitForDisplayed = waitForDisplayed;
41
+ exports.waitForDisappear = waitForDisappear;
42
+ exports.waitForTextAtLocation = waitForTextAtLocation;
43
+ exports.waitForTextToDisappearAtLocation = waitForTextToDisappearAtLocation;
44
+ exports.waitForSelector = waitForSelector;
45
+ exports.waitForHeader = waitForHeader;
46
+ exports.waitForInputState = waitForInputState;
47
+ exports.waitForUrl = waitForUrl;
48
+ /**
49
+ * @file waitActions.ts
50
+ *
51
+ * Wait utilities for PlayQ web actions.
52
+ * Provides time-based waits, page load settling, element visibility/state
53
+ * waits, header/text waits, and URL waits with runner-aware step wrappers.
54
+ *
55
+ * Authors: PlayQ Team
56
+ * Version: v1.0.0
57
+ */
58
+ const allure = __importStar(require("allure-js-commons"));
59
+ const test_1 = require("@playwright/test");
60
+ const global_1 = require("../../../global");
61
+ const webLocFixture_1 = require("../../fixtures/webLocFixture");
62
+ const screenshotActions_1 = require("./screenshotActions");
63
+ const commonActions_1 = require("../comm/commonActions");
64
+ const vars_1 = require("../../bundle/vars");
65
+ function isPlaywrightRunner() { return process.env.TEST_RUNNER === 'playwright'; }
66
+ const __allureAny_wait = allure;
67
+ if (typeof __allureAny_wait.step !== 'function') {
68
+ __allureAny_wait.step = async (_n, f) => await f();
69
+ }
70
+ /**
71
+ * Comm: Wait-In-Milli-Seconds -seconds: {param}
72
+ *
73
+ * Pauses execution for the given number of milliseconds.
74
+ * Delegates to `comm.waitInMilliSeconds`.
75
+ *
76
+ * @param ms Milliseconds to wait
77
+ */
78
+ async function wait(ms) {
79
+ return global_1.comm.waitInMilliSeconds(ms);
80
+ }
81
+ /**
82
+ * Web: Wait For Condition -timeout: {param}
83
+ *
84
+ * Polls a predicate until it returns true or times out.
85
+ *
86
+ * @param page Playwright Page instance
87
+ * @param predicate Async function returning a boolean
88
+ * @param options Optional JSON string or object ({ timeout, interval })
89
+ */
90
+ async function waitForCondition(page, predicate, options) {
91
+ const options_json = typeof options === 'string' ? global_1.vars.parseLooseJson(options) : options || {};
92
+ const { timeout = Number(global_1.vars.getConfigValue('testExecution.actionTimeout')) || 10000, interval = 250 } = options_json;
93
+ const stepName = `Web: Wait For Condition -timeout: ${timeout}`;
94
+ const start = Date.now();
95
+ async function loop() {
96
+ while (Date.now() - start < timeout) {
97
+ if (await predicate(page))
98
+ return true;
99
+ await global_1.comm.waitInMilliSeconds(interval);
100
+ }
101
+ throw new Error('Condition not met within timeout');
102
+ }
103
+ if (isPlaywrightRunner()) {
104
+ await __allureAny_wait.step(stepName, loop);
105
+ }
106
+ else {
107
+ await loop();
108
+ }
109
+ }
110
+ /**
111
+ * Waits for the page to fully load by checking multiple browser states:
112
+ * - `domcontentloaded`: Ensures DOM is parsed and ready.
113
+ * - `load`: Waits for all resources like images and scripts to load.
114
+ * - `requestIdleCallback`: Ensures the browser is idle before proceeding.
115
+ *
116
+ * This function is useful after navigation, form submission, or any page transition
117
+ * to ensure stable element interaction.
118
+ *
119
+ * @param page - The Playwright Page instance.
120
+ * @param actionTimeout - Optional timeout (in ms) to wait for each load state. Default: 10000.
121
+ *
122
+ */
123
+ async function waitForPageToLoad(page, actionTimeout = 10000) {
124
+ const wait = (ms) => new Promise((res) => setTimeout(res, ms));
125
+ console.log("⏳ Waiting for DOMContentLoaded...");
126
+ try {
127
+ await page.waitForLoadState("domcontentloaded", { timeout: actionTimeout });
128
+ console.log("✅ DOMContentLoaded");
129
+ }
130
+ catch {
131
+ console.warn("⚠️ DOMContentLoaded not detected within timeout");
132
+ }
133
+ console.log("🔄 Waiting for load event...");
134
+ try {
135
+ await page.waitForLoadState("load", { timeout: actionTimeout });
136
+ console.log("✅ Load event");
137
+ }
138
+ catch {
139
+ console.warn("⚠️ Page load event not triggered within timeout");
140
+ }
141
+ console.log("🕓 Waiting for browser idle callback...");
142
+ try {
143
+ await page.evaluate(() => {
144
+ return new Promise((resolve) => {
145
+ window.requestIdleCallback(() => resolve(true));
146
+ });
147
+ });
148
+ console.log("✅ requestIdleCallback done");
149
+ }
150
+ catch {
151
+ console.warn("⚠️ requestIdleCallback failed or delayed");
152
+ }
153
+ }
154
+ /**
155
+ * Waits for a given locator (element) to become enabled within the specified timeout.
156
+ * Useful before interacting with inputs, buttons, or other dynamic UI elements.
157
+ *
158
+ * @param locator - The Playwright Locator to wait for (e.g., input field, button).
159
+ * @param actionTimeout - Optional timeout (in ms). Default: 5000.
160
+ *
161
+ * @throws Error if the locator does not become enabled within the timeout.
162
+ *
163
+ */
164
+ async function waitForEnabled(locator, actionTimeout = 5000) {
165
+ await (0, test_1.expect)(locator).toBeEnabled({ timeout: actionTimeout });
166
+ }
167
+ /**
168
+ * Web: Wait for displayed -field: {param} -options: {param}
169
+ *
170
+ * Waits for an element to become visible on the page.
171
+ *
172
+ * @param page - Playwright Page instance
173
+ * @param field - The label, id, name, or selector of the element to wait for
174
+ * @param options - Optional JSON string or object:
175
+ * - actionTimeout: [number] Optional timeout in milliseconds. Default: Configured timeout.
176
+ * - pattern: [string] Optional pattern to refine element search.
177
+ * - fieldType: [string] Type of field (e.g., input, button, etc.)
178
+ * - screenshot: [boolean] Capture screenshot after waiting. Default: false.
179
+ * - screenshotText: [string] Description for screenshot.
180
+ * - screenshotFullPage: [boolean] Full page screenshot. Default: true.
181
+ */
182
+ async function waitForDisplayed(page, field, options) {
183
+ const options_json = typeof options === "string" ? global_1.vars.parseLooseJson(options) : options || {};
184
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")) || 30000, pattern, fieldType, screenshot = false, screenshotText = "", screenshotFullPage = true } = options_json;
185
+ const stepName = `Web: Wait for displayed -field: ${String(field)} -options: ${JSON.stringify(options_json)}`;
186
+ async function run() {
187
+ if (!page)
188
+ throw new Error("Page not initialized");
189
+ const target = typeof field === "string" ? await (0, webLocFixture_1.webLocResolver)(fieldType, field, page, pattern, actionTimeout) : field;
190
+ try {
191
+ await target.waitFor({ state: "visible", timeout: actionTimeout });
192
+ await (0, commonActions_1.attachLog)(`✅ Element "${String(field)}" is now visible`, "text/plain", "Log");
193
+ }
194
+ catch {
195
+ throw new Error(`❌ Element "${String(field)}" did not become visible within ${actionTimeout}ms`);
196
+ }
197
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for element to be displayed: ${String(field)}`, screenshotFullPage);
198
+ }
199
+ if (isPlaywrightRunner()) {
200
+ await __allureAny_wait.step(stepName, run);
201
+ }
202
+ else {
203
+ await run();
204
+ }
205
+ }
206
+ /**
207
+ * Web: Wait for disappear -field: {param} -options: {param}
208
+ *
209
+ * Waits for an element to disappear (become hidden or removed) from the page.
210
+ *
211
+ * @param page - Playwright Page instance
212
+ * @param field - The label, id, name, or selector of the element to wait for
213
+ * @param options - Optional JSON string or object:
214
+ * - actionTimeout: [number] Optional timeout in milliseconds. Default: Configured timeout.
215
+ * - pattern: [string] Optional pattern to refine element search.
216
+ * - fieldType: [string] Type of field (e.g., input, button, etc.)
217
+ * - screenshot: [boolean] Capture screenshot after waiting. Default: false.
218
+ * - screenshotText: [string] Description for screenshot.
219
+ * - screenshotFullPage: [boolean] Full page screenshot. Default: true.
220
+ */
221
+ async function waitForDisappear(page, field, options) {
222
+ const options_json = typeof options === "string" ? global_1.vars.parseLooseJson(options) : options || {};
223
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")) || 30000, pattern, fieldType, screenshot = false, screenshotText = "", screenshotFullPage = true } = options_json;
224
+ const stepName = `Web: Wait for disappear -field: ${String(field)} -options: ${JSON.stringify(options_json)}`;
225
+ async function run() {
226
+ if (!page)
227
+ throw new Error("Page not initialized");
228
+ const target = typeof field === "string" ? await (0, webLocFixture_1.webLocResolver)(fieldType, field, page, pattern, actionTimeout) : field;
229
+ try {
230
+ await target.waitFor({ state: "hidden", timeout: actionTimeout });
231
+ await (0, commonActions_1.attachLog)(`✅ Element "${String(field)}" has disappeared`, "text/plain", "Log");
232
+ }
233
+ catch {
234
+ throw new Error(`❌ Element "${String(field)}" did not disappear within ${actionTimeout}ms`);
235
+ }
236
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for element to disappear: ${String(field)}`, screenshotFullPage);
237
+ }
238
+ if (isPlaywrightRunner()) {
239
+ await __allureAny_wait.step(stepName, run);
240
+ }
241
+ else {
242
+ await run();
243
+ }
244
+ }
245
+ /**
246
+ * Web: Wait for Text at Location -field: {param} -text: {param} -options: {param}
247
+ *
248
+ * Waits until the specified text appears at the given field/locator.
249
+ *
250
+ * @param page - Playwright Page instance
251
+ * @param field - The selector or Locator where the text should appear
252
+ * @param expectedText - The text to wait for
253
+ * @param options - Optional string or object:
254
+ * - actionTimeout: [number] Timeout in ms (default: 30000)
255
+ * - partialMatch: [boolean] If true, waits for substring match (default: false)
256
+ * - caseSensitive: [boolean] If true, match is case-sensitive (default: true)
257
+ * - screenshot: [boolean] Capture screenshot after waiting (default: false)
258
+ * - screenshotText: [string] Description for screenshot
259
+ * - screenshotFullPage: [boolean] Full page screenshot (default: true)
260
+ *
261
+ * @example
262
+ * await waitForTextAtLocation(page, 'h1', 'Welcome', { actionTimeout: 10000, partialMatch: true });
263
+ */
264
+ async function waitForTextAtLocation(page, field, expectedText, options) {
265
+ const options_json = typeof options === "string" ? (0, vars_1.parseLooseJson)(options) : options || {};
266
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")), partialMatch = false, ignoreCase = true, screenshot = false, screenshotText = "", screenshotFullPage = true, pattern, } = options_json;
267
+ if (!page)
268
+ throw new Error("Page not initialized");
269
+ if (isPlaywrightRunner()) {
270
+ await __allureAny_wait.step(`Web: Wait for Text at Location -field: ${field} -text: ${expectedText} -options: ${JSON.stringify(options_json)}`, async () => {
271
+ await doWaitForTextAtLocation();
272
+ });
273
+ }
274
+ else {
275
+ await doWaitForTextAtLocation();
276
+ }
277
+ async function doWaitForTextAtLocation() {
278
+ const target = typeof field === "string"
279
+ ? await (0, webLocFixture_1.webLocResolver)("text", field, page, pattern, actionTimeout)
280
+ : field;
281
+ const start = Date.now();
282
+ let found = false;
283
+ let lastActual = "";
284
+ while (Date.now() - start < actionTimeout) {
285
+ const actualText = ((await target.innerText()) || "").trim();
286
+ lastActual = actualText;
287
+ let expected = expectedText;
288
+ let actual = actualText;
289
+ if (!ignoreCase) {
290
+ expected = expected.toLowerCase();
291
+ actual = actual.toLowerCase();
292
+ }
293
+ if (partialMatch ? actual.includes(expected) : actual === expected) {
294
+ found = true;
295
+ break;
296
+ }
297
+ await new Promise((res) => setTimeout(res, 300));
298
+ }
299
+ if (!found) {
300
+ const msg = `❌ Text "${expectedText}" did not appear at location "${field}" within ${actionTimeout}ms. Last actual: "${lastActual}"`;
301
+ await (0, commonActions_1.attachLog)(msg, "text/plain");
302
+ throw new Error(msg);
303
+ }
304
+ else {
305
+ await (0, commonActions_1.attachLog)(`✅ Text "${expectedText}" appeared at location "${field}"`, "text/plain");
306
+ }
307
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for text at location: ${expectedText}`, screenshotFullPage);
308
+ }
309
+ }
310
+ /**
311
+ * Web: Wait for Text to Disappear at Location -field: {param} -text: {param} -options: {param}
312
+ *
313
+ * Waits until the specified text disappears from the given field/locator.
314
+ *
315
+ * @param page - Playwright Page instance
316
+ * @param field - The selector or Locator where the text should disappear
317
+ * @param textToDisappear - The text to wait for disappearance
318
+ * @param options - Optional string or object:
319
+ * - actionTimeout: [number] Timeout in ms (default: 30000)
320
+ * - partialMatch: [boolean] If true, waits for substring match (default: false)
321
+ * - ignoreCase: [boolean] If true, match is case-insensitive (default: true)
322
+ * - screenshot: [boolean] Capture screenshot after waiting (default: false)
323
+ * - screenshotText: [string] Description for screenshot
324
+ * - screenshotFullPage: [boolean] Full page screenshot (default: true)
325
+ */
326
+ async function waitForTextToDisappearAtLocation(page, field, textToDisappear, options) {
327
+ const options_json = typeof options === "string" ? (0, vars_1.parseLooseJson)(options) : options || {};
328
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")) || 30000, partialMatch = true, ignoreCase = true, screenshot = false, screenshotText = "", screenshotFullPage = true, } = options_json;
329
+ if (!page)
330
+ throw new Error("Page not initialized");
331
+ let locator;
332
+ if (typeof field === "string") {
333
+ // ✅ Build regex safely
334
+ const escapedText = textToDisappear.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
335
+ const pattern = partialMatch
336
+ ? `.*${escapedText}.*`
337
+ : `^${escapedText}$`;
338
+ const regex = new RegExp(pattern, ignoreCase ? "i" : undefined);
339
+ locator = page.getByText(regex);
340
+ }
341
+ else {
342
+ locator = field;
343
+ }
344
+ await locator.waitFor({
345
+ state: "hidden",
346
+ timeout: actionTimeout,
347
+ });
348
+ await (0, commonActions_1.attachLog)(`✅ Text "${textToDisappear}" disappeared (partialMatch=${partialMatch}, ignoreCase=${ignoreCase})`, "text/plain");
349
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for text to disappear: ${textToDisappear}`, screenshotFullPage);
350
+ }
351
+ /**
352
+ * Web: Wait for Selector -field: {param} -options: {param}
353
+ *
354
+ * Waits for a selector or locator to reach a specific state.
355
+ *
356
+ * @param page - Playwright Page instance
357
+ * @param field - The selector string or Locator to wait for
358
+ * @param options - Optional string or object:
359
+ * - fieldType: [string] Type of field (e.g., 'button', 'input') for pattern resolution
360
+ * - state: [string] 'attached' | 'detached' | 'visible' | 'hidden' (default: 'visible')
361
+ * - actionTimeout: [number] Timeout in ms (default: 30000)
362
+ * - pattern: [string] Optional pattern for locator resolution
363
+ * - screenshot: [boolean] Capture screenshot after waiting (default: false)
364
+ * - screenshotText: [string] Description for screenshot
365
+ * - screenshotFullPage: [boolean] Full page screenshot (default: true)
366
+ *
367
+ * @example
368
+ * await waitForSelector(page, 'img[alt="~"]', { state: 'hidden', actionTimeout: 10000 });
369
+ */
370
+ async function waitForSelector(page, field, options) {
371
+ const options_json = typeof options === "string" ? (0, vars_1.parseLooseJson)(options) : options || {};
372
+ const { fieldType, state = "visible", actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")) || 30000, pattern, screenshot = false, screenshotText = "", screenshotFullPage = true, } = options_json;
373
+ if (!page)
374
+ throw new Error("Page not initialized");
375
+ if (isPlaywrightRunner()) {
376
+ await __allureAny_wait.step(`Web: Wait for Selector -field: ${field} -state: ${state} -options: ${JSON.stringify(options_json)}`, async () => {
377
+ await doWaitForSelector();
378
+ });
379
+ }
380
+ else {
381
+ await doWaitForSelector();
382
+ }
383
+ async function doWaitForSelector() {
384
+ if (typeof field === "string" && !fieldType) {
385
+ throw new Error(`fieldType is required for string selectors. Received field="${field}"`);
386
+ }
387
+ let target;
388
+ if (typeof field === "string") {
389
+ if (state === "hidden" || state === "detached") {
390
+ if (fieldType === "text") {
391
+ target = page.getByText(field, { exact: false });
392
+ }
393
+ else {
394
+ target = page.locator(`//*[normalize-space()='${field}']`);
395
+ }
396
+ }
397
+ else {
398
+ target = await (0, webLocFixture_1.webLocResolver)(fieldType, field, page, pattern, actionTimeout);
399
+ }
400
+ }
401
+ else {
402
+ target = field;
403
+ }
404
+ await target.waitFor({ state, timeout: actionTimeout });
405
+ await (0, commonActions_1.attachLog)(`✅ Selector "${field}" reached state "${state}".`, "text/plain");
406
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for selector: ${field} state: ${state}`, screenshotFullPage);
407
+ }
408
+ }
409
+ /**
410
+ * Web: Wait for Header -header: {param} -text: {param} -options: {param}
411
+ *
412
+ * Waits until a specific header element contains the expected text.
413
+ * The header parameter should be a locator or will use pattern resolution.
414
+ *
415
+ * @param page - Playwright Page instance
416
+ * @param header - The locator of the header element (e.g., "h1", "xpath=//h1[@class='title']", or Locator object)
417
+ * @param headerText - The expected header text to wait for (e.g., "Welcome", "Dashboard")
418
+ * @param options - Optional string or object:
419
+ * - actionTimeout: [number] Timeout in ms (default: 30000)
420
+ * - partialMatch: [boolean] If true, waits for substring match (default: false)
421
+ * - ignoreCase: [boolean] If true, case-insensitive match (default: true)
422
+ * - pattern: [string] Optional pattern to refine element search
423
+ * - screenshot: [boolean] Capture screenshot after waiting (default: false)
424
+ * - screenshotText: [string] Description for screenshot
425
+ * - screenshotFullPage: [boolean] Full page screenshot (default: true)
426
+ *
427
+ * @example
428
+ * await waitForHeader(page, 'h1', 'Welcome Back!', {
429
+ * partialMatch: true,
430
+ * screenshot: true
431
+ * });
432
+ */
433
+ async function waitForHeader(page, header, headerText, options) {
434
+ const resolvedHeaderText = global_1.vars.replaceVariables(headerText);
435
+ const options_json = typeof options === "string" ? (0, vars_1.parseLooseJson)(options) : options || {};
436
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")) || 30000, partialMatch = false, ignoreCase = true, pattern, screenshot = false, screenshotText = "", screenshotFullPage = true, } = options_json;
437
+ if (!page)
438
+ throw new Error("Page not initialized");
439
+ if (isPlaywrightRunner()) {
440
+ await __allureAny_wait.step(`Web: Wait for Header -header: ${header} -text: ${resolvedHeaderText} -options: ${JSON.stringify(options_json)}`, async () => {
441
+ await doWaitForHeader();
442
+ });
443
+ }
444
+ else {
445
+ await doWaitForHeader();
446
+ }
447
+ async function doWaitForHeader() {
448
+ // Use webLocResolver for header locator resolution or direct Locator
449
+ const target = typeof header === "string"
450
+ ? await (0, webLocFixture_1.webLocResolver)("header", header, page, pattern, actionTimeout)
451
+ : header;
452
+ const start = Date.now();
453
+ let found = false;
454
+ let lastActualText = "";
455
+ while (Date.now() - start < actionTimeout) {
456
+ try {
457
+ // Check if header is visible and get its text
458
+ if (await target.isVisible()) {
459
+ const actualText = (await target.innerText()).trim();
460
+ lastActualText = actualText;
461
+ let expected = resolvedHeaderText;
462
+ let actual = actualText;
463
+ // Apply case sensitivity
464
+ if (ignoreCase) {
465
+ expected = expected.toLowerCase();
466
+ actual = actual.toLowerCase();
467
+ }
468
+ // Check for match
469
+ const isMatch = partialMatch
470
+ ? actual.includes(expected)
471
+ : actual === expected;
472
+ if (isMatch) {
473
+ found = true;
474
+ await (0, commonActions_1.attachLog)(`✅ Header found: "${actualText}" matches expected "${resolvedHeaderText}"`, "text/plain");
475
+ break;
476
+ }
477
+ }
478
+ // Wait before next check
479
+ await new Promise((resolve) => setTimeout(resolve, 300));
480
+ }
481
+ catch (error) {
482
+ // Continue waiting if there's an error
483
+ await new Promise((resolve) => setTimeout(resolve, 300));
484
+ }
485
+ }
486
+ if (!found) {
487
+ const msg = `❌ Header text "${resolvedHeaderText}" did not appear at locator "${header}" within ${actionTimeout}ms. Last seen: "${lastActualText}"`;
488
+ await (0, commonActions_1.attachLog)(msg, "text/plain");
489
+ throw new Error(msg);
490
+ }
491
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for header: ${resolvedHeaderText}`, screenshotFullPage);
492
+ }
493
+ }
494
+ /**
495
+ * Web: Wait for Input -field: {param} -state: {param} (enabled or disabled) -options: {param}
496
+ *
497
+ * Waits for an input field to become 'enabled' or 'disabled'.
498
+ *
499
+ * @param page - Playwright Page instance
500
+ * @param field - Locator or label of the input field
501
+ * @param state - Desired state: 'enabled' or 'disabled'
502
+ * @param options - Optional string or object:
503
+ * - actionTimeout: [number] Optional timeout in milliseconds for waiting. Default: from [config] or 30000.
504
+ * - pattern: [string] Optional pattern to refine element search.
505
+ * - screenshot: [boolean] Capture a screenshot. Default: true.
506
+ * - screenshotText: [string] Description for the screenshot.
507
+ * - screenshotFullPage: [boolean] Capture full page screenshot. Default: true.
508
+ * - smartIQ_refreshLoc: optional override for locator refresh key
509
+ */
510
+ async function waitForInputState(page, field, state, options) {
511
+ const options_json = typeof options === "string" ? (0, vars_1.parseLooseJson)(options) : options || {};
512
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")), pattern, screenshot = false, screenshotText = "", screenshotFullPage = true, smartIQ_refreshLoc = "", } = options_json;
513
+ if (isPlaywrightRunner()) {
514
+ await __allureAny_wait.step(`Web: Wait for Input -field: ${field} -state: ${state} (enabled or disabled) -options: ${JSON.stringify(options_json)}`, async () => {
515
+ await doWaitForInputState();
516
+ });
517
+ }
518
+ else {
519
+ await doWaitForInputState();
520
+ }
521
+ async function doWaitForInputState() {
522
+ if (!page)
523
+ throw new Error("Page not initialized");
524
+ const target = typeof field === "string"
525
+ ? await (0, webLocFixture_1.webLocResolver)("input", field, page, pattern, actionTimeout, smartIQ_refreshLoc)
526
+ : field;
527
+ try {
528
+ if (state === "enabled") {
529
+ await (0, test_1.expect)(target).toBeEnabled({ timeout: actionTimeout });
530
+ }
531
+ else if (state === "disabled") {
532
+ await (0, test_1.expect)(target).toBeDisabled({ timeout: actionTimeout });
533
+ }
534
+ else {
535
+ throw new Error(`Invalid state "${state}". Use "enabled" or "disabled".`);
536
+ }
537
+ }
538
+ catch (e) {
539
+ throw new Error(`❌ Input "${field}" did not reach state "${state}" within ${actionTimeout}ms. ${e}`);
540
+ }
541
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || `Waited for input state: ${state}`, screenshotFullPage);
542
+ }
543
+ }
544
+ /**
545
+ * Web: Wait for URL -url: {param} -options: {param}
546
+ *
547
+ * Waits until the current page URL matches or contains the specified string or regex.
548
+ *
549
+ * @param url - The expected URL or substring/regex to match (e.g., "/dashboard", "https://example.com/page").
550
+ * @param options - Optional JSON string or object:
551
+ * - actionTimeout: [number] Timeout in ms to wait for URL. Default: 30000.
552
+ * - match: [string] "exact" | "contains" . Default: "contains".
553
+ * - assert: [boolean] If false, logs the failure but does not throw. Default: true.
554
+ * - screenshot: [boolean] If true, captures screenshot. Default: false.
555
+ * - screenshotText: [string] Custom screenshot label.
556
+ * - screenshotFullPage: [boolean] Full page screenshot. Default: true.
557
+ */
558
+ async function waitForUrl(page, url, options) {
559
+ const options_json = typeof options === "string" ? (0, vars_1.parseLooseJson)(options) : options || {};
560
+ const { actionTimeout = Number(global_1.vars.getConfigValue("testExecution.actionTimeout")), match = "contains", screenshot = false, screenshotText, screenshotFullPage = true, } = options_json;
561
+ if (isPlaywrightRunner()) {
562
+ await __allureAny_wait.step(`Web: Wait for URL -url: ${url} -options: ${JSON.stringify(options_json)}`, async () => {
563
+ await doWaitForUrl();
564
+ });
565
+ }
566
+ else {
567
+ await doWaitForUrl();
568
+ }
569
+ async function doWaitForUrl() {
570
+ try {
571
+ if (match === "exact") {
572
+ await page.waitForURL(url.toString(), { timeout: actionTimeout });
573
+ }
574
+ else if (match === "contains") {
575
+ const cleanUrl = url.replace(/^\/|\/$/g, "");
576
+ const regexUrl = new RegExp(escapeRegExp(cleanUrl), "i");
577
+ await (0, test_1.expect)(page).toHaveURL(regexUrl, { timeout: actionTimeout });
578
+ }
579
+ }
580
+ catch (error) {
581
+ throw new Error(`⚠️ waitForUrl failed: ${error.message}`);
582
+ }
583
+ await waitForPageToLoad(page);
584
+ await (0, screenshotActions_1.processScreenshot)(page, screenshot, screenshotText || "", screenshotFullPage);
585
+ }
586
+ }
587
+ function escapeRegExp(str) {
588
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
589
+ }