artes 1.7.4 → 1.7.6

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 (48) hide show
  1. package/README.md +781 -779
  2. package/assets/styles.css +4 -4
  3. package/cucumber.config.js +253 -253
  4. package/docs/ciExecutors.md +198 -198
  5. package/docs/emulationDevicesList.md +152 -152
  6. package/docs/functionDefinitions.md +2401 -2401
  7. package/docs/stepDefinitions.md +435 -433
  8. package/executer.js +266 -264
  9. package/index.js +50 -50
  10. package/package.json +56 -56
  11. package/src/helper/contextManager/browserManager.js +74 -74
  12. package/src/helper/contextManager/requestManager.js +23 -23
  13. package/src/helper/controller/elementController.js +210 -210
  14. package/src/helper/controller/findDuplicateTestNames.js +69 -69
  15. package/src/helper/controller/getEnvInfo.js +94 -94
  16. package/src/helper/controller/getExecutor.js +109 -109
  17. package/src/helper/controller/pomCollector.js +83 -83
  18. package/src/helper/controller/reportCustomizer.js +485 -485
  19. package/src/helper/controller/screenComparer.js +97 -108
  20. package/src/helper/controller/status-formatter.js +137 -137
  21. package/src/helper/controller/testCoverageCalculator.js +111 -111
  22. package/src/helper/executers/cleaner.js +23 -23
  23. package/src/helper/executers/exporter.js +19 -19
  24. package/src/helper/executers/helper.js +193 -191
  25. package/src/helper/executers/projectCreator.js +226 -222
  26. package/src/helper/executers/reportGenerator.js +91 -91
  27. package/src/helper/executers/testRunner.js +28 -28
  28. package/src/helper/executers/versionChecker.js +31 -31
  29. package/src/helper/imports/commons.js +65 -65
  30. package/src/helper/stepFunctions/APIActions.js +495 -495
  31. package/src/helper/stepFunctions/assertions.js +986 -986
  32. package/src/helper/stepFunctions/browserActions.js +87 -87
  33. package/src/helper/stepFunctions/elementInteractions.js +60 -60
  34. package/src/helper/stepFunctions/exporter.js +19 -19
  35. package/src/helper/stepFunctions/frameActions.js +72 -72
  36. package/src/helper/stepFunctions/keyboardActions.js +66 -66
  37. package/src/helper/stepFunctions/mouseActions.js +84 -84
  38. package/src/helper/stepFunctions/pageActions.js +43 -43
  39. package/src/hooks/context.js +15 -15
  40. package/src/hooks/hooks.js +287 -279
  41. package/src/stepDefinitions/API.steps.js +310 -310
  42. package/src/stepDefinitions/assertions.steps.js +1303 -1280
  43. package/src/stepDefinitions/browser.steps.js +74 -74
  44. package/src/stepDefinitions/frameActions.steps.js +76 -76
  45. package/src/stepDefinitions/keyboardActions.steps.js +264 -264
  46. package/src/stepDefinitions/mouseActions.steps.js +378 -378
  47. package/src/stepDefinitions/page.steps.js +71 -71
  48. package/src/stepDefinitions/random.steps.js +191 -191
@@ -1,108 +1,97 @@
1
- const path = require("path");
2
- const fs = require("fs");
3
- require("allure-cucumberjs");
4
- const allure = require("allure-js-commons");
5
- const sharp = require("sharp");
6
- const pixelmatch = require("pixelmatch");
7
- const { PNG } = require("pngjs");
8
- const { moduleConfig } = require("artes/src/helper/imports/commons");
9
-
10
- async function screenComparer(baselineFilename, screenshotFn, options = {}) {
11
- const { maxDiffPercent = 0.01, threshold = 0.1 } = options;
12
-
13
- const baselinePath = path.join(moduleConfig.projectPath, baselineFilename);
14
- const actualPath = path.join(
15
- moduleConfig.projectPath,
16
- "visualComparison",
17
- `actual_${baselineFilename}`,
18
- );
19
- const diffPath = path.join(
20
- moduleConfig.projectPath,
21
- "visualComparison",
22
- `diff_${baselineFilename}`,
23
- );
24
-
25
- await screenshotFn(actualPath);
26
-
27
- const baselineMeta = await sharp(baselinePath).metadata();
28
- const actualMeta = await sharp(actualPath).metadata();
29
-
30
- // if (baselineMeta.width !== actualMeta.width || baselineMeta.height !== actualMeta.height) {
31
- // console.warn(`⚠️ Dimension mismatch! Baseline: ${baselineMeta.width}x${baselineMeta.height} | Actual: ${actualMeta.width}x${actualMeta.height}`);
32
- // }
33
-
34
- const width = actualMeta.width;
35
- const height = actualMeta.height;
36
-
37
- const baselineBuffer = await sharp(baselinePath)
38
- .resize(width, height, { fit: "fill" })
39
- .ensureAlpha()
40
- .raw()
41
- .toBuffer();
42
-
43
- const actualBuffer = await sharp(actualPath)
44
- .resize(width, height, { fit: "fill" })
45
- .ensureAlpha()
46
- .raw()
47
- .toBuffer();
48
-
49
- const diffImg = new PNG({ width, height });
50
-
51
- const mismatchedPixels = pixelmatch(
52
- baselineBuffer,
53
- actualBuffer,
54
- diffImg.data,
55
- width,
56
- height,
57
- { threshold, includeAA: false },
58
- );
59
-
60
- fs.writeFileSync(diffPath, PNG.sync.write(diffImg));
61
-
62
- const totalPixels = width * height;
63
- const mismatchRatio = mismatchedPixels / totalPixels;
64
-
65
- const expectedBase64 = (
66
- await sharp(baselinePath)
67
- .resize(width, height, { fit: "fill" })
68
- .png()
69
- .toBuffer()
70
- ).toString("base64");
71
- const actualBase64 = (await sharp(actualPath).png().toBuffer()).toString(
72
- "base64",
73
- );
74
- const diffBase64 = (await sharp(diffPath).png().toBuffer()).toString(
75
- "base64",
76
- );
77
-
78
- const content = JSON.stringify({
79
- expected: `data:image/png;base64,${expectedBase64}`,
80
- actual: `data:image/png;base64,${actualBase64}`,
81
- diff: `data:image/png;base64,${diffBase64}`,
82
- });
83
-
84
- await allure.attachment(
85
- "Screenshot diff details",
86
- ` Mismatched pixels: ${mismatchedPixels} / ${totalPixels} (${(mismatchRatio * 100).toFixed(2)}%) Max allowed: ${maxDiffPercent * 100}%`,
87
- "text/plain",
88
- );
89
- await allure.attachment(
90
- "Screenshot diff",
91
- content,
92
- "application/vnd.allure.image.diff",
93
- );
94
-
95
- if (fs.existsSync(path.join(moduleConfig.projectPath, "visualComparison")))
96
- fs.rmSync(path.join(moduleConfig.projectPath, "visualComparison"), {
97
- recursive: true,
98
- force: true,
99
- });
100
-
101
- if (mismatchRatio > maxDiffPercent) {
102
- throw new Error(
103
- `Screenshot mismatch: ${(mismatchRatio * 100).toFixed(2)}% pixels differ (max allowed: ${maxDiffPercent * 100}%)`,
104
- );
105
- }
106
- }
107
-
108
- module.exports = { screenComparer };
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ require("allure-cucumberjs");
4
+ const allure = require("allure-js-commons");
5
+ const sharp = require("sharp");
6
+ const pixelmatch = require("pixelmatch");
7
+ const { PNG } = require("pngjs");
8
+ const { moduleConfig } = require("artes/src/helper/imports/commons");
9
+
10
+ async function screenComparer(baselineFilename, screenshotFn, options = {}) {
11
+ const { maxDiffPercent = 0.01, threshold = 0.1, comparePath } = options;
12
+
13
+ const baselinePath = path.join(moduleConfig.projectPath, baselineFilename);
14
+
15
+ const actualPath = comparePath
16
+ ? path.join(moduleConfig.projectPath, comparePath)
17
+ : path.join(moduleConfig.projectPath, "visualComparison", `actual_${baselineFilename}`);
18
+
19
+ const diffPath = path.join(
20
+ moduleConfig.projectPath,
21
+ "visualComparison",
22
+ `diff_${baselineFilename}`,
23
+ );
24
+
25
+ const visualComparisonDir = path.join(moduleConfig.projectPath, "visualComparison");
26
+ if (!fs.existsSync(visualComparisonDir)) {
27
+ fs.mkdirSync(visualComparisonDir, { recursive: true });
28
+ }
29
+
30
+ if (!comparePath) {
31
+ await screenshotFn(actualPath);
32
+ }
33
+
34
+ const { width, height } = await sharp(actualPath).metadata();
35
+
36
+ const baselineBuffer = await sharp(baselinePath)
37
+ .resize(width, height, { fit: "fill" })
38
+ .ensureAlpha()
39
+ .raw()
40
+ .toBuffer();
41
+
42
+ const actualBuffer = await sharp(actualPath)
43
+ .resize(width, height, { fit: "fill" })
44
+ .ensureAlpha()
45
+ .raw()
46
+ .toBuffer();
47
+
48
+ const diffImg = new PNG({ width, height });
49
+
50
+ const mismatchedPixels = pixelmatch(
51
+ baselineBuffer,
52
+ actualBuffer,
53
+ diffImg.data,
54
+ width,
55
+ height,
56
+ { threshold, includeAA: false },
57
+ );
58
+
59
+ fs.writeFileSync(diffPath, PNG.sync.write(diffImg));
60
+
61
+ const totalPixels = width * height;
62
+ const mismatchRatio = mismatchedPixels / totalPixels;
63
+
64
+ const expectedBase64 = (await sharp(baselinePath).resize(width, height, { fit: "fill" }).png().toBuffer()).toString("base64");
65
+ const actualBase64 = (await sharp(actualPath).png().toBuffer()).toString("base64");
66
+ const diffBase64 = (await sharp(diffPath).png().toBuffer()).toString("base64");
67
+
68
+ const content = JSON.stringify({
69
+ expected: `data:image/png;base64,${expectedBase64}`,
70
+ actual: `data:image/png;base64,${actualBase64}`,
71
+ diff: `data:image/png;base64,${diffBase64}`,
72
+ });
73
+
74
+ await allure.attachment(
75
+ "Screenshot diff details",
76
+ `Mismatched pixels: ${mismatchedPixels} / ${totalPixels} (${(mismatchRatio * 100).toFixed(2)}%) Max allowed: ${maxDiffPercent * 100}%`,
77
+ "text/plain",
78
+ );
79
+
80
+ await allure.attachment(
81
+ "Screenshot diff",
82
+ content,
83
+ "application/vnd.allure.image.diff",
84
+ );
85
+
86
+ if (fs.existsSync(visualComparisonDir)) {
87
+ fs.rmSync(visualComparisonDir, { recursive: true, force: true });
88
+ }
89
+
90
+ if (mismatchRatio > maxDiffPercent) {
91
+ throw new Error(
92
+ `Screenshot mismatch: ${(mismatchRatio * 100).toFixed(2)}% pixels differ (max allowed: ${maxDiffPercent * 100}%)`,
93
+ );
94
+ }
95
+ }
96
+
97
+ module.exports = { screenComparer };
@@ -1,137 +1,137 @@
1
- const { Formatter } = require("@cucumber/cucumber");
2
- const fs = require("fs");
3
- const path = require("path");
4
-
5
- class StatusFormatter extends Formatter {
6
- constructor(options) {
7
- super(options);
8
-
9
- const outputDir = "./test-status";
10
- if (!fs.existsSync(outputDir)) {
11
- fs.mkdirSync(outputDir, { recursive: true });
12
- }
13
-
14
- const workerId = process.env.CUCUMBER_WORKER_ID || "0";
15
- this.workerId = workerId;
16
- this.outputFile = path.join(outputDir, `test-results-${workerId}.txt`);
17
- this.outputDir = outputDir;
18
-
19
- fs.writeFileSync(this.outputFile, "", "utf8");
20
-
21
- this.pickles = new Map();
22
- this.testCases = new Map();
23
- this.testCaseStartedIdToAttempt = new Map();
24
-
25
- const { eventBroadcaster } = options;
26
-
27
- eventBroadcaster.on("envelope", (envelope) => {
28
- if (envelope.pickle) {
29
- this.pickles.set(envelope.pickle.id, envelope.pickle);
30
- }
31
-
32
- if (envelope.testCase) {
33
- this.testCases.set(envelope.testCase.id, envelope.testCase);
34
- }
35
-
36
- if (envelope.testCaseStarted) {
37
- this.testCaseStartedIdToAttempt.set(
38
- envelope.testCaseStarted.id,
39
- envelope.testCaseStarted.testCaseId,
40
- );
41
- }
42
-
43
- if (envelope.testCaseFinished) {
44
- this.handleTestCaseFinished(envelope.testCaseFinished);
45
- }
46
-
47
- if (envelope.testRunFinished) {
48
- this.handleTestRunFinished();
49
- }
50
- });
51
- }
52
-
53
- getFormattedTimestamp() {
54
- const now = new Date();
55
- const YYYY = now.getFullYear();
56
- const MM = String(now.getMonth() + 1).padStart(2, "0");
57
- const DD = String(now.getDate()).padStart(2, "0");
58
- const hh = String(now.getHours()).padStart(2, "0");
59
- const mm = String(now.getMinutes()).padStart(2, "0");
60
- const ss = String(now.getSeconds()).padStart(2, "0");
61
- const ms = String(now.getMilliseconds()).padStart(3, "0");
62
-
63
- return `${YYYY}${MM}${DD}-${hh}${mm}${ss}-${ms}`;
64
- }
65
-
66
- handleTestCaseFinished(testCaseFinished) {
67
- try {
68
- const timestamp = this.getFormattedTimestamp();
69
-
70
- const testCaseId = this.testCaseStartedIdToAttempt.get(
71
- testCaseFinished.testCaseStartedId,
72
- );
73
-
74
- if (!testCaseId) return;
75
-
76
- const testCase = this.testCases.get(testCaseId);
77
- if (!testCase) return;
78
-
79
- const pickle = this.pickles.get(testCase.pickleId);
80
- if (!pickle) return;
81
-
82
- const testCaseAttempt = this.eventDataCollector.getTestCaseAttempt(
83
- testCaseFinished.testCaseStartedId,
84
- );
85
-
86
- const status = testCaseAttempt?.worstTestStepResult?.status || "UNKNOWN";
87
-
88
- const info = {
89
- name: pickle.name,
90
- id: pickle.id,
91
- uri: pickle.uri,
92
- };
93
-
94
- const line = `${timestamp} | ${status.toUpperCase()} | ${info.name} | ${info.id} | ${info.uri}\n`;
95
-
96
- fs.appendFileSync(this.outputFile, line, "utf8");
97
- } catch (error) {
98
- console.error("Error in handleTestCaseFinished:", error);
99
- }
100
- }
101
-
102
- handleTestRunFinished() {
103
- if (this.workerId !== "0") {
104
- return;
105
- }
106
-
107
- setTimeout(() => {
108
- this.mergeResults();
109
- }, 1000);
110
- }
111
-
112
- mergeResults() {
113
- try {
114
- const testStatusFile = path.join(this.outputDir, "test-status.txt");
115
-
116
- const files = fs
117
- .readdirSync(this.outputDir)
118
- .filter((f) => f.startsWith("test-results-") && f.endsWith(".txt"))
119
- .sort();
120
-
121
- if (files.length === 0) {
122
- console.log("No result files found to merge");
123
- return;
124
- }
125
-
126
- const combined = files
127
- .map((f) => fs.readFileSync(path.join(this.outputDir, f), "utf8"))
128
- .join("");
129
-
130
- fs.writeFileSync(testStatusFile, combined, "utf8");
131
- } catch (error) {
132
- console.error("Error merging results:", error);
133
- }
134
- }
135
- }
136
-
137
- module.exports = StatusFormatter;
1
+ const { Formatter } = require("@cucumber/cucumber");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+
5
+ class StatusFormatter extends Formatter {
6
+ constructor(options) {
7
+ super(options);
8
+
9
+ const outputDir = "./test-status";
10
+ if (!fs.existsSync(outputDir)) {
11
+ fs.mkdirSync(outputDir, { recursive: true });
12
+ }
13
+
14
+ const workerId = process.env.CUCUMBER_WORKER_ID || "0";
15
+ this.workerId = workerId;
16
+ this.outputFile = path.join(outputDir, `test-results-${workerId}.txt`);
17
+ this.outputDir = outputDir;
18
+
19
+ fs.writeFileSync(this.outputFile, "", "utf8");
20
+
21
+ this.pickles = new Map();
22
+ this.testCases = new Map();
23
+ this.testCaseStartedIdToAttempt = new Map();
24
+
25
+ const { eventBroadcaster } = options;
26
+
27
+ eventBroadcaster.on("envelope", (envelope) => {
28
+ if (envelope.pickle) {
29
+ this.pickles.set(envelope.pickle.id, envelope.pickle);
30
+ }
31
+
32
+ if (envelope.testCase) {
33
+ this.testCases.set(envelope.testCase.id, envelope.testCase);
34
+ }
35
+
36
+ if (envelope.testCaseStarted) {
37
+ this.testCaseStartedIdToAttempt.set(
38
+ envelope.testCaseStarted.id,
39
+ envelope.testCaseStarted.testCaseId,
40
+ );
41
+ }
42
+
43
+ if (envelope.testCaseFinished) {
44
+ this.handleTestCaseFinished(envelope.testCaseFinished);
45
+ }
46
+
47
+ if (envelope.testRunFinished) {
48
+ this.handleTestRunFinished();
49
+ }
50
+ });
51
+ }
52
+
53
+ getFormattedTimestamp() {
54
+ const now = new Date();
55
+ const YYYY = now.getFullYear();
56
+ const MM = String(now.getMonth() + 1).padStart(2, "0");
57
+ const DD = String(now.getDate()).padStart(2, "0");
58
+ const hh = String(now.getHours()).padStart(2, "0");
59
+ const mm = String(now.getMinutes()).padStart(2, "0");
60
+ const ss = String(now.getSeconds()).padStart(2, "0");
61
+ const ms = String(now.getMilliseconds()).padStart(3, "0");
62
+
63
+ return `${YYYY}${MM}${DD}-${hh}${mm}${ss}-${ms}`;
64
+ }
65
+
66
+ handleTestCaseFinished(testCaseFinished) {
67
+ try {
68
+ const timestamp = this.getFormattedTimestamp();
69
+
70
+ const testCaseId = this.testCaseStartedIdToAttempt.get(
71
+ testCaseFinished.testCaseStartedId,
72
+ );
73
+
74
+ if (!testCaseId) return;
75
+
76
+ const testCase = this.testCases.get(testCaseId);
77
+ if (!testCase) return;
78
+
79
+ const pickle = this.pickles.get(testCase.pickleId);
80
+ if (!pickle) return;
81
+
82
+ const testCaseAttempt = this.eventDataCollector.getTestCaseAttempt(
83
+ testCaseFinished.testCaseStartedId,
84
+ );
85
+
86
+ const status = testCaseAttempt?.worstTestStepResult?.status || "UNKNOWN";
87
+
88
+ const info = {
89
+ name: pickle.name,
90
+ id: pickle.id,
91
+ uri: pickle.uri,
92
+ };
93
+
94
+ const line = `${timestamp} | ${status.toUpperCase()} | ${info.name} | ${info.id} | ${info.uri}\n`;
95
+
96
+ fs.appendFileSync(this.outputFile, line, "utf8");
97
+ } catch (error) {
98
+ console.error("Error in handleTestCaseFinished:", error);
99
+ }
100
+ }
101
+
102
+ handleTestRunFinished() {
103
+ if (this.workerId !== "0") {
104
+ return;
105
+ }
106
+
107
+ setTimeout(() => {
108
+ this.mergeResults();
109
+ }, 1000);
110
+ }
111
+
112
+ mergeResults() {
113
+ try {
114
+ const testStatusFile = path.join(this.outputDir, "test-status.txt");
115
+
116
+ const files = fs
117
+ .readdirSync(this.outputDir)
118
+ .filter((f) => f.startsWith("test-results-") && f.endsWith(".txt"))
119
+ .sort();
120
+
121
+ if (files.length === 0) {
122
+ console.log("No result files found to merge");
123
+ return;
124
+ }
125
+
126
+ const combined = files
127
+ .map((f) => fs.readFileSync(path.join(this.outputDir, f), "utf8"))
128
+ .join("");
129
+
130
+ fs.writeFileSync(testStatusFile, combined, "utf8");
131
+ } catch (error) {
132
+ console.error("Error merging results:", error);
133
+ }
134
+ }
135
+ }
136
+
137
+ module.exports = StatusFormatter;