@dev-blinq/cucumber_client 1.0.1223-dev → 1.0.1225-dev
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.
- package/bin/assets/preload/recorderv3.js +1 -0
- package/bin/assets/preload/unique_locators.js +2 -1
- package/bin/client/code_cleanup/utils.js +6 -1
- package/bin/client/code_gen/page_reflection.js +21 -5
- package/bin/client/recorderv3/step_utils.js +12 -2
- package/bin/client/run_cucumber.js +10 -1
- package/package.json +2 -2
|
@@ -357,6 +357,7 @@ function generateUniqueCSSSelector(element, options) {
|
|
|
357
357
|
const root = options?.root || window.document;
|
|
358
358
|
const separator = options?.separator || " > ";
|
|
359
359
|
const isUnique = options?.isunique || ((selector) => getMatchingElements(selector, options).length === 1);
|
|
360
|
+
const noCSSId = options?.noCSSId || false;
|
|
360
361
|
|
|
361
362
|
if (!(element instanceof Element)) return null;
|
|
362
363
|
|
|
@@ -364,7 +365,7 @@ function generateUniqueCSSSelector(element, options) {
|
|
|
364
365
|
|
|
365
366
|
let selector = "";
|
|
366
367
|
const id = element.getAttribute("id");
|
|
367
|
-
if (id && !/\d/.test(id)) {
|
|
368
|
+
if (id && !/\d/.test(id) && (!noCSSId)) {
|
|
368
369
|
selector = "#" + cssEscape(id);
|
|
369
370
|
if (isUnique(selector)) return selector;
|
|
370
371
|
}
|
|
@@ -10,6 +10,7 @@ import * as t from "@babel/types";
|
|
|
10
10
|
|
|
11
11
|
import { CucumberExpression, ParameterTypeRegistry } from "@cucumber/cucumber-expressions";
|
|
12
12
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
13
|
+
import { getAiConfig } from "../code_gen/page_reflection";
|
|
13
14
|
const STEP_KEYWORDS = new Set(["Given", "When", "Then"]);
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -293,7 +294,11 @@ export function removeUnusedElementsKeys(ast, supportFilePath) {
|
|
|
293
294
|
* @param {Array<{keyword: string, pattern: string}>} stepDefinitions
|
|
294
295
|
*/
|
|
295
296
|
export async function removeUnusedStepDefinitions(filePath, stepDefinitions) {
|
|
296
|
-
|
|
297
|
+
let supportFilePath = filePath.replace(".mjs", ".json");
|
|
298
|
+
const config = getAiConfig();
|
|
299
|
+
if (config && config.locatorsMetadataDir) {
|
|
300
|
+
supportFilePath = path.join(config.locatorsMetadataDir, path.basename(supportFilePath));
|
|
301
|
+
}
|
|
297
302
|
const ast = await parse(filePath);
|
|
298
303
|
removeStepDefinitions(stepDefinitions, ast);
|
|
299
304
|
removeUnusedDeclarations(ast);
|
|
@@ -22,6 +22,18 @@ function unescapeFromComment(text) {
|
|
|
22
22
|
.replace(/\*\\/g, "*/") // Unescape comment-closing sequence
|
|
23
23
|
.replace(/\\\\/g, "\\"); // Unescape backslashes
|
|
24
24
|
}
|
|
25
|
+
let ai_config = null;
|
|
26
|
+
export function getAiConfig() {
|
|
27
|
+
if (ai_config) {
|
|
28
|
+
return ai_config;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
ai_config = JSON.parse(readFileSync("ai_config.json", "utf8"));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
ai_config = {};
|
|
34
|
+
}
|
|
35
|
+
return ai_config;
|
|
36
|
+
}
|
|
25
37
|
class CodePage {
|
|
26
38
|
constructor(sourceFileName = null) {
|
|
27
39
|
this.sourceFileName = sourceFileName;
|
|
@@ -224,13 +236,12 @@ this.imports[2].node.source.value
|
|
|
224
236
|
params = paramsObj.map((param) => param.name);
|
|
225
237
|
}
|
|
226
238
|
firstFind = false;
|
|
227
|
-
}
|
|
239
|
+
}
|
|
228
240
|
stepPaths.push(method.path);
|
|
229
|
-
|
|
230
241
|
}
|
|
231
242
|
}
|
|
232
243
|
if (foundMethod) {
|
|
233
|
-
templates.push({ pattern, methodName, params, stepType, paths: stepPaths});
|
|
244
|
+
templates.push({ pattern, methodName, params, stepType, paths: stepPaths });
|
|
234
245
|
}
|
|
235
246
|
}
|
|
236
247
|
}
|
|
@@ -481,7 +492,12 @@ this.imports[2].node.source.value
|
|
|
481
492
|
}
|
|
482
493
|
addLocatorsMetadata(locatorsMetadata) {
|
|
483
494
|
// create a file name based on the source file name replace .mjs with .json
|
|
484
|
-
|
|
495
|
+
let locatorsMetadataFileName = this.sourceFileName.replace(".mjs", ".json");
|
|
496
|
+
const config = getAiConfig();
|
|
497
|
+
if (config && config.locatorsMetadataDir) {
|
|
498
|
+
// if config.locatorsMetadataDir is set, use it to create the file path
|
|
499
|
+
locatorsMetadataFileName = path.join(config.locatorsMetadataDir, path.basename(locatorsMetadataFileName));
|
|
500
|
+
}
|
|
485
501
|
let metadata = {};
|
|
486
502
|
// try to read the file to metadata, protect with try catch
|
|
487
503
|
try {
|
|
@@ -782,7 +798,7 @@ function getPath(comment) {
|
|
|
782
798
|
if (index === -1) {
|
|
783
799
|
return null;
|
|
784
800
|
}
|
|
785
|
-
return comment.substring(index).split(
|
|
801
|
+
return comment.substring(index).split("\n")[0].substring(6);
|
|
786
802
|
}
|
|
787
803
|
|
|
788
804
|
class CodePart {
|
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import url from "url";
|
|
4
4
|
import logger from "../../logger.js";
|
|
5
|
-
import { CodePage } from "../code_gen/page_reflection.js";
|
|
5
|
+
import { CodePage, getAiConfig } from "../code_gen/page_reflection.js";
|
|
6
6
|
import { generateCode, generatePageName } from "../code_gen/playwright_codeget.js";
|
|
7
7
|
import { invertCodeToCommand } from "../code_gen/code_inversion.js";
|
|
8
8
|
import { Step } from "../cucumber/feature.js";
|
|
@@ -187,7 +187,17 @@ export async function saveRecording({ step, cucumberStep, codePage, projectDir,
|
|
|
187
187
|
|
|
188
188
|
const getLocatorsJson = (file) => {
|
|
189
189
|
if (!file) return {};
|
|
190
|
-
|
|
190
|
+
let locatorsFilePath = file.replace(".mjs", ".json");
|
|
191
|
+
const originLocatorsFilePath = locatorsFilePath;
|
|
192
|
+
const config = getAiConfig();
|
|
193
|
+
if (config && config.locatorsMetadataDir) {
|
|
194
|
+
// if config.locatorsMetadataDir is set, use it to create the file path
|
|
195
|
+
locatorsFilePath = path.join(config.locatorsMetadataDir, path.basename(locatorsFilePath));
|
|
196
|
+
if (!existsSync(locatorsFilePath)) {
|
|
197
|
+
// if the file does not exist in the config directory, use the original path
|
|
198
|
+
locatorsFilePath = originLocatorsFilePath;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
191
201
|
if (!existsSync(locatorsFilePath)) {
|
|
192
202
|
return {};
|
|
193
203
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
|
|
2
2
|
import logger from "../logger.js";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { scenarioResolution } from "./cucumber/feature.js";
|
|
@@ -236,6 +236,15 @@ const runCucumber = async (
|
|
|
236
236
|
|
|
237
237
|
let scenarioId = findNextIdInFolder("./reports");
|
|
238
238
|
let scenarioPath = "./reports" + "/" + scenarioId;
|
|
239
|
+
const dataFilePath = path.join(scenarioPath, "data.json");
|
|
240
|
+
mkdirSync(path.dirname(dataFilePath), { recursive: true });
|
|
241
|
+
if (process.env.NODE_ENV_BLINQ === "local") {
|
|
242
|
+
let dataPath = aiAgent.project.rootFolder + "/data/data.json";
|
|
243
|
+
if (existsSync(dataPath)) {
|
|
244
|
+
const poolData = JSON.parse(readFileSync(dataPath, "utf-8"));
|
|
245
|
+
writeFileSync(dataFilePath, JSON.stringify(poolData, null, 2), "utf-8");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
239
248
|
result.scenarioPath = scenarioPath;
|
|
240
249
|
aiAgent.initTestData(envFile, path.join(scenarioPath, "data.json"));
|
|
241
250
|
let featureFileRelative = path.relative(projectDir, fullFeatureFilePath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev-blinq/cucumber_client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1225-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"types": "bin/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@cucumber/tag-expressions": "^6.1.1",
|
|
29
29
|
"@dev-blinq/cucumber-js": "1.0.172-dev",
|
|
30
30
|
"@faker-js/faker": "^8.1.0",
|
|
31
|
-
"automation_model": "1.0.
|
|
31
|
+
"automation_model": "1.0.737-dev",
|
|
32
32
|
"axios": "^1.7.4",
|
|
33
33
|
"chokidar": "^3.6.0",
|
|
34
34
|
"create-require": "^1.1.1",
|