artes 1.4.7 → 1.4.8

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/executer.js CHANGED
@@ -445,12 +445,11 @@ if (fs.existsSync(path.join(process.cwd(), "node_modules", "artes" , "@rerun.txt
445
445
  artesConfig.report
446
446
  ){
447
447
  const executor = getExecutor();
448
-
449
- fs.writeFileSync(
450
- path.join(process.cwd(), "node_modules", "artes",'allure-result',"executor.json"),
451
- JSON.stringify(executor, null, 2)
452
- );
453
- generateReport();
448
+ fs.writeFileSync(
449
+ path.join(process.cwd(), "node_modules", "artes",'allure-result',"executor.json"),
450
+ JSON.stringify(executor, null, 2)
451
+ );
452
+ generateReport();
454
453
  }
455
454
 
456
455
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -94,12 +94,13 @@ function getElement(element) {
94
94
  return locator;
95
95
  }
96
96
 
97
- function extractVarsFromResponse(responseBody, vars, customVarName) {
97
+ function extractVarsFromResponse(responseBody, vars, customVarNames) {
98
+
98
99
  function getValueByPath(obj, path) {
99
100
  const keys = path.split(".");
100
101
  let current = obj;
101
102
 
102
- if (typeof obj == "string") return obj;
103
+ if (typeof obj === "string") return obj;
103
104
 
104
105
  for (const key of keys) {
105
106
  if (current && typeof current === "object" && key in current) {
@@ -112,11 +113,28 @@ function extractVarsFromResponse(responseBody, vars, customVarName) {
112
113
  return current;
113
114
  }
114
115
 
115
- vars.split(",").forEach((v) => {
116
- const path = v.trim();
116
+
117
+ const varPaths = vars.split(",").map(v => v.trim());
118
+ let customNames = [];
119
+
120
+ if (typeof customVarNames === "string") {
121
+ customNames = customVarNames.split(",").map(n => n.trim());
122
+ } else if (Array.isArray(customVarNames)) {
123
+ customNames = customVarNames;
124
+ } else {
125
+ throw new Error("customVarNames must be a string or an array");
126
+ }
127
+
128
+
129
+ if (customNames.length !== varPaths.length) {
130
+ customNames = varPaths;
131
+ }
132
+
133
+
134
+ varPaths.forEach((path, index) => {
117
135
  const value = getValueByPath(responseBody, path);
118
136
  if (value !== undefined) {
119
- saveVar(value, customVarName, path);
137
+ saveVar(value, customNames[index], path);
120
138
  }
121
139
  });
122
140
  }
@@ -136,43 +154,43 @@ function saveVar(value, customName, path) {
136
154
  }
137
155
  }
138
156
 
139
- function resolveVariable(template) {
140
- if (typeof template === "string") {
141
- return template.replace(/{{\s*(\w+)\s*}}/g, (_, varName) => {
142
- let value = context.vars[varName];
143
-
144
- if (value !== undefined) {
145
- if (typeof value !== "string") {
146
- try {
147
- value = JSON.stringify(value);
148
- } catch {
149
- value = String(value);
150
- }
151
- }
152
-
153
- return value
154
- .replace(/\n/g, "\\n")
155
- .replace(/\r/g, "\\r")
156
- .replace(/\t/g, "\\t");
157
+ function extractVarsFromResponse(responseBody, vars, customVarName) {
158
+ function getValueByPath(obj, path) {
159
+ const keys = path.split(".");
160
+ let current = obj;
161
+
162
+ if (typeof obj == "string") return obj;
163
+
164
+ for (const key of keys) {
165
+ if (current && typeof current === "object" && key in current) {
166
+ current = current[key];
167
+ } else {
168
+ return undefined;
157
169
  }
170
+ }
158
171
 
159
- return `{{${varName}}}`;
160
- });
172
+ return current;
161
173
  }
162
174
 
163
- if (Array.isArray(template)) {
164
- return template.map((item) => resolveVariable(item));
165
- }
175
+ const varList = vars.split(",").map((v) => v.trim());
176
+ const customVarNames = customVarName
177
+ ? customVarName.split(",").map((n) => n.trim())
178
+ : [];
166
179
 
167
- if (template && typeof template === "object") {
168
- const result = {};
169
- for (const key in template) {
170
- result[key] = resolveVariable(template[key]);
180
+ varList.forEach((path, index) => {
181
+ const value = getValueByPath(responseBody, path);
182
+ if (value !== undefined) {
183
+ let resolvedName;
184
+ if (customVarNames.length === 0) {
185
+ resolvedName = undefined;
186
+ } else if (customVarNames.length === 1) {
187
+ resolvedName = customVarNames[0];
188
+ } else {
189
+ resolvedName = customVarNames[index] ?? path;
190
+ }
191
+ saveVar(value, resolvedName, path);
171
192
  }
172
- return result;
173
- }
174
-
175
- return template;
193
+ });
176
194
  }
177
195
 
178
196
  module.exports = {
@@ -21,7 +21,6 @@ const { moduleConfig, saveVar } = require("artes/src/helper/imports/commons");
21
21
  require("allure-cucumberjs");
22
22
  const allure = require("allure-js-commons");
23
23
 
24
- const statusDir = path.join(process.cwd(), "testsStatus");
25
24
  const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
26
25
 
27
26
  /* ------------------- Helpers ------------------- */
@@ -58,6 +57,23 @@ if (fs.existsSync(projectHooksPath)) {
58
57
  projectHooks = {};
59
58
  }
60
59
 
60
+ // const mergedParams = {};
61
+
62
+ // function mergeObjects(target, source) {
63
+ // for (const key in source) {
64
+ // if (
65
+ // source[key] &&
66
+ // typeof source[key] === 'object' &&
67
+ // !Array.isArray(source[key])
68
+ // ) {
69
+ // if (!target[key]) target[key] = {};
70
+ // mergeObjects(target[key], source[key]);
71
+ // } else {
72
+ // target[key] = source[key];
73
+ // }
74
+ // }
75
+ // }
76
+
61
77
  /* ------------------- Hooks ------------------- */
62
78
 
63
79
  BeforeAll(async () => {
@@ -126,6 +142,12 @@ BeforeStep(async ({ pickleStep }) => {
126
142
  context.response = {};
127
143
  }
128
144
 
145
+ // if (pickleStep.argument?.docString?.content) {
146
+ // const resolvedParams = (await pickleStep.argument.docString.content) && resolveVariable(pickleStep.argument.docString.content)
147
+ // const parsedParams = JSON.parse(resolvedParams);
148
+ // mergeObjects(mergedParams, parsedParams);
149
+ // }
150
+
129
151
  if (typeof projectHooks.BeforeStep === "function") {
130
152
  await projectHooks.BeforeStep();
131
153
  }
@@ -146,7 +168,6 @@ After(async function ({result, pickle}) {
146
168
  await projectHooks.After();
147
169
  }
148
170
 
149
- await attachResponse(allure.attachment);
150
171
  context.response = await {};
151
172
  allure.attachment('Variables', JSON.stringify(context.vars, null, 2), 'application/json')
152
173