automation_model 1.0.556-dev → 1.0.556-stage

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table_helper.js","sourceRoot":"","sources":["../../src/table_helper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,WAAmB,EAAE,KAAU,EAAE,GAAQ;IAC1F,MAAM,GAAG,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAEjD,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;KAC7C;IACD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;IAC5C,2GAA2G;IAC3G,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,UAAU,GAAG,OAAO,CAAC;IACzB,IAAI,UAAU,GAAG,WAAW,CAAC;IAC7B,OAAO,IAAI,EAAE;QACX,KAAK,EAAE,CAAC;QACR,4CAA4C;QAC5C,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/D,MAAM,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;QAClD,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC;QAC3D,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM;SACP;QACD,MAAM,cAAc,GAAG,MAAM,YAAY,CAAC,SAAS,EAAE,CAAC;QACtD,IAAI,cAAc,KAAK,SAAS,EAAE;YAChC,MAAM;SACP;QACD,UAAU,GAAG,YAA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,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9B,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACxD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;KACF;IACD,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE;QACzD,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QAClC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;KACnC;IACD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,CAAC,IAAI,EAAE;YACT,SAAS;SACV;QACD,IACE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,WAAW;YAC9B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,WAAW;YACxD,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,WAAW;YAC9B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,WAAW,EAC1D;YACA,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC7B;KACF;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -2,8 +2,10 @@ import { BrowserContext, Page, Browser as PlaywrightBrowser } from "playwright";
2
2
  import { Environment } from "./environment.js";
3
3
  import { StableBrowser } from "./stable_browser.js";
4
4
  import { Api } from "./api.js";
5
+ import { InitScripts } from "./generation_scripts.js";
5
6
  declare class TestContext {
6
7
  stable: StableBrowser | null;
8
+ web: StableBrowser | null;
7
9
  browser: PlaywrightBrowser | null;
8
10
  playContext: BrowserContext | null;
9
11
  page: Page | null;
@@ -14,6 +16,7 @@ declare class TestContext {
14
16
  headless: boolean;
15
17
  browserName: string | null;
16
18
  browserObject: any;
19
+ initScripts: InitScripts | null;
17
20
  constructor();
18
21
  }
19
22
  export { TestContext };
@@ -1,5 +1,6 @@
1
1
  class TestContext {
2
2
  stable = null;
3
+ web = null;
3
4
  browser = null;
4
5
  playContext = null;
5
6
  page = null;
@@ -10,6 +11,7 @@ class TestContext {
10
11
  headless = false;
11
12
  browserName = null;
12
13
  browserObject = null;
14
+ initScripts = null;
13
15
  constructor() { }
14
16
  }
15
17
  export { TestContext };
@@ -1 +1 @@
1
- {"version":3,"file":"test_context.js","sourceRoot":"","sources":["../../src/test_context.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW;IACf,MAAM,GAAyB,IAAI,CAAC;IACpC,OAAO,GAA6B,IAAI,CAAC;IACzC,WAAW,GAA0B,IAAI,CAAC;IAC1C,IAAI,GAAgB,IAAI,CAAC;IACzB,WAAW,GAAuB,IAAI,CAAC;IACvC,YAAY,GAAkB,IAAI,CAAC;IACnC,GAAG,GAAe,IAAI,CAAC;IACvB,QAAQ,GAAG,KAAK,CAAC;IACjB,QAAQ,GAAG,KAAK,CAAC;IACjB,WAAW,GAAkB,IAAI,CAAC;IAClC,aAAa,GAAQ,IAAI,CAAC;IAC1B,gBAAe,CAAC;CACjB;AACD,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"test_context.js","sourceRoot":"","sources":["../../src/test_context.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW;IACf,MAAM,GAAyB,IAAI,CAAC;IACpC,GAAG,GAAyB,IAAI,CAAC;IACjC,OAAO,GAA6B,IAAI,CAAC;IACzC,WAAW,GAA0B,IAAI,CAAC;IAC1C,IAAI,GAAgB,IAAI,CAAC;IACzB,WAAW,GAAuB,IAAI,CAAC;IACvC,YAAY,GAAkB,IAAI,CAAC;IACnC,GAAG,GAAe,IAAI,CAAC;IACvB,QAAQ,GAAG,KAAK,CAAC;IACjB,QAAQ,GAAG,KAAK,CAAC;IACjB,WAAW,GAAkB,IAAI,CAAC;IAClC,aAAa,GAAQ,IAAI,CAAC;IAC1B,WAAW,GAAuB,IAAI,CAAC;IACvC,gBAAe,CAAC;CACjB;AACD,OAAO,EAAE,WAAW,EAAE,CAAC"}
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,21 @@
1
1
  declare function encrypt(text: string, key?: string | null): string;
2
2
  declare function decrypt(encryptedText: string, key?: string | null, totpWait?: boolean): Promise<string>;
3
- declare function replaceWithLocalTestData(value: string, world: any, _decrypt?: boolean, totpWait?: boolean, context?: any, stable?: any): Promise<string>;
3
+ export declare function testForRegex(text: string): boolean;
4
+ declare function _convertToRegexQuery(text: string, isRegex: boolean, fullMatch: boolean, ignoreCase: boolean): string;
5
+ declare function _getDataFile(world?: any, context?: any, web?: any): string;
6
+ declare function replaceWithLocalTestData(value: string, world: any, _decrypt?: boolean, totpWait?: boolean, context?: any, web?: any): Promise<string>;
4
7
  declare function maskValue(value: string): string;
5
- export { encrypt, decrypt, replaceWithLocalTestData, maskValue };
8
+ declare function _copyContext(from: any, to: any): void;
9
+ declare function scrollPageToLoadLazyElements(page: any): Promise<void>;
10
+ type Params = Record<string, string>;
11
+ declare function _fixUsingParams(text: string, _params: Params): string;
12
+ declare function getWebLogFile(logFolder: string): string;
13
+ declare function _fixLocatorUsingParams(locator: any, _params: Params): any;
14
+ declare function _isObject(value: any): any;
15
+ declare function scanAndManipulate(currentObj: any, _params: Params): void;
16
+ declare function extractStepExampleParameters(step: any): any;
17
+ export declare function performAction(action: string, element: any, options: any, web: any, state: any, _params: Params): Promise<void>;
18
+ declare const KEYBOARD_EVENTS: string[];
19
+ declare function unEscapeString(str: string): string;
20
+ declare function _getServerUrl(): string;
21
+ export { encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, Params, _getServerUrl, _convertToRegexQuery, _getDataFile, extractStepExampleParameters };
package/lib/utils.js CHANGED
@@ -3,6 +3,7 @@ import objectPath from "object-path";
3
3
  import path from "path";
4
4
  import { TOTP } from "totp-generator";
5
5
  import fs from "fs";
6
+ import axios from "axios";
6
7
  // Function to encrypt a string
7
8
  function encrypt(text, key = null) {
8
9
  if (!key) {
@@ -38,6 +39,86 @@ async function decrypt(encryptedText, key = null, totpWait = true) {
38
39
  const bytes = CryptoJS.AES.decrypt(encryptedText, key);
39
40
  return bytes.toString(CryptoJS.enc.Utf8);
40
41
  }
42
+ export function testForRegex(text) {
43
+ const regexEndPattern = /\/([gimuy]*)$/;
44
+ if (text.startsWith("/")) {
45
+ const match = regexEndPattern.test(text);
46
+ if (match) {
47
+ try {
48
+ const regex = new RegExp(text.substring(1, text.lastIndexOf("/")), text.match(regexEndPattern)[1]);
49
+ return true;
50
+ }
51
+ catch {
52
+ // not regex
53
+ }
54
+ }
55
+ }
56
+ return false;
57
+ }
58
+ function _convertToRegexQuery(text, isRegex, fullMatch, ignoreCase) {
59
+ let query = "internal:text=/";
60
+ let queryEnd = "/";
61
+ let pattern = "";
62
+ const regexEndPattern = /\/([gimuy]*)$/;
63
+ if (text.startsWith("/")) {
64
+ const match = regexEndPattern.test(text);
65
+ if (match) {
66
+ try {
67
+ const regex = new RegExp(text.substring(1, text.lastIndexOf("/")), text.match(regexEndPattern)[1]);
68
+ text = text.replace(/"/g, '\\"');
69
+ return "internal:text=" + text;
70
+ }
71
+ catch {
72
+ // not regex
73
+ }
74
+ }
75
+ }
76
+ if (isRegex) {
77
+ pattern = text;
78
+ }
79
+ else {
80
+ // first remove \n then split the text by any white space,
81
+ let parts = text.replace(/\\n/g, "").split(/\s+/);
82
+ // escape regex split part
83
+ parts = parts.map((part) => escapeRegex(part));
84
+ pattern = parts.join("\\s*");
85
+ }
86
+ if (fullMatch) {
87
+ pattern = "^\\s*" + pattern + "\\s*$";
88
+ }
89
+ if (ignoreCase) {
90
+ queryEnd += "i";
91
+ }
92
+ return query + pattern + queryEnd;
93
+ }
94
+ function escapeRegex(str) {
95
+ // Special regex characters that need to be escaped
96
+ const specialChars = [
97
+ "/",
98
+ ".",
99
+ "*",
100
+ "+",
101
+ "?",
102
+ "^",
103
+ "$",
104
+ "(",
105
+ ")",
106
+ "[",
107
+ "]",
108
+ "{",
109
+ "}",
110
+ "|",
111
+ "\\",
112
+ "-",
113
+ "'",
114
+ '"',
115
+ ">", // added to avoid confusion with pw selectorsxw
116
+ ];
117
+ // Create a regex that will match all special characters
118
+ const escapedRegex = new RegExp(specialChars.map((char) => `\\${char}`).join("|"), "g");
119
+ // Escape special characters by prefixing them with a backslash
120
+ return str.replace(escapedRegex, "\\$&");
121
+ }
41
122
  function _findKey() {
42
123
  if (process.env.PROJECT_ID) {
43
124
  return process.env.PROJECT_ID;
@@ -50,13 +131,13 @@ function _findKey() {
50
131
  // extract the base folder name
51
132
  return path.basename(folder);
52
133
  }
53
- function _getDataFile(world = null, context = null, stable = null) {
134
+ function _getDataFile(world = null, context = null, web = null) {
54
135
  let dataFile = null;
55
136
  if (world && world.reportFolder) {
56
137
  dataFile = path.join(world.reportFolder, "data.json");
57
138
  }
58
- else if (stable && stable.reportFolder) {
59
- dataFile = path.join(stable.reportFolder, "data.json");
139
+ else if (web && web.reportFolder) {
140
+ dataFile = path.join(web.reportFolder, "data.json");
60
141
  }
61
142
  else if (context && context.reportFolder) {
62
143
  dataFile = path.join(context.reportFolder, "data.json");
@@ -66,15 +147,15 @@ function _getDataFile(world = null, context = null, stable = null) {
66
147
  }
67
148
  return dataFile;
68
149
  }
69
- function _getTestData(world = null, context = null, stable = null) {
70
- const dataFile = _getDataFile(world, context, stable);
150
+ function _getTestData(world = null, context = null, web = null) {
151
+ const dataFile = _getDataFile(world, context, web);
71
152
  let data = {};
72
153
  if (fs.existsSync(dataFile)) {
73
154
  data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
74
155
  }
75
156
  return data;
76
157
  }
77
- async function replaceWithLocalTestData(value, world, _decrypt = true, totpWait = true, context = null, stable = null) {
158
+ async function replaceWithLocalTestData(value, world, _decrypt = true, totpWait = true, context = null, web = null) {
78
159
  if (!value) {
79
160
  return value;
80
161
  }
@@ -82,21 +163,79 @@ async function replaceWithLocalTestData(value, world, _decrypt = true, totpWait
82
163
  let regex = /{{(.*?)}}/g;
83
164
  let matches = value.match(regex);
84
165
  if (matches) {
85
- const testData = _getTestData(world, context, stable);
166
+ const testData = _getTestData(world, context, web);
86
167
  for (let i = 0; i < matches.length; i++) {
87
168
  let match = matches[i];
88
169
  let key = match.substring(2, match.length - 2);
89
- let newValue = objectPath.get(testData, key, null);
90
- if (newValue !== null) {
91
- value = value.replace(match, newValue);
170
+ if (key && key.trim().startsWith("date:")) {
171
+ const dateQuery = key.substring(5);
172
+ const parts = dateQuery.split(">>");
173
+ const returnTemplate = parts[1] || null;
174
+ let serviceUrl = _getServerUrl();
175
+ const config = {
176
+ method: "post",
177
+ url: `${serviceUrl}/api/runs/find-date/find`,
178
+ headers: {
179
+ "x-source": "true",
180
+ "Content-Type": "application/json",
181
+ Authorization: `Bearer ${process.env.TOKEN}`,
182
+ },
183
+ data: JSON.stringify({
184
+ value: parts[0],
185
+ }),
186
+ };
187
+ let result = await axios.request(config);
188
+ //console.log(JSON.stringify(frameDump[0]));
189
+ if (result.status !== 200 || !result.data || result.data.status !== true || !result.data.result) {
190
+ console.error("Failed to find date");
191
+ throw new Error("Failed to find date");
192
+ }
193
+ value = formatDate(result.data.result, returnTemplate);
194
+ }
195
+ else {
196
+ let newValue = objectPath.get(testData, key, null);
197
+ if (newValue !== null) {
198
+ value = value.replace(match, newValue);
199
+ }
92
200
  }
93
201
  }
94
202
  }
95
203
  if ((value.startsWith("secret:") || value.startsWith("totp:") || value.startsWith("mask:")) && _decrypt) {
96
204
  return await decrypt(value, null, totpWait);
97
205
  }
206
+ // check if the value is ${}
207
+ if (value.startsWith("${") && value.endsWith("}")) {
208
+ value = evaluateString(value, context.examplesRow);
209
+ }
98
210
  return value;
99
211
  }
212
+ function evaluateString(template, parameters) {
213
+ if (!parameters) {
214
+ parameters = {};
215
+ }
216
+ try {
217
+ return new Function(...Object.keys(parameters), `return \`${template}\`;`)(...Object.values(parameters));
218
+ }
219
+ catch (e) {
220
+ console.error(e);
221
+ return template;
222
+ }
223
+ }
224
+ function formatDate(dateStr, format) {
225
+ if (!format) {
226
+ return dateStr;
227
+ }
228
+ // Split the input date string
229
+ const [dd, mm, yyyy] = dateStr.split("-");
230
+ // Define replacements
231
+ const replacements = {
232
+ dd: dd,
233
+ mm: mm,
234
+ yyyy: yyyy,
235
+ };
236
+ // Replace format placeholders with actual values
237
+ return format.replace(/dd|mm|yyyy/g, (match) => replacements[match]);
238
+ }
100
239
  function maskValue(value) {
101
240
  if (!value) {
102
241
  return value;
@@ -112,7 +251,351 @@ function maskValue(value) {
112
251
  }
113
252
  return value;
114
253
  }
115
- // console.log(encrypt("Hello, World!", null));
116
- // console.log(decrypt("U2FsdGVkX1+6mavadgkMgJPIhR3IO1pDkx36TjTyoyE=", null));
117
- export { encrypt, decrypt, replaceWithLocalTestData, maskValue };
254
+ function _copyContext(from, to) {
255
+ to.browser = from.browser;
256
+ to.page = from.page;
257
+ to.context = from.context;
258
+ }
259
+ async function scrollPageToLoadLazyElements(page) {
260
+ let lastHeight = await page.evaluate(() => document.body.scrollHeight);
261
+ let retry = 0;
262
+ while (true) {
263
+ await page.evaluate(() => window.scrollBy(0, window.innerHeight));
264
+ await new Promise((resolve) => setTimeout(resolve, 1000));
265
+ let newHeight = await page.evaluate(() => document.body.scrollHeight);
266
+ if (newHeight === lastHeight) {
267
+ break;
268
+ }
269
+ lastHeight = newHeight;
270
+ retry++;
271
+ if (retry > 10) {
272
+ break;
273
+ }
274
+ }
275
+ await page.evaluate(() => window.scrollTo(0, 0));
276
+ }
277
+ function _fixUsingParams(text, _params) {
278
+ if (!_params || typeof text !== "string") {
279
+ return text;
280
+ }
281
+ for (let key in _params) {
282
+ let regValue = key;
283
+ if (key.startsWith("_")) {
284
+ // remove the _ prefix
285
+ regValue = key.substring(1);
286
+ }
287
+ text = text.replaceAll(new RegExp("{" + regValue + "}", "g"), _params[key]);
288
+ }
289
+ return text;
290
+ }
291
+ function getWebLogFile(logFolder) {
292
+ if (!fs.existsSync(logFolder)) {
293
+ fs.mkdirSync(logFolder, { recursive: true });
294
+ }
295
+ let nextIndex = 1;
296
+ while (fs.existsSync(path.join(logFolder, nextIndex.toString() + ".json"))) {
297
+ nextIndex++;
298
+ }
299
+ const fileName = nextIndex + ".json";
300
+ return path.join(logFolder, fileName);
301
+ }
302
+ function _fixLocatorUsingParams(locator, _params) {
303
+ // check if not null
304
+ if (!locator) {
305
+ return locator;
306
+ }
307
+ // clone the locator
308
+ locator = JSON.parse(JSON.stringify(locator));
309
+ scanAndManipulate(locator, _params);
310
+ return locator;
311
+ }
312
+ function _isObject(value) {
313
+ return value && typeof value === "object" && value.constructor === Object;
314
+ }
315
+ function scanAndManipulate(currentObj, _params) {
316
+ for (const key in currentObj) {
317
+ if (typeof currentObj[key] === "string") {
318
+ // Perform string manipulation
319
+ currentObj[key] = _fixUsingParams(currentObj[key], _params);
320
+ }
321
+ else if (_isObject(currentObj[key])) {
322
+ // Recursively scan nested objects
323
+ scanAndManipulate(currentObj[key], _params);
324
+ }
325
+ }
326
+ }
327
+ function extractStepExampleParameters(step) {
328
+ if (!step ||
329
+ !step.gherkinDocument ||
330
+ !step.pickle ||
331
+ !step.pickle.astNodeIds ||
332
+ !(step.pickle.astNodeIds.length > 1) ||
333
+ !step.gherkinDocument.feature ||
334
+ !step.gherkinDocument.feature.children) {
335
+ return {};
336
+ }
337
+ try {
338
+ const scenarioId = step.pickle.astNodeIds[0];
339
+ const exampleId = step.pickle.astNodeIds[1];
340
+ // find the scenario in the gherkin document
341
+ const scenario = step.gherkinDocument.feature.children.find((child) => child.scenario.id === scenarioId).scenario;
342
+ if (!scenario || !scenario.examples || !scenario.examples[0].tableBody) {
343
+ return {};
344
+ }
345
+ // find the table body in the examples
346
+ const row = scenario.examples[0].tableBody.find((r) => r.id === exampleId);
347
+ if (!row) {
348
+ return {};
349
+ }
350
+ // extract the cells values (row.cells.value) into an array
351
+ const values = row.cells.map((cell) => cell.value);
352
+ // extract the table headers keys (scenario.examples.tableHeader.cells.value) into an array
353
+ const keys = scenario.examples[0].tableHeader.cells.map((cell) => cell.value);
354
+ // create a dictionary of the keys and values
355
+ const params = {};
356
+ for (let i = 0; i < keys.length; i++) {
357
+ params[keys[i]] = values[i];
358
+ }
359
+ return params;
360
+ }
361
+ catch (e) {
362
+ console.error(e);
363
+ return {};
364
+ }
365
+ }
366
+ export async function performAction(action, element, options, web, state, _params) {
367
+ let usedOptions;
368
+ if (!options) {
369
+ options = {};
370
+ }
371
+ if (!element) {
372
+ throw new Error("Element not found");
373
+ }
374
+ switch (action) {
375
+ case "click":
376
+ // copy any of the following options to usedOptions: button, clickCount, delay, modifiers, force, position, trial
377
+ usedOptions = ["button", "clickCount", "delay", "modifiers", "force", "position", "trial", "timeout"].reduce((acc, key) => {
378
+ if (options[key]) {
379
+ acc[key] = options[key];
380
+ }
381
+ return acc;
382
+ }, {});
383
+ if (!usedOptions.timeout) {
384
+ usedOptions.timeout = 10000;
385
+ if (usedOptions.position) {
386
+ usedOptions.timeout = 1000;
387
+ }
388
+ }
389
+ try {
390
+ await element.click(usedOptions);
391
+ }
392
+ catch (e) {
393
+ if (usedOptions.position) {
394
+ // find the element bounding box
395
+ const rect = await element.boundingBox();
396
+ // calculate the x and y position
397
+ const x = rect.x + rect.width / 2 + (usedOptions.position.x || 0);
398
+ const y = rect.y + rect.height / 2 + (usedOptions.position.y || 0);
399
+ // click on the x and y position
400
+ await web.page.mouse.click(x, y);
401
+ }
402
+ else {
403
+ if (state && state.selectors) {
404
+ state.element = await web._locate(state.selectors, state.info, _params);
405
+ element = state.element;
406
+ }
407
+ await element.dispatchEvent("click");
408
+ }
409
+ }
410
+ break;
411
+ case "hover":
412
+ usedOptions = ["position", "trial", "timeout"].reduce((acc, key) => {
413
+ acc[key] = options[key];
414
+ return acc;
415
+ }, {});
416
+ try {
417
+ await element.hover(usedOptions);
418
+ await new Promise((resolve) => setTimeout(resolve, 1000));
419
+ }
420
+ catch (e) {
421
+ if (state && state.selectors) {
422
+ state.info.log += "hover failed, will try again" + "\n";
423
+ state.element = await web._locate(state.selectors, state.info, _params);
424
+ element = state.element;
425
+ }
426
+ usedOptions.timeout = 10000;
427
+ await element.hover(usedOptions);
428
+ await new Promise((resolve) => setTimeout(resolve, 1000));
429
+ }
430
+ break;
431
+ case "hover+click":
432
+ await performAction("hover", element, options, web, state, _params);
433
+ await performAction("click", element, options, web, state, _params);
434
+ break;
435
+ default:
436
+ throw new Error(`Action ${action} not supported`);
437
+ }
438
+ }
439
+ const KEYBOARD_EVENTS = [
440
+ "ALT",
441
+ "AltGraph",
442
+ "CapsLock",
443
+ "Control",
444
+ "Fn",
445
+ "FnLock",
446
+ "Hyper",
447
+ "Meta",
448
+ "NumLock",
449
+ "ScrollLock",
450
+ "Shift",
451
+ "Super",
452
+ "Symbol",
453
+ "SymbolLock",
454
+ "Enter",
455
+ "Tab",
456
+ "ArrowDown",
457
+ "ArrowLeft",
458
+ "ArrowRight",
459
+ "ArrowUp",
460
+ "End",
461
+ "Home",
462
+ "PageDown",
463
+ "PageUp",
464
+ "Backspace",
465
+ "Clear",
466
+ "Copy",
467
+ "CrSel",
468
+ "Cut",
469
+ "Delete",
470
+ "EraseEof",
471
+ "ExSel",
472
+ "Insert",
473
+ "Paste",
474
+ "Redo",
475
+ "Undo",
476
+ "Accept",
477
+ "Again",
478
+ "Attn",
479
+ "Cancel",
480
+ "ContextMenu",
481
+ "Escape",
482
+ "Execute",
483
+ "Find",
484
+ "Finish",
485
+ "Help",
486
+ "Pause",
487
+ "Play",
488
+ "Props",
489
+ "Select",
490
+ "ZoomIn",
491
+ "ZoomOut",
492
+ "BrightnessDown",
493
+ "BrightnessUp",
494
+ "Eject",
495
+ "LogOff",
496
+ "Power",
497
+ "PowerOff",
498
+ "PrintScreen",
499
+ "Hibernate",
500
+ "Standby",
501
+ "WakeUp",
502
+ "AllCandidates",
503
+ "Alphanumeric",
504
+ "CodeInput",
505
+ "Compose",
506
+ "Convert",
507
+ "Dead",
508
+ "FinalMode",
509
+ "GroupFirst",
510
+ "GroupLast",
511
+ "GroupNext",
512
+ "GroupPrevious",
513
+ "ModeChange",
514
+ "NextCandidate",
515
+ "NonConvert",
516
+ "PreviousCandidate",
517
+ "Process",
518
+ "SingleCandidate",
519
+ "HangulMode",
520
+ "HanjaMode",
521
+ "JunjaMode",
522
+ "Eisu",
523
+ "Hankaku",
524
+ "Hiragana",
525
+ "HiraganaKatakana",
526
+ "KanaMode",
527
+ "KanjiMode",
528
+ "Katakana",
529
+ "Romaji",
530
+ "Zenkaku",
531
+ "ZenkakuHanaku",
532
+ "F1",
533
+ "F2",
534
+ "F3",
535
+ "F4",
536
+ "F5",
537
+ "F6",
538
+ "F7",
539
+ "F8",
540
+ "F9",
541
+ "F10",
542
+ "F11",
543
+ "F12",
544
+ "Soft1",
545
+ "Soft2",
546
+ "Soft3",
547
+ "Soft4",
548
+ "ChannelDown",
549
+ "ChannelUp",
550
+ "Close",
551
+ "MailForward",
552
+ "MailReply",
553
+ "MailSend",
554
+ "MediaFastForward",
555
+ "MediaPause",
556
+ "MediaPlay",
557
+ "MediaPlayPause",
558
+ "MediaRecord",
559
+ "MediaRewind",
560
+ "MediaStop",
561
+ "MediaTrackNext",
562
+ "MediaTrackPrevious",
563
+ "AudioBalanceLeft",
564
+ "AudioBalanceRight",
565
+ "AudioBassBoostDown",
566
+ "AudioBassBoostToggle",
567
+ "AudioBassBoostUp",
568
+ "AudioFaderFront",
569
+ "AudioFaderRear",
570
+ "AudioSurroundModeNext",
571
+ "AudioTrebleDown",
572
+ "AudioTrebleUp",
573
+ "AudioVolumeDown",
574
+ "AudioVolumeMute",
575
+ "AudioVolumeUp",
576
+ "MicrophoneToggle",
577
+ "MicrophoneVolumeDown",
578
+ "MicrophoneVolumeMute",
579
+ "MicrophoneVolumeUp",
580
+ "TV",
581
+ "TV3DMode",
582
+ "TVAntennaCable",
583
+ "TVAudioDescription",
584
+ ];
585
+ function unEscapeString(str) {
586
+ const placeholder = "__NEWLINE__";
587
+ str = str.replace(new RegExp(placeholder, "g"), "\n");
588
+ return str;
589
+ }
590
+ function _getServerUrl() {
591
+ let serviceUrl = "https://api.blinq.io";
592
+ if (process.env.NODE_ENV_BLINQ === "dev") {
593
+ serviceUrl = "https://dev.api.blinq.io";
594
+ }
595
+ else if (process.env.NODE_ENV_BLINQ === "stage") {
596
+ serviceUrl = "https://stage.api.blinq.io";
597
+ }
598
+ return serviceUrl;
599
+ }
600
+ export { encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, _getServerUrl, _convertToRegexQuery, _getDataFile, extractStepExampleParameters };
118
601
  //# sourceMappingURL=utils.js.map