automation_model 1.0.477-dev → 1.0.477

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