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,279 +1,287 @@
1
- const {
2
- BeforeAll,
3
- Before,
4
- After,
5
- Status,
6
- setDefaultTimeout,
7
- AfterStep,
8
- BeforeStep,
9
- AfterAll,
10
- } = require("@cucumber/cucumber");
11
- const { invokeBrowser } = require("../helper/contextManager/browserManager");
12
- const { invokeRequest } = require("../helper/contextManager/requestManager");
13
- const { pomCollector } = require("../helper/controller/pomCollector");
14
- const cucumberConfig = require("../../cucumber.config");
15
- const { context } = require("./context");
16
- const fs = require("fs");
17
- const path = require("path");
18
- const { moduleConfig, saveVar } = require("artes/src/helper/imports/commons");
19
- require("allure-cucumberjs");
20
- const allure = require("allure-js-commons");
21
- const ffprobe = require("ffprobe-static");
22
- const ffmpegPath = require("ffmpeg-static");
23
- const { execSync } = require("child_process");
24
- const { attachAiBugReport } = require("artes/src/helper/controller/aiBugReporter");
25
-
26
-
27
- const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
28
-
29
- /* ------------------- Helpers ------------------- */
30
-
31
- setDefaultTimeout(cucumberConfig.default.timeout);
32
-
33
- async function attachResponse(attachFn) {
34
- if (!context.response) return;
35
-
36
- for (const [key, value] of Object.entries(context.response)) {
37
- const text =
38
- typeof value === "object"
39
- ? `${key}:\n${JSON.stringify(value, null, 2)}`
40
- : `${key}:\n${value}`;
41
-
42
- await attachFn(key, text, "application/json");
43
- }
44
- }
45
-
46
- const projectHooksPath = path.resolve(
47
- moduleConfig.projectPath,
48
- "tests/steps/hooks.js",
49
- );
50
-
51
- let projectHooks = {};
52
-
53
- if (fs.existsSync(projectHooksPath)) {
54
- try {
55
- projectHooks = require(projectHooksPath);
56
- } catch (err) {
57
- console.warn("⚠️ Failed to load project hooks.js:", err.message);
58
- }
59
- } else {
60
- projectHooks = {};
61
- }
62
-
63
- /* ------------------- Hooks ------------------- */
64
-
65
- BeforeAll(async () => {
66
- if (typeof projectHooks.BeforeAll === "function") {
67
- await projectHooks.BeforeAll();
68
- }
69
-
70
- pomCollector();
71
- });
72
-
73
- Before(async function ({ pickle }) {
74
- context.vars = {};
75
-
76
- const vars = await cucumberConfig.variables;
77
-
78
- if (vars && typeof vars === "object") {
79
- for (let [key, value] of Object.entries(vars)) {
80
- saveVar(value, key);
81
- }
82
- }
83
-
84
- const envFilePath = path.join(
85
- moduleConfig.projectPath,
86
- "tests",
87
- "environment_variables",
88
- `${cucumberConfig.env}.env.json`,
89
- );
90
-
91
- if (fs.existsSync(envFilePath)) {
92
- let env_vars = fs.readFileSync(envFilePath, "utf-8");
93
- try {
94
- env_vars = JSON.parse(env_vars);
95
- context.vars = { ...context.vars, ...env_vars };
96
- } catch (err) {
97
- console.error("Error parsing environment variables JSON:", err);
98
- }
99
- }
100
-
101
- const { browser, context: browserContext } = await invokeBrowser();
102
- const requestInstance = await invokeRequest();
103
-
104
- context.browser = browser;
105
- context.browserContext = browserContext;
106
- context.page = await browserContext.newPage();
107
- context.request = requestInstance;
108
-
109
- const dimensions = await context.page.evaluate(() => {
110
- return {
111
- width: window.innerWidth,
112
- height: window.innerHeight,
113
- };
114
- });
115
-
116
- fs.writeFileSync(
117
- path.join(moduleConfig.modulePath, "browser-info.json"),
118
- JSON.stringify({
119
- BROWSER_WIDTH: dimensions.width,
120
- BROWSER_HEIGHT: dimensions.height,
121
- BROWSER_VERSION: browser.version(),
122
- }),
123
- );
124
-
125
- await context.page.setDefaultTimeout(cucumberConfig.default.timeout);
126
-
127
- if (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) {
128
- await browserContext.tracing.start({
129
- title: pickle.name,
130
- sources: true,
131
- screenshots: true,
132
- snapshots: true,
133
- });
134
- }
135
-
136
- if (typeof projectHooks.Before === "function") {
137
- await projectHooks.Before();
138
- }
139
- });
140
-
141
- BeforeStep(async ({ pickleStep }) => {
142
- if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
143
- context.response = {};
144
- }
145
-
146
- if (typeof projectHooks.BeforeStep === "function") {
147
- await projectHooks.BeforeStep();
148
- }
149
- });
150
-
151
- AfterStep(async function ({ pickleStep }) {
152
- if (typeof projectHooks.AfterStep === "function") {
153
- await projectHooks.AfterStep();
154
- }
155
-
156
- if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
157
- await attachResponse(allure.attachment);
158
- }
159
- });
160
-
161
- After(async function ({ result, pickle }) {
162
- const shouldReport =
163
- cucumberConfig.default.successReport || result?.status !== Status.PASSED;
164
-
165
- await attachResponse(allure.attachment);
166
-
167
- if (shouldReport && cucumberConfig.ai.ai === "true") {
168
- await attachAiBugReport({
169
- result,
170
- pickle,
171
- response: context.response,
172
- language: cucumberConfig.ai.language,
173
- url: cucumberConfig.ai.url,
174
- aiModel: cucumberConfig.ai.model,
175
- aiKey: cucumberConfig.ai.key,
176
- maxReports: cucumberConfig.ai.maxReports,
177
- maxTokens: cucumberConfig.ai.maxTokens
178
- });
179
- }
180
-
181
-
182
- if (typeof projectHooks.After === "function") {
183
- await projectHooks.After();
184
- }
185
-
186
-
187
- context.response = await {};
188
-
189
- Object.keys(context.vars).length > 0 &&
190
- allure.attachment(
191
- "Variables",
192
- JSON.stringify(context.vars, null, 2),
193
- "application/json",
194
- );
195
-
196
-
197
- if (shouldReport & (context.page.url() !== "about:blank")) {
198
- const screenshotBuffer = await context.page.screenshot({ type: "png" });
199
-
200
- await allure.attachment("Screenshot", screenshotBuffer, "image/png");
201
- }
202
-
203
- if (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) {
204
- var tracePath = path.join(
205
- moduleConfig.projectPath,
206
- `./traces/${pickle.name.replaceAll(" ", "_")}-${pickle.id}.zip`,
207
- );
208
- }
209
-
210
- if (
211
- (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) &&
212
- shouldReport &&
213
- context.page.url() !== "about:blank"
214
- ) {
215
- await context.browserContext.tracing.stop({
216
- path: tracePath,
217
- });
218
-
219
- if (cucumberConfig.default.reportWithTrace) {
220
- await allure.attachTrace("Trace", tracePath);
221
- }
222
- }
223
-
224
- await context.page?.close();
225
- await context.browserContext?.close();
226
- await context.browser?.close();
227
- await context.request?.dispose();
228
-
229
- if (
230
- shouldReport &&
231
- context.page.video &&
232
- context.page.url() !== "about:blank"
233
- ) {
234
- const video = context.page.video();
235
-
236
- if (video) {
237
- const videoPath = await video.path();
238
-
239
- await new Promise((resolve) => setTimeout(resolve, 1000));
240
-
241
- if (fs.existsSync(videoPath)) {
242
- const trimmedPath = videoPath.replace(".webm", "-trimmed.webm");
243
-
244
- const isTimeoutError = result.message?.includes(
245
- "Error: function timed out, ensure the promise resolves within",
246
- );
247
-
248
- if (isTimeoutError) {
249
- const duration = parseFloat(
250
- execSync(
251
- `"${ffprobe.path}" -v error -show_entries format=duration -of csv=p=0 "${videoPath}"`,
252
- )
253
- .toString()
254
- .trim(),
255
- );
256
-
257
- const timeoutSeconds = cucumberConfig.default.timeout / 1000;
258
- const newDuration = Math.max(duration - timeoutSeconds + 3, 1);
259
-
260
- execSync(
261
- `"${ffmpegPath}" -loglevel quiet -i "${videoPath}" -t ${newDuration} -c copy "${trimmedPath}" -y`,
262
- );
263
-
264
- const webmBuffer = fs.readFileSync(trimmedPath);
265
- await allure.attachment("Screenrecord", webmBuffer, "video/webm");
266
- } else {
267
- const webmBuffer = fs.readFileSync(videoPath);
268
- await allure.attachment("Screenrecord", webmBuffer, "video/webm");
269
- }
270
- }
271
- }
272
- }
273
- });
274
-
275
- AfterAll(async () => {
276
- if (typeof projectHooks.AfterAll === "function") {
277
- await projectHooks.AfterAll();
278
- }
279
- });
1
+ const {
2
+ BeforeAll,
3
+ Before,
4
+ After,
5
+ Status,
6
+ setDefaultTimeout,
7
+ AfterStep,
8
+ BeforeStep,
9
+ AfterAll,
10
+ } = require("@cucumber/cucumber");
11
+ const { invokeBrowser } = require("../helper/contextManager/browserManager");
12
+ const { invokeRequest } = require("../helper/contextManager/requestManager");
13
+ const { pomCollector } = require("../helper/controller/pomCollector");
14
+ const cucumberConfig = require("../../cucumber.config");
15
+ const { context } = require("./context");
16
+ const fs = require("fs");
17
+ const path = require("path");
18
+ const { moduleConfig, saveVar } = require("artes/src/helper/imports/commons");
19
+ require("allure-cucumberjs");
20
+ const allure = require("allure-js-commons");
21
+ const ffprobe = require("ffprobe-static");
22
+ const ffmpegPath = require("ffmpeg-static");
23
+ const { execSync } = require("child_process");
24
+ const { attachAiBugReport } = require("artes/src/helper/controller/aiBugReporter");
25
+
26
+
27
+ const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
28
+
29
+ /* ------------------- Helpers ------------------- */
30
+
31
+ setDefaultTimeout(cucumberConfig.default.timeout);
32
+
33
+ async function attachResponse(attachFn) {
34
+ if (!context.response) return;
35
+
36
+ for (const [key, value] of Object.entries(context.response)) {
37
+ const text =
38
+ typeof value === "object"
39
+ ? `${key}:\n${JSON.stringify(value, null, 2)}`
40
+ : `${key}:\n${value}`;
41
+
42
+ await attachFn(key, text, "application/json");
43
+ }
44
+ }
45
+
46
+ const projectHooksPath = path.resolve(
47
+ moduleConfig.projectPath,
48
+ "tests/steps/hooks.js",
49
+ );
50
+
51
+ let projectHooks = {};
52
+
53
+ if (fs.existsSync(projectHooksPath)) {
54
+ try {
55
+ projectHooks = require(projectHooksPath);
56
+ } catch (err) {
57
+ console.warn("⚠️ Failed to load project hooks.js:", err.message);
58
+ }
59
+ } else {
60
+ projectHooks = {};
61
+ }
62
+
63
+ /* ------------------- Hooks ------------------- */
64
+
65
+ BeforeAll(async () => {
66
+ if (typeof projectHooks.BeforeAll === "function") {
67
+ await projectHooks.BeforeAll();
68
+ }
69
+
70
+ pomCollector();
71
+ });
72
+
73
+ Before(async function ({ pickle }) {
74
+ context.vars = {};
75
+
76
+ const vars = await cucumberConfig.variables;
77
+
78
+ if (vars && typeof vars === "object") {
79
+ for (let [key, value] of Object.entries(vars)) {
80
+ saveVar(value, key);
81
+ }
82
+ }
83
+
84
+ const envFilePath = path.join(
85
+ moduleConfig.projectPath,
86
+ "tests",
87
+ "environment_variables",
88
+ `${cucumberConfig.env}.env.json`,
89
+ );
90
+
91
+ if (fs.existsSync(envFilePath)) {
92
+ let env_vars = fs.readFileSync(envFilePath, "utf-8");
93
+ try {
94
+ env_vars = JSON.parse(env_vars);
95
+ context.vars = { ...context.vars, ...env_vars };
96
+ } catch (err) {
97
+ console.error("Error parsing environment variables JSON:", err);
98
+ }
99
+ }
100
+
101
+ const { browser, context: browserContext } = await invokeBrowser();
102
+ const requestInstance = await invokeRequest();
103
+
104
+ context.browser = browser;
105
+ context.browserContext = browserContext;
106
+ context.page = await browserContext.newPage();
107
+ context.request = requestInstance;
108
+ context.pickle = pickle;
109
+
110
+ const dimensions = await context.page.evaluate(() => {
111
+ return {
112
+ width: window.innerWidth,
113
+ height: window.innerHeight,
114
+ };
115
+ });
116
+
117
+ fs.writeFileSync(
118
+ path.join(moduleConfig.modulePath, "browser-info.json"),
119
+ JSON.stringify({
120
+ BROWSER_WIDTH: dimensions.width,
121
+ BROWSER_HEIGHT: dimensions.height,
122
+ BROWSER_VERSION: browser.version(),
123
+ }),
124
+ );
125
+
126
+ await context.page.setDefaultTimeout(cucumberConfig.default.timeout);
127
+
128
+ if (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) {
129
+ await browserContext.tracing.start({
130
+ title: pickle.name,
131
+ sources: true,
132
+ screenshots: true,
133
+ snapshots: true,
134
+ });
135
+ }
136
+
137
+ if (typeof projectHooks.Before === "function") {
138
+ await projectHooks.Before();
139
+ }
140
+ });
141
+
142
+ BeforeStep(async ({ pickleStep }) => {
143
+ context.step = pickleStep;
144
+
145
+ if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
146
+ context.response = {};
147
+ }
148
+
149
+ if (typeof projectHooks.BeforeStep === "function") {
150
+ await projectHooks.BeforeStep();
151
+ }
152
+ });
153
+
154
+ AfterStep(async function ({ pickleStep }) {
155
+ context.step = pickleStep;
156
+
157
+ if (typeof projectHooks.AfterStep === "function") {
158
+ await projectHooks.AfterStep();
159
+ }
160
+
161
+ if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
162
+ await attachResponse(allure.attachment);
163
+ }
164
+ });
165
+
166
+ After(async function ({ result, pickle }) {
167
+ context.pickle = pickle
168
+ context.pickleResult = result
169
+
170
+ const shouldReport =
171
+ cucumberConfig.default.successReport || result?.status !== Status.PASSED;
172
+
173
+ await attachResponse(allure.attachment);
174
+
175
+ if (shouldReport && cucumberConfig.ai.ai === "true") {
176
+ await attachAiBugReport({
177
+ result,
178
+ pickle,
179
+ response: context.response,
180
+ language: cucumberConfig.ai.language,
181
+ url: cucumberConfig.ai.url,
182
+ aiModel: cucumberConfig.ai.model,
183
+ aiKey: cucumberConfig.ai.key,
184
+ maxReports: cucumberConfig.ai.maxReports,
185
+ maxTokens: cucumberConfig.ai.maxTokens
186
+ });
187
+ }
188
+
189
+
190
+ if (typeof projectHooks.After === "function") {
191
+ await projectHooks.After();
192
+ }
193
+
194
+
195
+ context.response = await {};
196
+
197
+ Object.keys(context.vars).length > 0 &&
198
+ allure.attachment(
199
+ "Variables",
200
+ JSON.stringify(context.vars, null, 2),
201
+ "application/json",
202
+ );
203
+
204
+
205
+ if (shouldReport & (context.page.url() !== "about:blank")) {
206
+ const screenshotBuffer = await context.page.screenshot({ type: "png" });
207
+
208
+ await allure.attachment("Screenshot", screenshotBuffer, "image/png");
209
+ }
210
+
211
+ if (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) {
212
+ var tracePath = path.join(
213
+ moduleConfig.projectPath,
214
+ `./traces/${pickle.name.replaceAll(" ", "_")}-${pickle.id}.zip`,
215
+ );
216
+ }
217
+
218
+ if (
219
+ (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) &&
220
+ shouldReport &&
221
+ context.page.url() !== "about:blank"
222
+ ) {
223
+ await context.browserContext.tracing.stop({
224
+ path: tracePath,
225
+ });
226
+
227
+ if (cucumberConfig.default.reportWithTrace) {
228
+ await allure.attachTrace("Trace", tracePath);
229
+ }
230
+ }
231
+
232
+ await context.page?.close();
233
+ await context.browserContext?.close();
234
+ await context.browser?.close();
235
+ await context.request?.dispose();
236
+
237
+ if (
238
+ shouldReport &&
239
+ context.page.video &&
240
+ context.page.url() !== "about:blank"
241
+ ) {
242
+ const video = context.page.video();
243
+
244
+ if (video) {
245
+ const videoPath = await video.path();
246
+
247
+ await new Promise((resolve) => setTimeout(resolve, 1000));
248
+
249
+ if (fs.existsSync(videoPath)) {
250
+ const trimmedPath = videoPath.replace(".webm", "-trimmed.webm");
251
+
252
+ const isTimeoutError = result.message?.includes(
253
+ "Error: function timed out, ensure the promise resolves within",
254
+ );
255
+
256
+ if (isTimeoutError) {
257
+ const duration = parseFloat(
258
+ execSync(
259
+ `"${ffprobe.path}" -v error -show_entries format=duration -of csv=p=0 "${videoPath}"`,
260
+ )
261
+ .toString()
262
+ .trim(),
263
+ );
264
+
265
+ const timeoutSeconds = cucumberConfig.default.timeout / 1000;
266
+ const newDuration = Math.max(duration - timeoutSeconds + 3, 1);
267
+
268
+ execSync(
269
+ `"${ffmpegPath}" -loglevel quiet -i "${videoPath}" -t ${newDuration} -c copy "${trimmedPath}" -y`,
270
+ );
271
+
272
+ const webmBuffer = fs.readFileSync(trimmedPath);
273
+ await allure.attachment("Screenrecord", webmBuffer, "video/webm");
274
+ } else {
275
+ const webmBuffer = fs.readFileSync(videoPath);
276
+ await allure.attachment("Screenrecord", webmBuffer, "video/webm");
277
+ }
278
+ }
279
+ }
280
+ }
281
+ });
282
+
283
+ AfterAll(async () => {
284
+ if (typeof projectHooks.AfterAll === "function") {
285
+ await projectHooks.AfterAll();
286
+ }
287
+ });