artes 1.2.14 → 1.2.16
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/README.md +533 -533
- package/cucumber.config.js +171 -171
- package/docs/functionDefinitions.md +2401 -2401
- package/docs/stepDefinitions.md +352 -352
- package/executer.js +161 -161
- package/index.js +48 -48
- package/package.json +51 -54
- package/src/helper/contextManager/browserManager.js +63 -63
- package/src/helper/contextManager/requestManager.js +23 -23
- package/src/helper/controller/elementController.js +182 -182
- package/src/helper/controller/pomCollector.js +25 -25
- package/src/helper/executers/cleaner.js +19 -19
- package/src/helper/executers/exporter.js +15 -15
- package/src/helper/executers/helper.js +95 -95
- package/src/helper/executers/projectCreator.js +198 -198
- package/src/helper/executers/reportGenerator.js +58 -57
- package/src/helper/executers/testRunner.js +30 -30
- package/src/helper/executers/versionChecker.js +31 -31
- package/src/helper/imports/commons.js +56 -56
- package/src/helper/stepFunctions/APIActions.js +362 -362
- package/src/helper/stepFunctions/assertions.js +523 -523
- package/src/helper/stepFunctions/browserActions.js +22 -22
- package/src/helper/stepFunctions/elementInteractions.js +38 -38
- package/src/helper/stepFunctions/exporter.js +19 -19
- package/src/helper/stepFunctions/frameActions.js +50 -50
- package/src/helper/stepFunctions/keyboardActions.js +41 -41
- package/src/helper/stepFunctions/mouseActions.js +145 -145
- package/src/helper/stepFunctions/pageActions.js +27 -27
- package/src/hooks/context.js +15 -15
- package/src/hooks/hooks.js +257 -257
- package/src/stepDefinitions/API.steps.js +299 -299
- package/src/stepDefinitions/assertions.steps.js +861 -861
- package/src/stepDefinitions/browser.steps.js +7 -7
- package/src/stepDefinitions/frameActions.steps.js +76 -76
- package/src/stepDefinitions/keyboardActions.steps.js +226 -226
- package/src/stepDefinitions/mouseActions.steps.js +275 -275
- package/src/stepDefinitions/page.steps.js +71 -71
- package/src/stepDefinitions/random.steps.js +158 -158
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const { context, selector } = require("../imports/commons");
|
|
2
|
-
|
|
3
|
-
const page = {
|
|
4
|
-
navigateTo: async (url) => {
|
|
5
|
-
url = selector(url);
|
|
6
|
-
return await context.page.goto(url);
|
|
7
|
-
},
|
|
8
|
-
getURL: async () => {
|
|
9
|
-
return await context.page.url();
|
|
10
|
-
},
|
|
11
|
-
navigateBack: async () => {
|
|
12
|
-
return await context.page.goBack();
|
|
13
|
-
},
|
|
14
|
-
navigateForward: async () => {
|
|
15
|
-
return await context.page.goForward();
|
|
16
|
-
},
|
|
17
|
-
reload: async () => {
|
|
18
|
-
page.reload();
|
|
19
|
-
},
|
|
20
|
-
wait: async (time) => {
|
|
21
|
-
return await context.page.waitForTimeout(time);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
page,
|
|
27
|
-
};
|
|
1
|
+
const { context, selector } = require("../imports/commons");
|
|
2
|
+
|
|
3
|
+
const page = {
|
|
4
|
+
navigateTo: async (url) => {
|
|
5
|
+
url = selector(url);
|
|
6
|
+
return await context.page.goto(url);
|
|
7
|
+
},
|
|
8
|
+
getURL: async () => {
|
|
9
|
+
return await context.page.url();
|
|
10
|
+
},
|
|
11
|
+
navigateBack: async () => {
|
|
12
|
+
return await context.page.goBack();
|
|
13
|
+
},
|
|
14
|
+
navigateForward: async () => {
|
|
15
|
+
return await context.page.goForward();
|
|
16
|
+
},
|
|
17
|
+
reload: async () => {
|
|
18
|
+
page.reload();
|
|
19
|
+
},
|
|
20
|
+
wait: async (time) => {
|
|
21
|
+
return await context.page.waitForTimeout(time);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
page,
|
|
27
|
+
};
|
package/src/hooks/context.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
class Context {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.browser = undefined;
|
|
4
|
-
this.page = undefined;
|
|
5
|
-
this.request = undefined;
|
|
6
|
-
this.response = undefined;
|
|
7
|
-
this.vars = undefined;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const context = new Context();
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
context,
|
|
15
|
-
};
|
|
1
|
+
class Context {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.browser = undefined;
|
|
4
|
+
this.page = undefined;
|
|
5
|
+
this.request = undefined;
|
|
6
|
+
this.response = undefined;
|
|
7
|
+
this.vars = undefined;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const context = new Context();
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
context,
|
|
15
|
+
};
|
package/src/hooks/hooks.js
CHANGED
|
@@ -1,257 +1,257 @@
|
|
|
1
|
-
const {
|
|
2
|
-
BeforeAll,
|
|
3
|
-
Before,
|
|
4
|
-
After,
|
|
5
|
-
Status,
|
|
6
|
-
setDefaultTimeout,
|
|
7
|
-
AfterStep,
|
|
8
|
-
BeforeStep,
|
|
9
|
-
AfterAll,
|
|
10
|
-
} = require("@cucumber/cucumber");
|
|
11
|
-
const { spawnSync } = require("child_process");
|
|
12
|
-
const { invokeBrowser } = require("../helper/contextManager/browserManager");
|
|
13
|
-
const { invokeRequest } = require("../helper/contextManager/requestManager");
|
|
14
|
-
const { pomCollector } = require("../helper/controller/pomCollector");
|
|
15
|
-
const cucumberConfig = require("../../cucumber.config");
|
|
16
|
-
const { context } = require("./context");
|
|
17
|
-
const fs = require("fs");
|
|
18
|
-
const path = require("path");
|
|
19
|
-
const { moduleConfig } = require("artes/src/helper/imports/commons");
|
|
20
|
-
|
|
21
|
-
const statusDir = path.join(process.cwd(), "testsStatus");
|
|
22
|
-
const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
|
|
23
|
-
|
|
24
|
-
/* ------------------- Helpers ------------------- */
|
|
25
|
-
|
|
26
|
-
setDefaultTimeout(cucumberConfig.default.timeout);
|
|
27
|
-
|
|
28
|
-
async function attachResponse(attachFn) {
|
|
29
|
-
if (!context.response) return;
|
|
30
|
-
|
|
31
|
-
for (const [key, value] of Object.entries(context.response)) {
|
|
32
|
-
const text =
|
|
33
|
-
typeof value === "object"
|
|
34
|
-
? `${key}:\n${JSON.stringify(value, null, 2)}`
|
|
35
|
-
: `${key}:\n${value}`;
|
|
36
|
-
|
|
37
|
-
await attachFn(text, "text/plain");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function saveTestStatus(result, pickle) {
|
|
42
|
-
fs.mkdirSync(statusDir, { recursive: true });
|
|
43
|
-
fs.writeFileSync(
|
|
44
|
-
path.join(statusDir, `${result.status}-${pickle.id}.txt`),
|
|
45
|
-
"",
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const projectHooksPath = path.resolve(moduleConfig.projectPath, "tests/steps/hooks.js");
|
|
51
|
-
|
|
52
|
-
let projectHooks = {};
|
|
53
|
-
|
|
54
|
-
if (fs.existsSync(projectHooksPath)) {
|
|
55
|
-
try {
|
|
56
|
-
projectHooks = require(projectHooksPath);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
console.warn("⚠️ Failed to load project hooks.js:", err.message);
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
projectHooks = {};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* ------------------- Hooks ------------------- */
|
|
65
|
-
|
|
66
|
-
BeforeAll(async () => {
|
|
67
|
-
if (typeof projectHooks.BeforeAll === "function") {
|
|
68
|
-
await projectHooks.BeforeAll();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
pomCollector();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
Before(async function () {
|
|
75
|
-
|
|
76
|
-
context.vars = {};
|
|
77
|
-
|
|
78
|
-
const envFilePath = path.join(
|
|
79
|
-
moduleConfig.projectPath,
|
|
80
|
-
"tests",
|
|
81
|
-
"environment_variables",
|
|
82
|
-
`${cucumberConfig.env}.env.json`,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (fs.existsSync(envFilePath)) {
|
|
86
|
-
let env_vars = fs.readFileSync(envFilePath, "utf-8");
|
|
87
|
-
try {
|
|
88
|
-
env_vars = JSON.parse(env_vars);
|
|
89
|
-
context.vars = { ...context.vars, ...env_vars };
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.error("Error parsing environment variables JSON:", err);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const { browser, context: browserContext } = await invokeBrowser();
|
|
96
|
-
const requestInstance = await invokeRequest();
|
|
97
|
-
|
|
98
|
-
context.browser = browser;
|
|
99
|
-
context.browserContext = browserContext;
|
|
100
|
-
context.page = await browserContext.newPage();
|
|
101
|
-
context.request = requestInstance;
|
|
102
|
-
|
|
103
|
-
await context.page.setDefaultTimeout(cucumberConfig.default.timeout);
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
(cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) &&
|
|
107
|
-
!context.response
|
|
108
|
-
) {
|
|
109
|
-
await browserContext.tracing.start({
|
|
110
|
-
sources: true,
|
|
111
|
-
screenshots: true,
|
|
112
|
-
snapshots: true,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (typeof projectHooks.Before === "function") {
|
|
117
|
-
await projectHooks.Before();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
BeforeStep(async ({ pickleStep }) => {
|
|
122
|
-
if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
|
|
123
|
-
context.response = {};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (typeof projectHooks.BeforeStep === "function") {
|
|
127
|
-
await projectHooks.BeforeStep();
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
AfterStep(async function ({ pickleStep }) {
|
|
132
|
-
if (typeof projectHooks.AfterStep === "function") {
|
|
133
|
-
await projectHooks.AfterStep();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
|
|
137
|
-
await attachResponse(this.attach);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
After(async function ({ pickle, result }) {
|
|
142
|
-
if (typeof projectHooks.After === "function") {
|
|
143
|
-
await projectHooks.After();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const shouldReport =
|
|
147
|
-
(cucumberConfig.default.successReport ||
|
|
148
|
-
result?.status !== Status.PASSED) &&
|
|
149
|
-
!context.response;
|
|
150
|
-
|
|
151
|
-
if (shouldReport) {
|
|
152
|
-
const screenshotPath = path.join(
|
|
153
|
-
"test-results",
|
|
154
|
-
"visualReport",
|
|
155
|
-
pickle.name,
|
|
156
|
-
`${pickle.name}.png`,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const img = await context.page.screenshot({
|
|
160
|
-
path: screenshotPath,
|
|
161
|
-
type: "png",
|
|
162
|
-
});
|
|
163
|
-
await this.attach(img, {
|
|
164
|
-
mediaType: "image/png",
|
|
165
|
-
fileName: `${pickle.name.replaceAll(" ", "_")}.png`,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
saveTestStatus(result, pickle);
|
|
170
|
-
|
|
171
|
-
const tracePath = path.join(
|
|
172
|
-
moduleConfig.projectPath,
|
|
173
|
-
`./${pickle.name.replaceAll(" ", "_")}.zip`,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
(cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) &&
|
|
178
|
-
!context.response &&
|
|
179
|
-
shouldReport
|
|
180
|
-
) {
|
|
181
|
-
await context.browserContext.tracing.stop({
|
|
182
|
-
path: tracePath,
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
if (cucumberConfig.default.reportWithTrace) {
|
|
186
|
-
const trace = fs.readFileSync(tracePath);
|
|
187
|
-
|
|
188
|
-
await this.attach(trace, {
|
|
189
|
-
mediaType: "application/zip",
|
|
190
|
-
fileName: `${pickle.name.replace(/\s+/g, "_")}_trace.zip`,
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
if (!cucumberConfig.default.trace) {
|
|
194
|
-
spawnSync("npx", ["rimraf", tracePath], {
|
|
195
|
-
cwd: moduleConfig.projectPath,
|
|
196
|
-
stdio: "inherit",
|
|
197
|
-
shell: true,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
await attachResponse(this.attach);
|
|
204
|
-
|
|
205
|
-
await context.page?.close();
|
|
206
|
-
await context.browserContext?.close();
|
|
207
|
-
await context.browser?.close();
|
|
208
|
-
await context.request?.dispose();
|
|
209
|
-
|
|
210
|
-
if (shouldReport && context.page.video) {
|
|
211
|
-
const video = context.page.video();
|
|
212
|
-
if (video) {
|
|
213
|
-
const videoPath = await video.path();
|
|
214
|
-
|
|
215
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
216
|
-
|
|
217
|
-
if (fs.existsSync(videoPath)) {
|
|
218
|
-
const webmBuffer = fs.readFileSync(videoPath);
|
|
219
|
-
await this.attach(webmBuffer, {
|
|
220
|
-
mediaType: "video/webm",
|
|
221
|
-
fileName: `${pickle.name.replaceAll(" ", "_")}.webm`,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
AfterAll(async () => {
|
|
230
|
-
if (typeof projectHooks.AfterAll === "function") {
|
|
231
|
-
await projectHooks.AfterAll();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (!fs.existsSync(statusDir)) return;
|
|
235
|
-
|
|
236
|
-
const files = fs.readdirSync(statusDir);
|
|
237
|
-
const passedCount = files.filter((f) => f.split("-")[0] === "PASSED").length;
|
|
238
|
-
const totalTests = files.length;
|
|
239
|
-
const successPercentage = (passedCount / totalTests) * 100;
|
|
240
|
-
|
|
241
|
-
if (cucumberConfig.default.testPercentage !== undefined) {
|
|
242
|
-
const meetsThreshold =
|
|
243
|
-
successPercentage >= cucumberConfig.default.testPercentage;
|
|
244
|
-
|
|
245
|
-
if (meetsThreshold) {
|
|
246
|
-
console.log(
|
|
247
|
-
`✅ Tests passed required ${cucumberConfig.default.testPercentage}% success rate with ${successPercentage.toFixed(2)}%!`,
|
|
248
|
-
);
|
|
249
|
-
fs.writeFileSync(path.join(process.cwd(), "EXIT_CODE.txt"), "0");
|
|
250
|
-
} else {
|
|
251
|
-
console.log(
|
|
252
|
-
`❌ Tests failed required ${cucumberConfig.default.testPercentage}% success rate with ${successPercentage.toFixed(2)}%!`,
|
|
253
|
-
);
|
|
254
|
-
fs.writeFileSync(path.join(process.cwd(), "EXIT_CODE.txt"), "1");
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
1
|
+
const {
|
|
2
|
+
BeforeAll,
|
|
3
|
+
Before,
|
|
4
|
+
After,
|
|
5
|
+
Status,
|
|
6
|
+
setDefaultTimeout,
|
|
7
|
+
AfterStep,
|
|
8
|
+
BeforeStep,
|
|
9
|
+
AfterAll,
|
|
10
|
+
} = require("@cucumber/cucumber");
|
|
11
|
+
const { spawnSync } = require("child_process");
|
|
12
|
+
const { invokeBrowser } = require("../helper/contextManager/browserManager");
|
|
13
|
+
const { invokeRequest } = require("../helper/contextManager/requestManager");
|
|
14
|
+
const { pomCollector } = require("../helper/controller/pomCollector");
|
|
15
|
+
const cucumberConfig = require("../../cucumber.config");
|
|
16
|
+
const { context } = require("./context");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
const path = require("path");
|
|
19
|
+
const { moduleConfig } = require("artes/src/helper/imports/commons");
|
|
20
|
+
|
|
21
|
+
const statusDir = path.join(process.cwd(), "testsStatus");
|
|
22
|
+
const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
|
|
23
|
+
|
|
24
|
+
/* ------------------- Helpers ------------------- */
|
|
25
|
+
|
|
26
|
+
setDefaultTimeout(cucumberConfig.default.timeout);
|
|
27
|
+
|
|
28
|
+
async function attachResponse(attachFn) {
|
|
29
|
+
if (!context.response) return;
|
|
30
|
+
|
|
31
|
+
for (const [key, value] of Object.entries(context.response)) {
|
|
32
|
+
const text =
|
|
33
|
+
typeof value === "object"
|
|
34
|
+
? `${key}:\n${JSON.stringify(value, null, 2)}`
|
|
35
|
+
: `${key}:\n${value}`;
|
|
36
|
+
|
|
37
|
+
await attachFn(text, "text/plain");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function saveTestStatus(result, pickle) {
|
|
42
|
+
fs.mkdirSync(statusDir, { recursive: true });
|
|
43
|
+
fs.writeFileSync(
|
|
44
|
+
path.join(statusDir, `${result.status}-${pickle.id}.txt`),
|
|
45
|
+
"",
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const projectHooksPath = path.resolve(moduleConfig.projectPath, "tests/steps/hooks.js");
|
|
51
|
+
|
|
52
|
+
let projectHooks = {};
|
|
53
|
+
|
|
54
|
+
if (fs.existsSync(projectHooksPath)) {
|
|
55
|
+
try {
|
|
56
|
+
projectHooks = require(projectHooksPath);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.warn("⚠️ Failed to load project hooks.js:", err.message);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
projectHooks = {};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* ------------------- Hooks ------------------- */
|
|
65
|
+
|
|
66
|
+
BeforeAll(async () => {
|
|
67
|
+
if (typeof projectHooks.BeforeAll === "function") {
|
|
68
|
+
await projectHooks.BeforeAll();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
pomCollector();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
Before(async function () {
|
|
75
|
+
|
|
76
|
+
context.vars = {};
|
|
77
|
+
|
|
78
|
+
const envFilePath = path.join(
|
|
79
|
+
moduleConfig.projectPath,
|
|
80
|
+
"tests",
|
|
81
|
+
"environment_variables",
|
|
82
|
+
`${cucumberConfig.env}.env.json`,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (fs.existsSync(envFilePath)) {
|
|
86
|
+
let env_vars = fs.readFileSync(envFilePath, "utf-8");
|
|
87
|
+
try {
|
|
88
|
+
env_vars = JSON.parse(env_vars);
|
|
89
|
+
context.vars = { ...context.vars, ...env_vars };
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error("Error parsing environment variables JSON:", err);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { browser, context: browserContext } = await invokeBrowser();
|
|
96
|
+
const requestInstance = await invokeRequest();
|
|
97
|
+
|
|
98
|
+
context.browser = browser;
|
|
99
|
+
context.browserContext = browserContext;
|
|
100
|
+
context.page = await browserContext.newPage();
|
|
101
|
+
context.request = requestInstance;
|
|
102
|
+
|
|
103
|
+
await context.page.setDefaultTimeout(cucumberConfig.default.timeout);
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
(cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) &&
|
|
107
|
+
!context.response
|
|
108
|
+
) {
|
|
109
|
+
await browserContext.tracing.start({
|
|
110
|
+
sources: true,
|
|
111
|
+
screenshots: true,
|
|
112
|
+
snapshots: true,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (typeof projectHooks.Before === "function") {
|
|
117
|
+
await projectHooks.Before();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
BeforeStep(async ({ pickleStep }) => {
|
|
122
|
+
if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
|
|
123
|
+
context.response = {};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (typeof projectHooks.BeforeStep === "function") {
|
|
127
|
+
await projectHooks.BeforeStep();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
AfterStep(async function ({ pickleStep }) {
|
|
132
|
+
if (typeof projectHooks.AfterStep === "function") {
|
|
133
|
+
await projectHooks.AfterStep();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
|
|
137
|
+
await attachResponse(this.attach);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
After(async function ({ pickle, result }) {
|
|
142
|
+
if (typeof projectHooks.After === "function") {
|
|
143
|
+
await projectHooks.After();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const shouldReport =
|
|
147
|
+
(cucumberConfig.default.successReport ||
|
|
148
|
+
result?.status !== Status.PASSED) &&
|
|
149
|
+
!context.response;
|
|
150
|
+
|
|
151
|
+
if (shouldReport) {
|
|
152
|
+
const screenshotPath = path.join(
|
|
153
|
+
"test-results",
|
|
154
|
+
"visualReport",
|
|
155
|
+
pickle.name,
|
|
156
|
+
`${pickle.name}.png`,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const img = await context.page.screenshot({
|
|
160
|
+
path: screenshotPath,
|
|
161
|
+
type: "png",
|
|
162
|
+
});
|
|
163
|
+
await this.attach(img, {
|
|
164
|
+
mediaType: "image/png",
|
|
165
|
+
fileName: `${pickle.name.replaceAll(" ", "_")}.png`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
saveTestStatus(result, pickle);
|
|
170
|
+
|
|
171
|
+
const tracePath = path.join(
|
|
172
|
+
moduleConfig.projectPath,
|
|
173
|
+
`./${pickle.name.replaceAll(" ", "_")}.zip`,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (
|
|
177
|
+
(cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) &&
|
|
178
|
+
!context.response &&
|
|
179
|
+
shouldReport
|
|
180
|
+
) {
|
|
181
|
+
await context.browserContext.tracing.stop({
|
|
182
|
+
path: tracePath,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
if (cucumberConfig.default.reportWithTrace) {
|
|
186
|
+
const trace = fs.readFileSync(tracePath);
|
|
187
|
+
|
|
188
|
+
await this.attach(trace, {
|
|
189
|
+
mediaType: "application/zip",
|
|
190
|
+
fileName: `${pickle.name.replace(/\s+/g, "_")}_trace.zip`,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (!cucumberConfig.default.trace) {
|
|
194
|
+
spawnSync("npx", ["rimraf", tracePath], {
|
|
195
|
+
cwd: moduleConfig.projectPath,
|
|
196
|
+
stdio: "inherit",
|
|
197
|
+
shell: true,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
await attachResponse(this.attach);
|
|
204
|
+
|
|
205
|
+
await context.page?.close();
|
|
206
|
+
await context.browserContext?.close();
|
|
207
|
+
await context.browser?.close();
|
|
208
|
+
await context.request?.dispose();
|
|
209
|
+
|
|
210
|
+
if (shouldReport && context.page.video) {
|
|
211
|
+
const video = context.page.video();
|
|
212
|
+
if (video) {
|
|
213
|
+
const videoPath = await video.path();
|
|
214
|
+
|
|
215
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
216
|
+
|
|
217
|
+
if (fs.existsSync(videoPath)) {
|
|
218
|
+
const webmBuffer = fs.readFileSync(videoPath);
|
|
219
|
+
await this.attach(webmBuffer, {
|
|
220
|
+
mediaType: "video/webm",
|
|
221
|
+
fileName: `${pickle.name.replaceAll(" ", "_")}.webm`,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
AfterAll(async () => {
|
|
230
|
+
if (typeof projectHooks.AfterAll === "function") {
|
|
231
|
+
await projectHooks.AfterAll();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (!fs.existsSync(statusDir)) return;
|
|
235
|
+
|
|
236
|
+
const files = fs.readdirSync(statusDir);
|
|
237
|
+
const passedCount = files.filter((f) => f.split("-")[0] === "PASSED").length;
|
|
238
|
+
const totalTests = files.length;
|
|
239
|
+
const successPercentage = (passedCount / totalTests) * 100;
|
|
240
|
+
|
|
241
|
+
if (cucumberConfig.default.testPercentage !== undefined) {
|
|
242
|
+
const meetsThreshold =
|
|
243
|
+
successPercentage >= cucumberConfig.default.testPercentage;
|
|
244
|
+
|
|
245
|
+
if (meetsThreshold) {
|
|
246
|
+
console.log(
|
|
247
|
+
`✅ Tests passed required ${cucumberConfig.default.testPercentage}% success rate with ${successPercentage.toFixed(2)}%!`,
|
|
248
|
+
);
|
|
249
|
+
fs.writeFileSync(path.join(process.cwd(), "EXIT_CODE.txt"), "0");
|
|
250
|
+
} else {
|
|
251
|
+
console.log(
|
|
252
|
+
`❌ Tests failed required ${cucumberConfig.default.testPercentage}% success rate with ${successPercentage.toFixed(2)}%!`,
|
|
253
|
+
);
|
|
254
|
+
fs.writeFileSync(path.join(process.cwd(), "EXIT_CODE.txt"), "1");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|