artes 1.2.26 → 1.2.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.2.26",
3
+ "version": "1.2.28",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,9 +23,9 @@
23
23
  "@faker-js/faker": "9.8.0",
24
24
  "@types/node": "22.9.0",
25
25
  "ajv": "8.17.1",
26
- "allure-commandline": "2.30.0",
27
- "allure-cucumberjs": "3.0.5",
28
- "allure-js-commons": "3.0.5",
26
+ "allure-commandline": "2.36.0",
27
+ "allure-cucumberjs": "3.4.5",
28
+ "allure-js-commons": "3.4.5",
29
29
  "archiver": "^7.0.1",
30
30
  "dayjs": "1.11.13",
31
31
  "deasync": "^0.1.31",
@@ -12,7 +12,7 @@ function addElements(newElements) {
12
12
  // return locatorCount ==0 ? false : true;
13
13
  // }
14
14
 
15
- function selectorSeperator(element) {
15
+ function selectorSeparator(element) {
16
16
  if (typeof element !== "string") return element;
17
17
 
18
18
  const selector = element?.split("=");
@@ -41,7 +41,7 @@ function selectorSeperator(element) {
41
41
  function getSelector(element) {
42
42
  const selector =
43
43
  elements?.[element]?.selector || elements?.[element] || element;
44
- return resolveVariable(selectorSeperator(selector));
44
+ return resolveVariable(selectorSeparator(selector));
45
45
  }
46
46
 
47
47
  function getElement(element) {
@@ -1,25 +1,53 @@
1
1
  const { addElements } = require("./elementController");
2
2
  const cucumberConfig = require("../../../cucumber.config");
3
3
  const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ const duplicateWarnings = [];
7
+ const keyRegistry = {};
4
8
 
5
9
  function pomCollector() {
6
- if (fs.existsSync(cucumberConfig.default.pomPath)) {
7
- fs.readdir(`${cucumberConfig.default.pomPath}`, (err, files) => {
8
- files.forEach((file) => {
9
- fs.readFile(
10
- `${cucumberConfig.default.pomPath}/${file}`,
11
- "utf-8",
12
- (err, content) => {
13
- try {
14
- addElements(JSON.parse(content));
15
- } catch (error) {
16
- console.log(`Error parsing POM file ${file}:`, error.message);
17
- }
18
- },
10
+ const pomPath = cucumberConfig.default.pomPath;
11
+
12
+ if (!fs.existsSync(pomPath)) return;
13
+
14
+ fs.readdirSync(pomPath).forEach((file) => {
15
+ const filePath = path.join(pomPath, file);
16
+
17
+ let parsed;
18
+ try {
19
+ parsed = JSON.parse(fs.readFileSync(filePath, "utf-8"));
20
+ } catch (error) {
21
+ console.log(`Error parsing POM file ${file}: ${error.message}`);
22
+ return;
23
+ }
24
+
25
+ Object.keys(parsed).forEach((key) => {
26
+ if (keyRegistry[key]) {
27
+ duplicateWarnings.push(
28
+ `${key} in ${file} has the same key with ${key} in ${keyRegistry[key]}`
19
29
  );
20
- });
30
+ } else {
31
+ keyRegistry[key] = file;
32
+ }
21
33
  });
22
- }
34
+
35
+ addElements(parsed);
36
+ });
37
+ }
38
+
39
+ function logPomWarnings() {
40
+ if (duplicateWarnings.length === 0) return;
41
+
42
+ console.warn(
43
+ "\n\x1b[33m[WARNING] POM DUPLICATE KEY WARNINGS: This may break your tests or cause flaky behavior."
44
+ );
45
+
46
+ duplicateWarnings.forEach((warning) => {
47
+ console.warn(`- ${warning}`);
48
+ });
49
+
50
+ console.log("\x1b[0m")
23
51
  }
24
52
 
25
- module.exports = { pomCollector };
53
+ module.exports = { pomCollector, logPomWarnings };
@@ -11,12 +11,14 @@ const {
11
11
  const { spawnSync } = require("child_process");
12
12
  const { invokeBrowser } = require("../helper/contextManager/browserManager");
13
13
  const { invokeRequest } = require("../helper/contextManager/requestManager");
14
- const { pomCollector } = require("../helper/controller/pomCollector");
14
+ const { pomCollector, logPomWarnings } = require("../helper/controller/pomCollector");
15
15
  const cucumberConfig = require("../../cucumber.config");
16
16
  const { context } = require("./context");
17
17
  const fs = require("fs");
18
18
  const path = require("path");
19
19
  const { moduleConfig } = require("artes/src/helper/imports/commons");
20
+ require("allure-cucumberjs");
21
+ const allure = require("allure-js-commons");
20
22
 
21
23
  const statusDir = path.join(process.cwd(), "testsStatus");
22
24
  const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
@@ -34,7 +36,7 @@ async function attachResponse(attachFn) {
34
36
  ? `${key}:\n${JSON.stringify(value, null, 2)}`
35
37
  : `${key}:\n${value}`;
36
38
 
37
- await attachFn(text, "text/plain");
39
+ await attachFn(key, text, "text/plain");
38
40
  }
39
41
  }
40
42
 
@@ -132,7 +134,7 @@ AfterStep(async function ({ pickleStep }) {
132
134
  }
133
135
 
134
136
  if (HTTP_METHODS.some((method) => pickleStep.text.includes(method))) {
135
- await attachResponse(this.attach);
137
+ await attachResponse(allure.attachment);
136
138
  }
137
139
  });
138
140
 
@@ -145,24 +147,19 @@ After(async function ({ pickle, result }) {
145
147
  cucumberConfig.default.successReport || result?.status !== Status.PASSED;
146
148
 
147
149
  if (shouldReport & (context.page.url() !== "about:blank")) {
148
- const screenshotPath = path.join(
149
- "test-results",
150
- "visualReport",
151
- pickle.name,
152
- `${pickle.name}.png`,
150
+
151
+ const screenshotBuffer = await context.page.screenshot({ type: "png" });
152
+
153
+ await allure.attachment(
154
+ pickle.name.replaceAll(" ", "_"),
155
+ screenshotBuffer,
156
+ "image/png"
153
157
  );
154
158
 
155
- const img = await context.page.screenshot({
156
- path: screenshotPath,
157
- type: "png",
158
- });
159
- await this.attach(img, {
160
- mediaType: "image/png",
161
- fileName: `${pickle.name.replaceAll(" ", "_")}.png`,
162
- });
163
159
  }
164
160
 
165
161
  saveTestStatus(result, pickle);
162
+
166
163
  if (cucumberConfig.default.reportWithTrace || cucumberConfig.default.trace) {
167
164
  var tracePath = path.join(
168
165
  moduleConfig.projectPath,
@@ -175,17 +172,14 @@ After(async function ({ pickle, result }) {
175
172
  shouldReport &&
176
173
  context.page.url() !== "about:blank"
177
174
  ) {
178
- await context.browserContext.tracing.stop({
175
+
176
+ await context.browserContext.tracing.stop({
179
177
  path: tracePath,
180
178
  });
181
179
 
182
180
  if (cucumberConfig.default.reportWithTrace) {
183
- const trace = fs.readFileSync(tracePath);
184
181
 
185
- await this.attach(trace, {
186
- mediaType: "application/zip",
187
- fileName: `${pickle.name.replace(/\s+/g, "_")}_trace.zip`,
188
- });
182
+ await allure.attachTrace("Trace", tracePath);
189
183
 
190
184
  if (!cucumberConfig.default.trace) {
191
185
  spawnSync(
@@ -202,11 +196,13 @@ After(async function ({ pickle, result }) {
202
196
  },
203
197
  );
204
198
  }
199
+
205
200
  }
206
201
  }
207
202
 
208
- await attachResponse(this.attach);
209
-
203
+ await attachResponse(allure.attachment);
204
+ context.response = await {}
205
+
210
206
  await context.page?.close();
211
207
  await context.browserContext?.close();
212
208
  await context.browser?.close();
@@ -223,15 +219,13 @@ After(async function ({ pickle, result }) {
223
219
 
224
220
  await new Promise((resolve) => setTimeout(resolve, 1000));
225
221
 
226
- if (fs.existsSync(videoPath)) {
222
+ if (fs.existsSync(videoPath)) {
227
223
  const webmBuffer = fs.readFileSync(videoPath);
228
- await this.attach(webmBuffer, {
229
- mediaType: "video/webm",
230
- fileName: `${pickle.name.replaceAll(" ", "_")}.webm`,
231
- });
224
+ await allure.attachment("Screenrecord", webmBuffer, "video/webm");
232
225
  }
233
226
  }
234
227
  }
228
+
235
229
  });
236
230
 
237
231
  AfterAll(async () => {
@@ -256,9 +250,8 @@ AfterAll(async () => {
256
250
  });
257
251
  }
258
252
 
259
- if (cucumberConfig.default.testPercentage !== undefined) {
260
- const meetsThreshold =
261
- successPercentage >= cucumberConfig.default.testPercentage;
253
+ if (cucumberConfig.default.testPercentage>0) {
254
+ const meetsThreshold = successPercentage >= cucumberConfig.default.testPercentage;
262
255
 
263
256
  if (meetsThreshold) {
264
257
  console.log(