automation_model 1.0.464-dev → 1.0.464

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 (77) hide show
  1. package/README.md +133 -0
  2. package/lib/analyze_helper.js.map +1 -1
  3. package/lib/api.d.ts +43 -2
  4. package/lib/api.js +240 -49
  5. package/lib/api.js.map +1 -1
  6. package/lib/auto_page.d.ts +7 -2
  7. package/lib/auto_page.js +282 -26
  8. package/lib/auto_page.js.map +1 -1
  9. package/lib/browser_manager.d.ts +6 -3
  10. package/lib/browser_manager.js +163 -47
  11. package/lib/browser_manager.js.map +1 -1
  12. package/lib/bruno.d.ts +2 -0
  13. package/lib/bruno.js +381 -0
  14. package/lib/bruno.js.map +1 -0
  15. package/lib/check_performance.d.ts +1 -0
  16. package/lib/check_performance.js +57 -0
  17. package/lib/check_performance.js.map +1 -0
  18. package/lib/command_common.d.ts +6 -0
  19. package/lib/command_common.js +218 -0
  20. package/lib/command_common.js.map +1 -0
  21. package/lib/date_time.js.map +1 -1
  22. package/lib/drawRect.js.map +1 -1
  23. package/lib/environment.d.ts +1 -0
  24. package/lib/environment.js +6 -3
  25. package/lib/environment.js.map +1 -1
  26. package/lib/error-messages.d.ts +6 -0
  27. package/lib/error-messages.js +206 -0
  28. package/lib/error-messages.js.map +1 -0
  29. package/lib/file_checker.d.ts +1 -0
  30. package/lib/file_checker.js +165 -0
  31. package/lib/file_checker.js.map +1 -0
  32. package/lib/find_function.js.map +1 -1
  33. package/lib/generation_scripts.d.ts +4 -0
  34. package/lib/generation_scripts.js +2 -0
  35. package/lib/generation_scripts.js.map +1 -0
  36. package/lib/index.d.ts +3 -0
  37. package/lib/index.js +4 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/init_browser.d.ts +4 -3
  40. package/lib/init_browser.js +159 -82
  41. package/lib/init_browser.js.map +1 -1
  42. package/lib/locate_element.d.ts +7 -0
  43. package/lib/locate_element.js +215 -0
  44. package/lib/locate_element.js.map +1 -0
  45. package/lib/locator.d.ts +37 -0
  46. package/lib/locator.js +172 -0
  47. package/lib/locator.js.map +1 -1
  48. package/lib/locator_log.d.ts +26 -0
  49. package/lib/locator_log.js +69 -0
  50. package/lib/locator_log.js.map +1 -0
  51. package/lib/network.d.ts +5 -0
  52. package/lib/network.js +494 -0
  53. package/lib/network.js.map +1 -0
  54. package/lib/route.d.ts +21 -0
  55. package/lib/route.js +575 -0
  56. package/lib/route.js.map +1 -0
  57. package/lib/scripts/axe.mini.js +12 -0
  58. package/lib/snapshot_validation.d.ts +37 -0
  59. package/lib/snapshot_validation.js +357 -0
  60. package/lib/snapshot_validation.js.map +1 -0
  61. package/lib/stable_browser.d.ts +157 -55
  62. package/lib/stable_browser.js +2757 -1298
  63. package/lib/stable_browser.js.map +1 -1
  64. package/lib/table.d.ts +15 -0
  65. package/lib/table.js +257 -0
  66. package/lib/table.js.map +1 -0
  67. package/lib/table_analyze.js.map +1 -1
  68. package/lib/table_helper.d.ts +19 -0
  69. package/lib/table_helper.js +130 -0
  70. package/lib/table_helper.js.map +1 -0
  71. package/lib/test_context.d.ts +6 -0
  72. package/lib/test_context.js +16 -12
  73. package/lib/test_context.js.map +1 -1
  74. package/lib/utils.d.ts +36 -2
  75. package/lib/utils.js +709 -13
  76. package/lib/utils.js.map +1 -1
  77. package/package.json +22 -12
package/lib/utils.js CHANGED
@@ -1,15 +1,61 @@
1
+ import { check_performance } from "./check_performance.js";
1
2
  import CryptoJS from "crypto-js";
2
3
  import path from "path";
3
4
  import { TOTP } from "totp-generator";
4
- // Function to encrypt a string
5
+ import fs from "fs";
6
+ import axios from "axios";
7
+ import objectPath from "object-path";
8
+ const measureAsync = async (name, fn) => {
9
+ const id = `${name}-${Math.random().toString(36).slice(2, 9)}`;
10
+ const startMark = `${id}-start`;
11
+ const endMark = `${id}-end`;
12
+ try {
13
+ performance.mark(startMark);
14
+ try {
15
+ return await fn();
16
+ }
17
+ finally {
18
+ performance.mark(endMark);
19
+ const measure = performance.measure(id, startMark, endMark);
20
+ console.log(`${name}: ${measure.duration.toFixed(3)}ms`);
21
+ performance.clearMarks(startMark);
22
+ performance.clearMarks(endMark);
23
+ performance.clearMeasures(id);
24
+ }
25
+ }
26
+ catch (error) {
27
+ if (!(error instanceof DOMException) || !error.message.includes("performance mark")) {
28
+ throw error;
29
+ }
30
+ }
31
+ };
5
32
  function encrypt(text, key = null) {
6
33
  if (!key) {
7
34
  key = _findKey();
8
35
  }
9
36
  return CryptoJS.AES.encrypt(text, key).toString();
10
37
  }
11
- // Function to decrypt a string
12
- async function decrypt(encryptedText, key = null, totpWait = true) {
38
+ function getTestDataValue(key, environment = "*") {
39
+ const blinqEnvPath = "data/data.json";
40
+ const envPath = path.resolve(process.cwd(), blinqEnvPath);
41
+ const envJson = JSON.parse(fs.readFileSync(envPath, "utf-8"));
42
+ const dataArray = envJson[environment];
43
+ const item = dataArray.find((item) => item.key === key);
44
+ if (!item && environment !== "*") {
45
+ return getTestDataValue(key, "*");
46
+ }
47
+ if (!item) {
48
+ throw new Error(`Key ${key} not found in data.json`);
49
+ }
50
+ if (item.DataType === "string") {
51
+ return item.value;
52
+ }
53
+ else if (item.DataType === "secret" || item.DataType === "totp") {
54
+ return decrypt(item.value, null, false);
55
+ }
56
+ throw new Error(`Unsupported data type for key ${key}`);
57
+ }
58
+ function decrypt(encryptedText, key = null, totpWait = true) {
13
59
  if (!key) {
14
60
  key = _findKey();
15
61
  }
@@ -21,19 +67,105 @@ async function decrypt(encryptedText, key = null, totpWait = true) {
21
67
  const bytes = CryptoJS.AES.decrypt(encryptedText, key);
22
68
  encryptedText = bytes.toString(CryptoJS.enc.Utf8);
23
69
  let { otp, expires } = TOTP.generate(encryptedText);
24
- if (totpWait) {
25
- // expires is in unix time, check if we have at least 10 seconds left, if it's less than wait for the expires time
26
- if (expires - Date.now() < 10000) {
27
- await new Promise((resolve) => setTimeout(resolve, (expires - Date.now() + 1000) % 30000));
28
- ({ otp, expires } = TOTP.generate(encryptedText));
29
- }
30
- }
70
+ // if (totpWait) {
71
+ // // expires is in unix time, check if we have at least 10 seconds left, if it's less than wait for the expires time
72
+ // if (expires - Date.now() < 10000) {
73
+ // await new Promise((resolve) => setTimeout(resolve, (expires - Date.now() + 1000) % 30000));
74
+ // ({ otp, expires } = TOTP.generate(encryptedText));
75
+ // }
76
+ // }
31
77
  return otp;
32
78
  }
79
+ if (encryptedText.startsWith("mask:")) {
80
+ return encryptedText.substring(5);
81
+ }
33
82
  const bytes = CryptoJS.AES.decrypt(encryptedText, key);
34
83
  return bytes.toString(CryptoJS.enc.Utf8);
35
84
  }
85
+ export function testForRegex(text) {
86
+ const regexEndPattern = /\/([gimuy]*)$/;
87
+ if (text.startsWith("/")) {
88
+ const match = regexEndPattern.test(text);
89
+ if (match) {
90
+ try {
91
+ const regex = new RegExp(text.substring(1, text.lastIndexOf("/")), text.match(regexEndPattern)[1]);
92
+ return true;
93
+ }
94
+ catch {
95
+ // not regex
96
+ }
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+ function _convertToRegexQuery(text, isRegex, fullMatch, ignoreCase) {
102
+ let query = "internal:text=/";
103
+ let queryEnd = "/";
104
+ let pattern = "";
105
+ const regexEndPattern = /\/([gimuy]*)$/;
106
+ if (text.startsWith("/")) {
107
+ const match = regexEndPattern.test(text);
108
+ if (match) {
109
+ try {
110
+ const regex = new RegExp(text.substring(1, text.lastIndexOf("/")), text.match(regexEndPattern)[1]);
111
+ text = text.replace(/"/g, '\\"');
112
+ return "internal:text=" + text;
113
+ }
114
+ catch {
115
+ // not regex
116
+ }
117
+ }
118
+ }
119
+ if (isRegex) {
120
+ pattern = text;
121
+ }
122
+ else {
123
+ // first remove \n then split the text by any white space,
124
+ let parts = text.replace(/\\n/g, "").split(/\s+/);
125
+ // escape regex split part
126
+ parts = parts.map((part) => escapeRegex(part));
127
+ pattern = parts.join("\\s*");
128
+ }
129
+ if (fullMatch) {
130
+ pattern = "^\\s*" + pattern + "\\s*$";
131
+ }
132
+ if (ignoreCase) {
133
+ queryEnd += "i";
134
+ }
135
+ return query + pattern + queryEnd + " >> visible=true";
136
+ }
137
+ function escapeRegex(str) {
138
+ // Special regex characters that need to be escaped
139
+ const specialChars = [
140
+ "/",
141
+ ".",
142
+ "*",
143
+ "+",
144
+ "?",
145
+ "^",
146
+ "$",
147
+ "(",
148
+ ")",
149
+ "[",
150
+ "]",
151
+ "{",
152
+ "}",
153
+ "|",
154
+ "\\",
155
+ "-",
156
+ "'",
157
+ '"',
158
+ ">", // added to avoid confusion with pw selectorsxw
159
+ ];
160
+ // Create a regex that will match all special characters
161
+ const escapedRegex = new RegExp(specialChars.map((char) => `\\${char}`).join("|"), "g");
162
+ // Escape special characters by prefixing them with a backslash
163
+ return str.replace(escapedRegex, "\\$&");
164
+ }
36
165
  function _findKey() {
166
+ if (process.env.PROJECT_KEY) {
167
+ return process.env.PROJECT_KEY;
168
+ }
37
169
  if (process.env.PROJECT_ID) {
38
170
  return process.env.PROJECT_ID;
39
171
  }
@@ -45,7 +177,571 @@ function _findKey() {
45
177
  // extract the base folder name
46
178
  return path.basename(folder);
47
179
  }
48
- // console.log(encrypt("Hello, World!", null));
49
- // console.log(decrypt("U2FsdGVkX1+6mavadgkMgJPIhR3IO1pDkx36TjTyoyE=", null));
50
- export { encrypt, decrypt };
180
+ function _getDataFile(world = null, context = null, web = null) {
181
+ let dataFile = null;
182
+ if (world && world.reportFolder) {
183
+ dataFile = path.join(world.reportFolder, "data.json");
184
+ }
185
+ else if (web && web.reportFolder) {
186
+ dataFile = path.join(web.reportFolder, "data.json");
187
+ }
188
+ else if (context && context.reportFolder) {
189
+ dataFile = path.join(context.reportFolder, "data.json");
190
+ }
191
+ else if (web && web.project_path) {
192
+ dataFile = path.join(web.project_path, "data", "data.json");
193
+ }
194
+ else {
195
+ dataFile = "data.json";
196
+ }
197
+ return dataFile;
198
+ }
199
+ function _getTestDataFile(world = null, context = null, web = null) {
200
+ let dataFile = null;
201
+ if (world && world.reportFolder) {
202
+ dataFile = path.join(world.reportFolder, "data.json");
203
+ }
204
+ else if (web && web.reportFolder) {
205
+ dataFile = path.join(web.reportFolder, "data.json");
206
+ }
207
+ else if (context && context.reportFolder) {
208
+ dataFile = path.join(context.reportFolder, "data.json");
209
+ }
210
+ else if (fs.existsSync(path.join("data", "data.json"))) {
211
+ dataFile = path.join("data", "data.json");
212
+ }
213
+ else {
214
+ dataFile = "data.json";
215
+ }
216
+ return dataFile;
217
+ }
218
+ function _getTestData(world = null, context = null, web = null) {
219
+ const dataFile = _getDataFile(world, context, web);
220
+ let data = {};
221
+ if (fs.existsSync(dataFile)) {
222
+ // convert \r\n to \n
223
+ const fileContent = fs.readFileSync(dataFile, "utf8").replace(/\r\n/g, "\n");
224
+ data = JSON.parse(fileContent);
225
+ }
226
+ return data;
227
+ }
228
+ async function replaceWithLocalTestData(value, world, _decrypt = true, totpWait = true, context = null, web = null, throwError = true) {
229
+ if (!value) {
230
+ return value;
231
+ }
232
+ let env = context?.environment?.name || "";
233
+ // used for unit tests
234
+ let testData = context?._data_ ? context._data_ : _getTestData(world, context, web);
235
+ const resolveDatePlaceholder = async (key) => {
236
+ const dateQuery = key.substring(5);
237
+ const parts = dateQuery.split(">>");
238
+ const returnTemplate = parts[1] || null;
239
+ const serviceUrl = _getServerUrl();
240
+ const config = {
241
+ method: "post",
242
+ url: `${serviceUrl}/api/runs/find-date/find`,
243
+ headers: {
244
+ "x-source": "true",
245
+ "Content-Type": "application/json",
246
+ Authorization: `Bearer ${process.env.TOKEN}`,
247
+ },
248
+ data: JSON.stringify({ value: parts[0] }),
249
+ };
250
+ const result = await axios.request(config);
251
+ if (result.status !== 200 || !result.data?.status || !result.data.result) {
252
+ console.error("Failed to find date");
253
+ throw new Error("Failed to find date");
254
+ }
255
+ return formatDate(result.data.result, returnTemplate);
256
+ };
257
+ const resolvePlaceholder = async (key) => {
258
+ if (key.startsWith("date:")) {
259
+ return await resolveDatePlaceholder(key);
260
+ }
261
+ let resolved = replaceTestDataValue(env, key, testData, _decrypt);
262
+ if (resolved !== null)
263
+ return resolved;
264
+ resolved = replaceTestDataValue("*", key, testData, _decrypt);
265
+ if (resolved !== null)
266
+ return resolved;
267
+ if (throwError) {
268
+ throw new Error(`Parameter "{{${key}}}" is undefined in the test data`);
269
+ }
270
+ else {
271
+ console.warn(`Parameter "{{${key}}}" is undefined in the test data`);
272
+ return null;
273
+ }
274
+ };
275
+ const recursiveReplace = async (input) => {
276
+ const regex = /{{([^{}]+)}}/g;
277
+ let result = input;
278
+ let match;
279
+ let anyChange = false;
280
+ while ((match = regex.exec(result)) !== null) {
281
+ const fullMatch = match[0];
282
+ const key = match[1].trim();
283
+ const replacement = await resolvePlaceholder(key);
284
+ if (replacement !== null) {
285
+ result = result.replace(fullMatch, replacement);
286
+ anyChange = true;
287
+ regex.lastIndex = 0; // reset index due to string mutation
288
+ }
289
+ }
290
+ // If replacements were made, repeat to resolve nested placeholders
291
+ return anyChange ? await recursiveReplace(result) : result;
292
+ };
293
+ value = await recursiveReplace(value);
294
+ // Only evaluate if value contains a JS expression
295
+ if ((value.startsWith("secret:") || value.startsWith("totp:") || value.startsWith("mask:")) && _decrypt) {
296
+ return decrypt(value, null, totpWait);
297
+ }
298
+ if (value.startsWith("${") && value.endsWith("}")) {
299
+ value = evaluateString(value, context?.examplesRow);
300
+ }
301
+ return value;
302
+ }
303
+ function replaceTestDataValue(env, key, testData, decryptValue = true) {
304
+ const path = key.split(".");
305
+ const value = objectPath.get(testData, path);
306
+ if (value && !Array.isArray(value)) {
307
+ return value;
308
+ }
309
+ const dataArray = testData[env];
310
+ if (!dataArray) {
311
+ return null;
312
+ }
313
+ for (const obj of dataArray) {
314
+ if (obj.key !== key) {
315
+ continue;
316
+ }
317
+ if (obj.DataType === "secret") {
318
+ if (decryptValue === true) {
319
+ return decrypt(`secret:${obj.value}`, null);
320
+ }
321
+ else {
322
+ return `secret:${obj.value}`;
323
+ }
324
+ }
325
+ if (obj.DataType === "totp") {
326
+ return `totp:${obj.value}`;
327
+ }
328
+ return obj.value;
329
+ }
330
+ return null;
331
+ }
332
+ function evaluateString(template, parameters) {
333
+ if (!parameters) {
334
+ parameters = {};
335
+ }
336
+ try {
337
+ return new Function(...Object.keys(parameters), `return \`${template}\`;`)(...Object.values(parameters));
338
+ }
339
+ catch (e) {
340
+ console.error(e);
341
+ return template;
342
+ }
343
+ }
344
+ function formatDate(dateStr, format) {
345
+ if (!format) {
346
+ return dateStr;
347
+ }
348
+ // Split the input date string
349
+ const [dd, mm, yyyy] = dateStr.split("-");
350
+ // Define replacements
351
+ const replacements = {
352
+ dd: dd,
353
+ mm: mm,
354
+ yyyy: yyyy,
355
+ };
356
+ // Replace format placeholders with actual values
357
+ return format.replace(/dd|mm|yyyy/g, (match) => replacements[match]);
358
+ }
359
+ function maskValue(value) {
360
+ if (!value) {
361
+ return value;
362
+ }
363
+ if (value.startsWith("secret:")) {
364
+ return "secret:****";
365
+ }
366
+ if (value.startsWith("totp:")) {
367
+ return "totp:****";
368
+ }
369
+ if (value.startsWith("mask:")) {
370
+ return "mask:****";
371
+ }
372
+ return value;
373
+ }
374
+ function _copyContext(from, to) {
375
+ to.browser = from.browser;
376
+ to.page = from.page;
377
+ to.context = from.context;
378
+ }
379
+ async function scrollPageToLoadLazyElements(page) {
380
+ let lastHeight = await page.evaluate(() => document.body.scrollHeight);
381
+ let retry = 0;
382
+ while (true) {
383
+ await page.evaluate(() => window.scrollBy(0, window.innerHeight));
384
+ await new Promise((resolve) => setTimeout(resolve, 1000));
385
+ let newHeight = await page.evaluate(() => document.body.scrollHeight);
386
+ if (newHeight === lastHeight) {
387
+ break;
388
+ }
389
+ lastHeight = newHeight;
390
+ retry++;
391
+ if (retry > 10) {
392
+ break;
393
+ }
394
+ }
395
+ await page.evaluate(() => window.scrollTo(0, 0));
396
+ }
397
+ function _fixUsingParams(text, _params) {
398
+ if (!_params || typeof text !== "string") {
399
+ return text;
400
+ }
401
+ for (let key in _params) {
402
+ let regValue = key;
403
+ if (key.startsWith("_")) {
404
+ // remove the _ prefix
405
+ regValue = key.substring(1);
406
+ }
407
+ text = text.replaceAll(new RegExp("{" + regValue + "}", "g"), _params[key]);
408
+ }
409
+ return text;
410
+ }
411
+ function getWebLogFile(logFolder) {
412
+ if (!fs.existsSync(logFolder)) {
413
+ fs.mkdirSync(logFolder, { recursive: true });
414
+ }
415
+ let nextIndex = 1;
416
+ while (fs.existsSync(path.join(logFolder, nextIndex.toString() + ".json"))) {
417
+ nextIndex++;
418
+ }
419
+ const fileName = nextIndex + ".json";
420
+ return path.join(logFolder, fileName);
421
+ }
422
+ function _fixLocatorUsingParams(locator, _params) {
423
+ // check if not null
424
+ if (!locator) {
425
+ return locator;
426
+ }
427
+ // clone the locator
428
+ locator = JSON.parse(JSON.stringify(locator));
429
+ scanAndManipulate(locator, _params);
430
+ return locator;
431
+ }
432
+ function _isObject(value) {
433
+ return value && typeof value === "object" && value.constructor === Object;
434
+ }
435
+ function scanAndManipulate(currentObj, _params) {
436
+ for (const key in currentObj) {
437
+ if (typeof currentObj[key] === "string") {
438
+ // Perform string manipulation
439
+ currentObj[key] = _fixUsingParams(currentObj[key], _params);
440
+ }
441
+ else if (_isObject(currentObj[key])) {
442
+ // Recursively scan nested objects
443
+ scanAndManipulate(currentObj[key], _params);
444
+ }
445
+ }
446
+ }
447
+ function extractStepExampleParameters(step) {
448
+ if (!step ||
449
+ !step.gherkinDocument ||
450
+ !step.pickle ||
451
+ !step.pickle.astNodeIds ||
452
+ !(step.pickle.astNodeIds.length > 1) ||
453
+ !step.gherkinDocument.feature ||
454
+ !step.gherkinDocument.feature.children) {
455
+ return {};
456
+ }
457
+ try {
458
+ const scenarioId = step.pickle.astNodeIds[0];
459
+ const exampleId = step.pickle.astNodeIds[1];
460
+ // find the scenario in the gherkin document
461
+ const scenario = step.gherkinDocument.feature.children.find((child) => child.scenario.id === scenarioId).scenario;
462
+ if (!scenario || !scenario.examples || !scenario.examples[0].tableBody) {
463
+ return {};
464
+ }
465
+ // find the table body in the examples
466
+ const row = scenario.examples[0].tableBody.find((r) => r.id === exampleId);
467
+ if (!row) {
468
+ return {};
469
+ }
470
+ // extract the cells values (row.cells.value) into an array
471
+ const values = row.cells.map((cell) => cell.value);
472
+ // extract the table headers keys (scenario.examples.tableHeader.cells.value) into an array
473
+ const keys = scenario.examples[0].tableHeader.cells.map((cell) => cell.value);
474
+ // create a dictionary of the keys and values
475
+ const params = {};
476
+ for (let i = 0; i < keys.length; i++) {
477
+ params[keys[i]] = values[i];
478
+ }
479
+ return params;
480
+ }
481
+ catch (e) {
482
+ console.error(e);
483
+ return {};
484
+ }
485
+ }
486
+ export async function performAction(action, element, options, web, state, _params) {
487
+ let usedOptions;
488
+ if (!options) {
489
+ options = {};
490
+ }
491
+ if (!element) {
492
+ throw new Error("Element not found");
493
+ }
494
+ switch (action) {
495
+ case "click":
496
+ // copy any of the following options to usedOptions: button, clickCount, delay, modifiers, force, position, trial
497
+ usedOptions = ["button", "clickCount", "delay", "modifiers", "force", "position", "trial", "timeout"].reduce((acc, key) => {
498
+ if (options[key]) {
499
+ acc[key] = options[key];
500
+ }
501
+ return acc;
502
+ }, {});
503
+ if (!usedOptions.timeout) {
504
+ usedOptions.timeout = 10000;
505
+ if (usedOptions.position) {
506
+ usedOptions.timeout = 1000;
507
+ }
508
+ }
509
+ if (usedOptions && usedOptions.clickCount) {
510
+ state.info.count = usedOptions.clickCount;
511
+ }
512
+ try {
513
+ check_performance("click_action", web.context, true);
514
+ await element.click(usedOptions);
515
+ check_performance("click_action", web.context, false);
516
+ }
517
+ catch (e) {
518
+ if (usedOptions.position) {
519
+ // find the element bounding box
520
+ const rect = await element.boundingBox();
521
+ // calculate the x and y position
522
+ const x = rect.x + rect.width / 2 + (usedOptions.position.x || 0);
523
+ const y = rect.y + rect.height / 2 + (usedOptions.position.y || 0);
524
+ // click on the x and y position
525
+ await web.page.mouse.click(x, y);
526
+ }
527
+ else {
528
+ if (state && state.selectors) {
529
+ state.element = await web._locate(state.selectors, state.info, _params);
530
+ element = state.element;
531
+ }
532
+ await element.dispatchEvent("click");
533
+ }
534
+ }
535
+ break;
536
+ case "hover":
537
+ usedOptions = ["position", "trial", "timeout"].reduce((acc, key) => {
538
+ acc[key] = options[key];
539
+ return acc;
540
+ }, {});
541
+ try {
542
+ await element.hover(usedOptions);
543
+ await new Promise((resolve) => setTimeout(resolve, 1000));
544
+ }
545
+ catch (e) {
546
+ if (state && state.selectors) {
547
+ state.info.log += "hover failed, will try again" + "\n";
548
+ state.element = await web._locate(state.selectors, state.info, _params);
549
+ element = state.element;
550
+ }
551
+ usedOptions.timeout = 10000;
552
+ await element.hover(usedOptions);
553
+ await new Promise((resolve) => setTimeout(resolve, 1000));
554
+ }
555
+ break;
556
+ case "hover+click":
557
+ await performAction("hover", element, options, web, state, _params);
558
+ await performAction("click", element, options, web, state, _params);
559
+ break;
560
+ default:
561
+ throw new Error(`Action ${action} not supported`);
562
+ }
563
+ }
564
+ const KEYBOARD_EVENTS = [
565
+ "ALT",
566
+ "AltGraph",
567
+ "CapsLock",
568
+ "Control",
569
+ "Fn",
570
+ "FnLock",
571
+ "Hyper",
572
+ "Meta",
573
+ "NumLock",
574
+ "ScrollLock",
575
+ "Shift",
576
+ "Super",
577
+ "Symbol",
578
+ "SymbolLock",
579
+ "Enter",
580
+ "Tab",
581
+ "ArrowDown",
582
+ "ArrowLeft",
583
+ "ArrowRight",
584
+ "ArrowUp",
585
+ "End",
586
+ "Home",
587
+ "PageDown",
588
+ "PageUp",
589
+ "Backspace",
590
+ "Clear",
591
+ "Copy",
592
+ "CrSel",
593
+ "Cut",
594
+ "Delete",
595
+ "EraseEof",
596
+ "ExSel",
597
+ "Insert",
598
+ "Paste",
599
+ "Redo",
600
+ "Undo",
601
+ "Accept",
602
+ "Again",
603
+ "Attn",
604
+ "Cancel",
605
+ "ContextMenu",
606
+ "Escape",
607
+ "Execute",
608
+ "Find",
609
+ "Finish",
610
+ "Help",
611
+ "Pause",
612
+ "Play",
613
+ "Props",
614
+ "Select",
615
+ "ZoomIn",
616
+ "ZoomOut",
617
+ "BrightnessDown",
618
+ "BrightnessUp",
619
+ "Eject",
620
+ "LogOff",
621
+ "Power",
622
+ "PowerOff",
623
+ "PrintScreen",
624
+ "Hibernate",
625
+ "Standby",
626
+ "WakeUp",
627
+ "AllCandidates",
628
+ "Alphanumeric",
629
+ "CodeInput",
630
+ "Compose",
631
+ "Convert",
632
+ "Dead",
633
+ "FinalMode",
634
+ "GroupFirst",
635
+ "GroupLast",
636
+ "GroupNext",
637
+ "GroupPrevious",
638
+ "ModeChange",
639
+ "NextCandidate",
640
+ "NonConvert",
641
+ "PreviousCandidate",
642
+ "Process",
643
+ "SingleCandidate",
644
+ "HangulMode",
645
+ "HanjaMode",
646
+ "JunjaMode",
647
+ "Eisu",
648
+ "Hankaku",
649
+ "Hiragana",
650
+ "HiraganaKatakana",
651
+ "KanaMode",
652
+ "KanjiMode",
653
+ "Katakana",
654
+ "Romaji",
655
+ "Zenkaku",
656
+ "ZenkakuHanaku",
657
+ "F1",
658
+ "F2",
659
+ "F3",
660
+ "F4",
661
+ "F5",
662
+ "F6",
663
+ "F7",
664
+ "F8",
665
+ "F9",
666
+ "F10",
667
+ "F11",
668
+ "F12",
669
+ "Soft1",
670
+ "Soft2",
671
+ "Soft3",
672
+ "Soft4",
673
+ "ChannelDown",
674
+ "ChannelUp",
675
+ "Close",
676
+ "MailForward",
677
+ "MailReply",
678
+ "MailSend",
679
+ "MediaFastForward",
680
+ "MediaPause",
681
+ "MediaPlay",
682
+ "MediaPlayPause",
683
+ "MediaRecord",
684
+ "MediaRewind",
685
+ "MediaStop",
686
+ "MediaTrackNext",
687
+ "MediaTrackPrevious",
688
+ "AudioBalanceLeft",
689
+ "AudioBalanceRight",
690
+ "AudioBassBoostDown",
691
+ "AudioBassBoostToggle",
692
+ "AudioBassBoostUp",
693
+ "AudioFaderFront",
694
+ "AudioFaderRear",
695
+ "AudioSurroundModeNext",
696
+ "AudioTrebleDown",
697
+ "AudioTrebleUp",
698
+ "AudioVolumeDown",
699
+ "AudioVolumeMute",
700
+ "AudioVolumeUp",
701
+ "MicrophoneToggle",
702
+ "MicrophoneVolumeDown",
703
+ "MicrophoneVolumeMute",
704
+ "MicrophoneVolumeUp",
705
+ "TV",
706
+ "TV3DMode",
707
+ "TVAntennaCable",
708
+ "TVAudioDescription",
709
+ ];
710
+ function unEscapeString(str) {
711
+ const placeholder = "\\n";
712
+ str = str.replace(new RegExp(placeholder, "g"), "\n");
713
+ return str;
714
+ }
715
+ function _getServerUrl() {
716
+ let serviceUrl = "https://api.blinq.io";
717
+ if (process.env.NODE_ENV_BLINQ === "dev") {
718
+ serviceUrl = "https://dev.api.blinq.io";
719
+ }
720
+ else if (process.env.NODE_ENV_BLINQ === "stage") {
721
+ serviceUrl = "https://stage.api.blinq.io";
722
+ }
723
+ else if (process.env.NODE_ENV_BLINQ === "prod") {
724
+ serviceUrl = "https://api.blinq.io";
725
+ }
726
+ else if (!process.env.NODE_ENV_BLINQ) {
727
+ serviceUrl = "https://api.blinq.io";
728
+ }
729
+ else {
730
+ serviceUrl = process.env.NODE_ENV_BLINQ;
731
+ }
732
+ return serviceUrl;
733
+ }
734
+ function tryParseJson(input) {
735
+ if (typeof input === "string") {
736
+ try {
737
+ return JSON.parse(input);
738
+ }
739
+ catch {
740
+ // If parsing fails, return the original input (assumed to be plain text or another format)
741
+ return input;
742
+ }
743
+ }
744
+ return input;
745
+ }
746
+ export { measureAsync, encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, _getServerUrl, _convertToRegexQuery, extractStepExampleParameters, _getDataFile, tryParseJson, getTestDataValue, replaceTestDataValue, _getTestData, };
51
747
  //# sourceMappingURL=utils.js.map