artes 1.7.10 → 1.7.11

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.7.10",
3
+ "version": "1.7.11",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -93,15 +93,37 @@ function getElement(element) {
93
93
  return locator;
94
94
  }
95
95
 
96
+ function pathToCamelCase(path) {
97
+ const cleaned = path.replace(/\[(\d+)\]/g, "_$1");
98
+ const parts = cleaned.split(".");
99
+ return parts
100
+ .map((part, index) => {
101
+ if (index === 0) return part;
102
+ return part.charAt(0).toUpperCase() + part.slice(1);
103
+ })
104
+ .join("");
105
+ }
106
+
96
107
  function extractVarsFromResponse(responseBody, vars, customVarNames) {
97
108
  function getValueByPath(obj, path) {
98
- const keys = path.split(".");
99
- let current = obj;
100
-
101
109
  if (typeof obj === "string") return obj;
102
110
 
111
+ const keys = path.split(".").flatMap((key) => {
112
+ const arrayMatch = key.match(/^([^\[]+)\[(\d+)\]$/);
113
+ if (arrayMatch) {
114
+ return [arrayMatch[1], parseInt(arrayMatch[2])];
115
+ }
116
+ return [key];
117
+ });
118
+
119
+ let current = obj;
103
120
  for (const key of keys) {
104
- if (current && typeof current === "object" && key in current) {
121
+ if (current == null) return undefined;
122
+
123
+ if (typeof key === "number") {
124
+ if (!Array.isArray(current)) return undefined;
125
+ current = current[key];
126
+ } else if (typeof current === "object" && key in current) {
105
127
  current = current[key];
106
128
  } else {
107
129
  return undefined;
@@ -111,15 +133,6 @@ function extractVarsFromResponse(responseBody, vars, customVarNames) {
111
133
  return current;
112
134
  }
113
135
 
114
- function pathToCamelCase(path) {
115
- const parts = path.split(".");
116
- return parts
117
- .map((part, index) => {
118
- if (index === 0) return part;
119
- return part.charAt(0).toUpperCase() + part.slice(1);
120
- })
121
- .join("");
122
- }
123
136
 
124
137
  const varPaths = vars.split(",").map((v) => v.trim());
125
138
  let customNames = [];
@@ -205,6 +218,7 @@ module.exports = {
205
218
  addElements,
206
219
  getSelector,
207
220
  extractVarsFromResponse,
221
+ pathToCamelCase,
208
222
  saveVar,
209
223
  resolveVariable,
210
224
  };
@@ -4,6 +4,7 @@ const {
4
4
  getElement,
5
5
  getSelector,
6
6
  extractVarsFromResponse,
7
+ pathToCamelCase,
7
8
  saveVar,
8
9
  resolveVariable,
9
10
  } = require("../controller/elementController");
@@ -54,6 +55,7 @@ module.exports = {
54
55
  element,
55
56
  selector,
56
57
  extractVarsFromResponse,
58
+ pathToCamelCase,
57
59
  saveVar,
58
60
  resolveVariable,
59
61
  random,
@@ -4,6 +4,7 @@ const {
4
4
  expect,
5
5
  element,
6
6
  extractVarsFromResponse,
7
+ pathToCamelCase,
7
8
  context,
8
9
  resolveVariable,
9
10
  } = require("../helper/imports/commons");
@@ -14,17 +15,6 @@ const { assert, frame } = require("../helper/stepFunctions/exporter");
14
15
  const Ajv = require("ajv");
15
16
 
16
17
 
17
- function pathToCamelCase(path) {
18
- const parts = path.split(".");
19
- return parts
20
- .map((part, index) => {
21
- if (index === 0) return part;
22
- return part.charAt(0).toUpperCase() + part.slice(1);
23
- })
24
- .join("");
25
- }
26
-
27
-
28
18
  // Check if a selector should be attached
29
19
  Then("User expects {string} should be attached", async function (selector) {
30
20
  await assert.shouldBeAttached(selector);