artes 1.7.20 → 1.7.21

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 (49) hide show
  1. package/README.md +781 -781
  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 -435
  8. package/executer.js +266 -266
  9. package/index.js +51 -51
  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 +230 -230
  14. package/src/helper/controller/findDuplicateTestNames.js +69 -69
  15. package/src/helper/controller/getEnvInfo.js +97 -97
  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 +511 -511
  19. package/src/helper/controller/screenComparer.js +96 -96
  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 -193
  25. package/src/helper/executers/projectCreator.js +226 -226
  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 +69 -69
  30. package/src/helper/stepFunctions/APIActions.js +582 -582
  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 +18 -18
  40. package/src/hooks/hooks.js +287 -287
  41. package/src/stepDefinitions/API.steps.js +404 -404
  42. package/src/stepDefinitions/assertions.steps.js +1358 -1349
  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 +374 -374
  47. package/src/stepDefinitions/page.steps.js +71 -71
  48. package/src/stepDefinitions/random.steps.js +199 -199
  49. package/src/stepDefinitions/report.steps.js +5 -5
@@ -1,97 +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, 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
-
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
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;