automation_model 1.0.587-dev → 1.0.587-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,116 @@
1
+ export async function findHighestWithSameInnerText(cssSelector, scope, web) {
2
+ await web._highlightElements(scope, cssSelector);
3
+ const element = await scope.locator(cssSelector).first();
4
+ if (!element) {
5
+ throw new Error("header element not found");
6
+ }
7
+ const innerText = await element.innerText();
8
+ // climb to the parent element until the innerText is changing, get the top element with the same innerText
9
+ let climb = 0;
10
+ let topElement = element;
11
+ let elementCss = cssSelector;
12
+ while (true) {
13
+ climb++;
14
+ // create a climb xpath: 1: .. 2: ../.. etc.
15
+ const climbXpath = "xpath=" + "../".repeat(climb).slice(0, -1);
16
+ const climbCss = elementCss + " >> " + climbXpath;
17
+ const climbElement = await scope.locator(climbCss).first();
18
+ if (!climbElement) {
19
+ break;
20
+ }
21
+ const climbInnerText = await climbElement.innerText();
22
+ if (climbInnerText !== innerText) {
23
+ break;
24
+ }
25
+ topElement = climbElement;
26
+ elementCss = climbCss;
27
+ }
28
+ return { element: topElement, cssSelector: elementCss, climb: climb, innerText: innerText };
29
+ }
30
+ export async function findCellRectangle(headerResult, rowResult, web, info) {
31
+ await web.scrollIfNeeded(rowResult.element, info);
32
+ // find the header cell and the row cell location
33
+ const headerRect = await headerResult.element.boundingBox();
34
+ const rowRect = await rowResult.element.boundingBox();
35
+ if (!headerRect || !rowRect) {
36
+ throw new Error("element not found");
37
+ }
38
+ // found there rectengle of cell that is in the header horizontal and the row vertical
39
+ return {
40
+ x: headerRect.x,
41
+ y: rowRect.y,
42
+ width: headerRect.width,
43
+ height: rowRect.height,
44
+ };
45
+ }
46
+ export async function _findCellArea(headerText, rowText, web, state) {
47
+ const headerFoundElements = await web.findTextInAllFrames({}, {}, headerText, state);
48
+ if (headerFoundElements.length === 0) {
49
+ throw new Error("header not found");
50
+ }
51
+ if (headerFoundElements.length > 1) {
52
+ throw new Error("multiple headers found");
53
+ }
54
+ const rowFoundElements = await web.findTextInAllFrames({}, {}, rowText, state);
55
+ if (rowFoundElements.length === 0) {
56
+ throw new Error("row not found");
57
+ }
58
+ if (rowFoundElements.length > 1) {
59
+ throw new Error("multiple rows found");
60
+ }
61
+ const headerScope = headerFoundElements[0].frame;
62
+ const headerResult = await findHighestWithSameInnerText(`[data-blinq-id-${headerFoundElements[0].randomToken}]`, headerScope, web);
63
+ const rowScope = rowFoundElements[0].frame;
64
+ const rowResult = await findHighestWithSameInnerText(`[data-blinq-id-${rowFoundElements[0].randomToken}]`, rowScope, web);
65
+ return await findCellRectangle(headerResult, rowResult, web, state.info);
66
+ }
67
+ export async function findElementsInArea(cssSelector, area, web, options) {
68
+ if (!cssSelector) {
69
+ cssSelector = "*";
70
+ }
71
+ const frames = await web.page.frames();
72
+ const elements = [];
73
+ for (const scope of frames) {
74
+ const count = await scope.locator(cssSelector).count();
75
+ for (let i = 0; i < count; i++) {
76
+ const element = await scope.locator(cssSelector).nth(i);
77
+ elements.push(element);
78
+ }
79
+ }
80
+ const foundElements = [];
81
+ let hTollarance = 10;
82
+ let vTollarance = 10;
83
+ if (options && options.hTollarance && options.vTollarance) {
84
+ hTollarance = options.hTollarance;
85
+ vTollarance = options.vTollarance;
86
+ }
87
+ for (const element of elements) {
88
+ const rect = await element.boundingBox();
89
+ if (!rect) {
90
+ continue;
91
+ }
92
+ if (rect.x >= area.x - hTollarance &&
93
+ rect.x + rect.width <= area.x + area.width + hTollarance &&
94
+ rect.y >= area.y - vTollarance &&
95
+ rect.y + rect.height <= area.y + area.height + vTollarance) {
96
+ foundElements.push(element);
97
+ }
98
+ }
99
+ if (foundElements.length === 0) {
100
+ // find elements that intersect with the area
101
+ for (const element of elements) {
102
+ const rect = await element.boundingBox();
103
+ if (!rect) {
104
+ continue;
105
+ }
106
+ if (rect.x + rect.width >= area.x &&
107
+ rect.x <= area.x + area.width &&
108
+ rect.y + rect.height >= area.y &&
109
+ rect.y <= area.y + area.height) {
110
+ foundElements.push(element);
111
+ }
112
+ }
113
+ }
114
+ return foundElements;
115
+ }
116
+ //# sourceMappingURL=table_helper.js.map
@@ -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,YAAY,CAAC;QAC1B,UAAU,GA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,EAAE;gBACT,SAAS;aACV;YACD,IACE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;gBAC7B,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK;gBAC7B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;gBAC9B,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAC9B;gBACA,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC7B;SACF;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,7 +1,10 @@
1
1
  declare function encrypt(text: string, key?: string | null): string;
2
- declare function decrypt(encryptedText: string, key?: string | null, totpWait?: boolean): Promise<string>;
2
+ declare function getTestDataValue(key: string, environment?: string): any;
3
+ declare function decrypt(encryptedText: string, key?: string | null, totpWait?: boolean): string;
4
+ export declare function testForRegex(text: string): boolean;
3
5
  declare function _convertToRegexQuery(text: string, isRegex: boolean, fullMatch: boolean, ignoreCase: boolean): string;
4
- declare function replaceWithLocalTestData(value: string, world: any, _decrypt?: boolean, totpWait?: boolean, context?: any, stable?: any): Promise<string>;
6
+ declare function _getDataFile(world?: any, context?: any, web?: any): string;
7
+ declare function replaceWithLocalTestData(value: string, world: any, _decrypt?: boolean, totpWait?: boolean, context?: any, web?: any): Promise<string>;
5
8
  declare function maskValue(value: string): string;
6
9
  declare function _copyContext(from: any, to: any): void;
7
10
  declare function scrollPageToLoadLazyElements(page: any): Promise<void>;
@@ -11,7 +14,10 @@ declare function getWebLogFile(logFolder: string): string;
11
14
  declare function _fixLocatorUsingParams(locator: any, _params: Params): any;
12
15
  declare function _isObject(value: any): any;
13
16
  declare function scanAndManipulate(currentObj: any, _params: Params): void;
17
+ declare function extractStepExampleParameters(step: any): any;
18
+ export declare function performAction(action: string, element: any, options: any, web: any, state: any, _params: Params): Promise<void>;
14
19
  declare const KEYBOARD_EVENTS: string[];
15
20
  declare function unEscapeString(str: string): string;
16
21
  declare function _getServerUrl(): string;
17
- export { encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, Params, _getServerUrl, _convertToRegexQuery, };
22
+ declare function tryParseJson(input: any): any;
23
+ export { encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, Params, _getServerUrl, _convertToRegexQuery, extractStepExampleParameters, _getDataFile, tryParseJson, getTestDataValue, };
package/lib/utils.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import CryptoJS from "crypto-js";
2
- import objectPath from "object-path";
3
2
  import path from "path";
4
3
  import { TOTP } from "totp-generator";
5
4
  import fs from "fs";
5
+ import axios from "axios";
6
+ import objectPath from "object-path";
6
7
  // Function to encrypt a string
7
8
  function encrypt(text, key = null) {
8
9
  if (!key) {
@@ -10,8 +11,25 @@ function encrypt(text, key = null) {
10
11
  }
11
12
  return CryptoJS.AES.encrypt(text, key).toString();
12
13
  }
14
+ function getTestDataValue(key, environment = "*") {
15
+ const blinqEnvPath = "data/data.json";
16
+ const envPath = path.resolve(process.cwd(), blinqEnvPath);
17
+ const envJson = JSON.parse(fs.readFileSync(envPath, "utf-8"));
18
+ const dataArray = envJson[environment];
19
+ const item = dataArray.find((item) => item.key === key);
20
+ if (!item) {
21
+ throw new Error(`Key ${key} not found in data.json`);
22
+ }
23
+ if (item.DataType === "string") {
24
+ return item.value;
25
+ }
26
+ else if (item.DataType === "secret" || item.DataType === "totp") {
27
+ return decrypt(item.value, null, false);
28
+ }
29
+ throw new Error(`Unsupported data type for key ${key}`);
30
+ }
13
31
  // Function to decrypt a string
14
- async function decrypt(encryptedText, key = null, totpWait = true) {
32
+ function decrypt(encryptedText, key = null, totpWait = true) {
15
33
  if (!key) {
16
34
  key = _findKey();
17
35
  }
@@ -23,13 +41,13 @@ async function decrypt(encryptedText, key = null, totpWait = true) {
23
41
  const bytes = CryptoJS.AES.decrypt(encryptedText, key);
24
42
  encryptedText = bytes.toString(CryptoJS.enc.Utf8);
25
43
  let { otp, expires } = TOTP.generate(encryptedText);
26
- if (totpWait) {
27
- // expires is in unix time, check if we have at least 10 seconds left, if it's less than wait for the expires time
28
- if (expires - Date.now() < 10000) {
29
- await new Promise((resolve) => setTimeout(resolve, (expires - Date.now() + 1000) % 30000));
30
- ({ otp, expires } = TOTP.generate(encryptedText));
31
- }
32
- }
44
+ // if (totpWait) {
45
+ // // expires is in unix time, check if we have at least 10 seconds left, if it's less than wait for the expires time
46
+ // if (expires - Date.now() < 10000) {
47
+ // await new Promise((resolve) => setTimeout(resolve, (expires - Date.now() + 1000) % 30000));
48
+ // ({ otp, expires } = TOTP.generate(encryptedText));
49
+ // }
50
+ // }
33
51
  return otp;
34
52
  }
35
53
  if (encryptedText.startsWith("mask:")) {
@@ -38,6 +56,22 @@ async function decrypt(encryptedText, key = null, totpWait = true) {
38
56
  const bytes = CryptoJS.AES.decrypt(encryptedText, key);
39
57
  return bytes.toString(CryptoJS.enc.Utf8);
40
58
  }
59
+ export function testForRegex(text) {
60
+ const regexEndPattern = /\/([gimuy]*)$/;
61
+ if (text.startsWith("/")) {
62
+ const match = regexEndPattern.test(text);
63
+ if (match) {
64
+ try {
65
+ const regex = new RegExp(text.substring(1, text.lastIndexOf("/")), text.match(regexEndPattern)[1]);
66
+ return true;
67
+ }
68
+ catch {
69
+ // not regex
70
+ }
71
+ }
72
+ }
73
+ return false;
74
+ }
41
75
  function _convertToRegexQuery(text, isRegex, fullMatch, ignoreCase) {
42
76
  let query = "internal:text=/";
43
77
  let queryEnd = "/";
@@ -48,6 +82,7 @@ function _convertToRegexQuery(text, isRegex, fullMatch, ignoreCase) {
48
82
  if (match) {
49
83
  try {
50
84
  const regex = new RegExp(text.substring(1, text.lastIndexOf("/")), text.match(regexEndPattern)[1]);
85
+ text = text.replace(/"/g, '\\"');
51
86
  return "internal:text=" + text;
52
87
  }
53
88
  catch {
@@ -113,53 +148,166 @@ function _findKey() {
113
148
  // extract the base folder name
114
149
  return path.basename(folder);
115
150
  }
116
- function _getDataFile(world = null, context = null, stable = null) {
151
+ function _getDataFile(world = null, context = null, web = null) {
152
+ let dataFile = null;
153
+ if (world && world.reportFolder) {
154
+ dataFile = path.join(world.reportFolder, "data.json");
155
+ }
156
+ else if (web && web.reportFolder) {
157
+ dataFile = path.join(web.reportFolder, "data.json");
158
+ }
159
+ else if (context && context.reportFolder) {
160
+ dataFile = path.join(context.reportFolder, "data.json");
161
+ }
162
+ else {
163
+ dataFile = "data.json";
164
+ }
165
+ return dataFile;
166
+ }
167
+ function _getTestDataFile(world = null, context = null, web = null) {
117
168
  let dataFile = null;
118
169
  if (world && world.reportFolder) {
119
170
  dataFile = path.join(world.reportFolder, "data.json");
120
171
  }
121
- else if (stable && stable.reportFolder) {
122
- dataFile = path.join(stable.reportFolder, "data.json");
172
+ else if (web && web.reportFolder) {
173
+ dataFile = path.join(web.reportFolder, "data.json");
123
174
  }
124
175
  else if (context && context.reportFolder) {
125
176
  dataFile = path.join(context.reportFolder, "data.json");
126
177
  }
178
+ else if (fs.existsSync(path.join("data", "data.json"))) {
179
+ dataFile = path.join("data", "data.json");
180
+ }
127
181
  else {
128
182
  dataFile = "data.json";
129
183
  }
130
184
  return dataFile;
131
185
  }
132
- function _getTestData(world = null, context = null, stable = null) {
133
- const dataFile = _getDataFile(world, context, stable);
186
+ function _getTestData(world = null, context = null, web = null) {
187
+ const dataFile = _getTestDataFile(world, context, web);
134
188
  let data = {};
135
189
  if (fs.existsSync(dataFile)) {
136
190
  data = JSON.parse(fs.readFileSync(dataFile, "utf8"));
137
191
  }
138
192
  return data;
139
193
  }
140
- async function replaceWithLocalTestData(value, world, _decrypt = true, totpWait = true, context = null, stable = null) {
194
+ async function replaceWithLocalTestData(value, world, _decrypt = true, totpWait = true, context = null, web = null) {
141
195
  if (!value) {
142
196
  return value;
143
197
  }
198
+ let env = "";
199
+ if (context && context.environment) {
200
+ env = context.environment.name;
201
+ }
144
202
  // find all the accurance of {{(.*?)}} and replace with the value
145
203
  let regex = /{{(.*?)}}/g;
146
204
  let matches = value.match(regex);
147
205
  if (matches) {
148
- const testData = _getTestData(world, context, stable);
206
+ const testData = _getTestData(world, context, web);
149
207
  for (let i = 0; i < matches.length; i++) {
150
208
  let match = matches[i];
151
209
  let key = match.substring(2, match.length - 2);
152
- let newValue = objectPath.get(testData, key, null);
153
- if (newValue !== null) {
154
- value = value.replace(match, newValue);
210
+ if (key && key.trim().startsWith("date:")) {
211
+ const dateQuery = key.substring(5);
212
+ const parts = dateQuery.split(">>");
213
+ const returnTemplate = parts[1] || null;
214
+ let serviceUrl = _getServerUrl();
215
+ const config = {
216
+ method: "post",
217
+ url: `${serviceUrl}/api/runs/find-date/find`,
218
+ headers: {
219
+ "x-source": "true",
220
+ "Content-Type": "application/json",
221
+ Authorization: `Bearer ${process.env.TOKEN}`,
222
+ },
223
+ data: JSON.stringify({
224
+ value: parts[0],
225
+ }),
226
+ };
227
+ let result = await axios.request(config);
228
+ //console.log(JSON.stringify(frameDump[0]));
229
+ if (result.status !== 200 || !result.data || result.data.status !== true || !result.data.result) {
230
+ console.error("Failed to find date");
231
+ throw new Error("Failed to find date");
232
+ }
233
+ value = formatDate(result.data.result, returnTemplate);
234
+ }
235
+ else {
236
+ let newValue = replaceTestDataValue(env, key, testData, _decrypt);
237
+ if (newValue !== null) {
238
+ value = value.replace(match, newValue);
239
+ }
240
+ else {
241
+ newValue = replaceTestDataValue("*", key, testData, _decrypt);
242
+ if (newValue !== null) {
243
+ value = value.replace(match, newValue);
244
+ }
245
+ }
155
246
  }
156
247
  }
157
248
  }
158
249
  if ((value.startsWith("secret:") || value.startsWith("totp:") || value.startsWith("mask:")) && _decrypt) {
159
- return await decrypt(value, null, totpWait);
250
+ return decrypt(value, null, totpWait);
251
+ }
252
+ // check if the value is ${}
253
+ if (value.startsWith("${") && value.endsWith("}")) {
254
+ value = evaluateString(value, context.examplesRow);
160
255
  }
161
256
  return value;
162
257
  }
258
+ function replaceTestDataValue(env, key, testData, decryptValue = true) {
259
+ const path = key.split(".");
260
+ const value = objectPath.get(testData, path);
261
+ if (value && !Array.isArray(value)) {
262
+ return value;
263
+ }
264
+ const dataArray = testData[env];
265
+ if (!dataArray) {
266
+ return null;
267
+ }
268
+ for (const obj of dataArray) {
269
+ if (obj.key !== key) {
270
+ continue;
271
+ }
272
+ if (obj.DataType === "secret") {
273
+ if (decryptValue === true) {
274
+ return decrypt(`secret:${obj.value}`, null);
275
+ }
276
+ else {
277
+ return `secret:${obj.value}`;
278
+ }
279
+ }
280
+ return obj.value;
281
+ }
282
+ return null;
283
+ }
284
+ function evaluateString(template, parameters) {
285
+ if (!parameters) {
286
+ parameters = {};
287
+ }
288
+ try {
289
+ return new Function(...Object.keys(parameters), `return \`${template}\`;`)(...Object.values(parameters));
290
+ }
291
+ catch (e) {
292
+ console.error(e);
293
+ return template;
294
+ }
295
+ }
296
+ function formatDate(dateStr, format) {
297
+ if (!format) {
298
+ return dateStr;
299
+ }
300
+ // Split the input date string
301
+ const [dd, mm, yyyy] = dateStr.split("-");
302
+ // Define replacements
303
+ const replacements = {
304
+ dd: dd,
305
+ mm: mm,
306
+ yyyy: yyyy,
307
+ };
308
+ // Replace format placeholders with actual values
309
+ return format.replace(/dd|mm|yyyy/g, (match) => replacements[match]);
310
+ }
163
311
  function maskValue(value) {
164
312
  if (!value) {
165
313
  return value;
@@ -248,6 +396,118 @@ function scanAndManipulate(currentObj, _params) {
248
396
  }
249
397
  }
250
398
  }
399
+ function extractStepExampleParameters(step) {
400
+ if (!step ||
401
+ !step.gherkinDocument ||
402
+ !step.pickle ||
403
+ !step.pickle.astNodeIds ||
404
+ !(step.pickle.astNodeIds.length > 1) ||
405
+ !step.gherkinDocument.feature ||
406
+ !step.gherkinDocument.feature.children) {
407
+ return {};
408
+ }
409
+ try {
410
+ const scenarioId = step.pickle.astNodeIds[0];
411
+ const exampleId = step.pickle.astNodeIds[1];
412
+ // find the scenario in the gherkin document
413
+ const scenario = step.gherkinDocument.feature.children.find((child) => child.scenario.id === scenarioId).scenario;
414
+ if (!scenario || !scenario.examples || !scenario.examples[0].tableBody) {
415
+ return {};
416
+ }
417
+ // find the table body in the examples
418
+ const row = scenario.examples[0].tableBody.find((r) => r.id === exampleId);
419
+ if (!row) {
420
+ return {};
421
+ }
422
+ // extract the cells values (row.cells.value) into an array
423
+ const values = row.cells.map((cell) => cell.value);
424
+ // extract the table headers keys (scenario.examples.tableHeader.cells.value) into an array
425
+ const keys = scenario.examples[0].tableHeader.cells.map((cell) => cell.value);
426
+ // create a dictionary of the keys and values
427
+ const params = {};
428
+ for (let i = 0; i < keys.length; i++) {
429
+ params[keys[i]] = values[i];
430
+ }
431
+ return params;
432
+ }
433
+ catch (e) {
434
+ console.error(e);
435
+ return {};
436
+ }
437
+ }
438
+ export async function performAction(action, element, options, web, state, _params) {
439
+ let usedOptions;
440
+ if (!options) {
441
+ options = {};
442
+ }
443
+ if (!element) {
444
+ throw new Error("Element not found");
445
+ }
446
+ switch (action) {
447
+ case "click":
448
+ // copy any of the following options to usedOptions: button, clickCount, delay, modifiers, force, position, trial
449
+ usedOptions = ["button", "clickCount", "delay", "modifiers", "force", "position", "trial", "timeout"].reduce((acc, key) => {
450
+ if (options[key]) {
451
+ acc[key] = options[key];
452
+ }
453
+ return acc;
454
+ }, {});
455
+ if (!usedOptions.timeout) {
456
+ usedOptions.timeout = 10000;
457
+ if (usedOptions.position) {
458
+ usedOptions.timeout = 1000;
459
+ }
460
+ }
461
+ try {
462
+ await element.click(usedOptions);
463
+ }
464
+ catch (e) {
465
+ if (usedOptions.position) {
466
+ // find the element bounding box
467
+ const rect = await element.boundingBox();
468
+ // calculate the x and y position
469
+ const x = rect.x + rect.width / 2 + (usedOptions.position.x || 0);
470
+ const y = rect.y + rect.height / 2 + (usedOptions.position.y || 0);
471
+ // click on the x and y position
472
+ await web.page.mouse.click(x, y);
473
+ }
474
+ else {
475
+ if (state && state.selectors) {
476
+ state.element = await web._locate(state.selectors, state.info, _params);
477
+ element = state.element;
478
+ }
479
+ await element.dispatchEvent("click");
480
+ }
481
+ }
482
+ break;
483
+ case "hover":
484
+ usedOptions = ["position", "trial", "timeout"].reduce((acc, key) => {
485
+ acc[key] = options[key];
486
+ return acc;
487
+ }, {});
488
+ try {
489
+ await element.hover(usedOptions);
490
+ await new Promise((resolve) => setTimeout(resolve, 1000));
491
+ }
492
+ catch (e) {
493
+ if (state && state.selectors) {
494
+ state.info.log += "hover failed, will try again" + "\n";
495
+ state.element = await web._locate(state.selectors, state.info, _params);
496
+ element = state.element;
497
+ }
498
+ usedOptions.timeout = 10000;
499
+ await element.hover(usedOptions);
500
+ await new Promise((resolve) => setTimeout(resolve, 1000));
501
+ }
502
+ break;
503
+ case "hover+click":
504
+ await performAction("hover", element, options, web, state, _params);
505
+ await performAction("click", element, options, web, state, _params);
506
+ break;
507
+ default:
508
+ throw new Error(`Action ${action} not supported`);
509
+ }
510
+ }
251
511
  const KEYBOARD_EVENTS = [
252
512
  "ALT",
253
513
  "AltGraph",
@@ -407,7 +667,28 @@ function _getServerUrl() {
407
667
  else if (process.env.NODE_ENV_BLINQ === "stage") {
408
668
  serviceUrl = "https://stage.api.blinq.io";
409
669
  }
670
+ else if (process.env.NODE_ENV_BLINQ === "prod") {
671
+ serviceUrl = "https://api.blinq.io";
672
+ }
673
+ else if (!process.env.NODE_ENV_BLINQ) {
674
+ serviceUrl = "https://api.blinq.io";
675
+ }
676
+ else {
677
+ serviceUrl = process.env.NODE_ENV_BLINQ;
678
+ }
410
679
  return serviceUrl;
411
680
  }
412
- export { encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, _getServerUrl, _convertToRegexQuery, };
681
+ function tryParseJson(input) {
682
+ if (typeof input === "string") {
683
+ try {
684
+ return JSON.parse(input);
685
+ }
686
+ catch {
687
+ // If parsing fails, return the original input (assumed to be plain text or another format)
688
+ return input;
689
+ }
690
+ }
691
+ return input;
692
+ }
693
+ export { encrypt, decrypt, replaceWithLocalTestData, maskValue, _copyContext, scrollPageToLoadLazyElements, _fixUsingParams, getWebLogFile, _fixLocatorUsingParams, _isObject, scanAndManipulate, KEYBOARD_EVENTS, unEscapeString, _getServerUrl, _convertToRegexQuery, extractStepExampleParameters, _getDataFile, tryParseJson, getTestDataValue, };
413
694
  //# sourceMappingURL=utils.js.map