artes 1.0.74 → 1.0.75
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/docs/functionDefinitions.md +3 -3
- package/package.json +1 -1
- package/src/helper/pomController/elementController.js +1 -2
- package/src/hooks/hooks.js +14 -3
- package/src/stepDefinitions/API.steps.js +11 -11
- package/src/stepDefinitions/assertions.steps.js +1 -1
- package/src/stepDefinitions/random.steps.js +5 -5
|
@@ -2236,7 +2236,7 @@ console.log(currentVars); // { token: "abc123", userId: "user456" }
|
|
|
2236
2236
|
|
|
2237
2237
|
## Static Methods
|
|
2238
2238
|
|
|
2239
|
-
### `extractVarsFromResponse(vars, customVarName)`
|
|
2239
|
+
### `extractVarsFromResponse(object, vars, customVarName)`
|
|
2240
2240
|
|
|
2241
2241
|
Extracts variables from the response body using dot notation paths.
|
|
2242
2242
|
|
|
@@ -2252,10 +2252,10 @@ Extracts variables from the response body using dot notation paths.
|
|
|
2252
2252
|
**Example:**
|
|
2253
2253
|
```javascript
|
|
2254
2254
|
// Response body: { user: { id: 123, profile: { name: "John" } } }
|
|
2255
|
-
extractVarsFromResponse("user.id,user.profile.name");
|
|
2255
|
+
extractVarsFromResponse(object, "user.id,user.profile.name");
|
|
2256
2256
|
// Creates variables: userId = 123, userProfileName = "John"
|
|
2257
2257
|
|
|
2258
|
-
extractVarsFromResponse("user.id", "currentUserId");
|
|
2258
|
+
extractVarsFromResponse(object, "user.id", "currentUserId");
|
|
2259
2259
|
// Creates variable: currentUserId = 123
|
|
2260
2260
|
```
|
|
2261
2261
|
|
package/package.json
CHANGED
|
@@ -85,8 +85,7 @@ class Elements {
|
|
|
85
85
|
return selector;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
static extractVarsFromResponse(vars, customVarName) {
|
|
89
|
-
const responseBody = context.response["Response Body"];
|
|
88
|
+
static extractVarsFromResponse(responseBody, vars, customVarName) {
|
|
90
89
|
|
|
91
90
|
function getValueByPath(obj, path) {
|
|
92
91
|
const keys = path.split(".");
|
package/src/hooks/hooks.js
CHANGED
|
@@ -3,7 +3,8 @@ const {
|
|
|
3
3
|
Before,
|
|
4
4
|
After,
|
|
5
5
|
Status,
|
|
6
|
-
setDefaultTimeout, AfterStep
|
|
6
|
+
setDefaultTimeout, AfterStep,
|
|
7
|
+
BeforeStep
|
|
7
8
|
} = require("@cucumber/cucumber");
|
|
8
9
|
const { invokeBrowser } = require("../helper/contextManager/browserManager");
|
|
9
10
|
const { invokeRequest } = require("../helper/contextManager/requestManager");
|
|
@@ -40,13 +41,23 @@ Before(async function () {
|
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
|
|
44
|
+
BeforeStep(async function ({ pickleStep }) {
|
|
45
|
+
const stepText = pickleStep.text;
|
|
46
|
+
|
|
47
|
+
const methods = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
48
|
+
|
|
49
|
+
if( methods.some(method => stepText.includes(method))){
|
|
50
|
+
context.response = {}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
43
54
|
AfterStep(async function ({pickleStep}) {
|
|
44
55
|
const stepText = pickleStep.text;
|
|
45
56
|
|
|
46
57
|
const methods = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
47
58
|
|
|
48
59
|
if( methods.some(method => stepText.includes(method))){
|
|
49
|
-
if (context.response) {
|
|
60
|
+
if (await context.response) {
|
|
50
61
|
for (const [key, value] of Object.entries(context.response)) {
|
|
51
62
|
let text = `${key}:\n`;
|
|
52
63
|
|
|
@@ -95,7 +106,7 @@ After(async function ({ pickle, result }) {
|
|
|
95
106
|
await context.browser?.close();
|
|
96
107
|
|
|
97
108
|
await context.request?.dispose();
|
|
98
|
-
|
|
109
|
+
|
|
99
110
|
if (result?.status != Status.PASSED && context.page.video()) {
|
|
100
111
|
const videoPath = await context.page.video().path();
|
|
101
112
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
@@ -24,7 +24,7 @@ When(
|
|
|
24
24
|
"User sends GET request to {string} and saves {string} variables",
|
|
25
25
|
async function (url, vars) {
|
|
26
26
|
await api.get(url);
|
|
27
|
-
extractVarsFromResponse(vars);
|
|
27
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
28
28
|
},
|
|
29
29
|
);
|
|
30
30
|
|
|
@@ -32,7 +32,7 @@ When(
|
|
|
32
32
|
"User sends GET request to {string} with payload and saves {string} variables",
|
|
33
33
|
async function (url, vars, payload) {
|
|
34
34
|
await api.get(url, payload);
|
|
35
|
-
extractVarsFromResponse(vars);
|
|
35
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
36
36
|
},
|
|
37
37
|
);
|
|
38
38
|
|
|
@@ -51,7 +51,7 @@ When(
|
|
|
51
51
|
"User sends POST request to {string} with payload and saves {string} variables",
|
|
52
52
|
async function (url, vars, payload) {
|
|
53
53
|
await api.post(url, payload);
|
|
54
|
-
extractVarsFromResponse(vars);
|
|
54
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
55
55
|
},
|
|
56
56
|
);
|
|
57
57
|
|
|
@@ -66,7 +66,7 @@ When(
|
|
|
66
66
|
"User sends multipart POST request to {string} with payload and saves {string} variables",
|
|
67
67
|
async (url, vars, payload) => {
|
|
68
68
|
await api.post(url, payload, "multipart");
|
|
69
|
-
extractVarsFromResponse(vars);
|
|
69
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
70
70
|
},
|
|
71
71
|
);
|
|
72
72
|
|
|
@@ -81,7 +81,7 @@ When(
|
|
|
81
81
|
"User sends PUT request to {string} with payload and saves {string} variables",
|
|
82
82
|
async function (url, vars, payload) {
|
|
83
83
|
await api.put(url, payload);
|
|
84
|
-
extractVarsFromResponse(vars);
|
|
84
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
85
85
|
},
|
|
86
86
|
);
|
|
87
87
|
|
|
@@ -96,7 +96,7 @@ When(
|
|
|
96
96
|
"User sends multipart PUT request to {string} with payload and saves {string} variables",
|
|
97
97
|
async function (url, vars, payload) {
|
|
98
98
|
await api.put(url, payload, "multipart");
|
|
99
|
-
extractVarsFromResponse(vars);
|
|
99
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
100
100
|
},
|
|
101
101
|
);
|
|
102
102
|
|
|
@@ -111,7 +111,7 @@ When(
|
|
|
111
111
|
"User sends PATCH request to {string} with payload and saves {string} variables",
|
|
112
112
|
async function (url, vars, payload) {
|
|
113
113
|
await api.patch(url, payload);
|
|
114
|
-
extractVarsFromResponse(vars);
|
|
114
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
115
115
|
},
|
|
116
116
|
);
|
|
117
117
|
|
|
@@ -126,7 +126,7 @@ When(
|
|
|
126
126
|
"User sends multipart PATCH request to {string} with payload and saves {string} variables",
|
|
127
127
|
async function (url, vars, payload) {
|
|
128
128
|
await api.patch(url, payload, "multipart");
|
|
129
|
-
extractVarsFromResponse(vars);
|
|
129
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
130
130
|
},
|
|
131
131
|
);
|
|
132
132
|
|
|
@@ -138,7 +138,7 @@ When(
|
|
|
138
138
|
"User sends DELETE request to {string} and saves {string} variables",
|
|
139
139
|
async function (url, vars) {
|
|
140
140
|
await api.delete(url);
|
|
141
|
-
extractVarsFromResponse(vars);
|
|
141
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
142
142
|
},
|
|
143
143
|
);
|
|
144
144
|
|
|
@@ -153,14 +153,14 @@ When(
|
|
|
153
153
|
"User sends DELETE request to {string} with payload and saves {string} variables",
|
|
154
154
|
async function (url, vars, payload) {
|
|
155
155
|
await api.delete(url, payload);
|
|
156
|
-
extractVarsFromResponse(vars);
|
|
156
|
+
await extractVarsFromResponse(context.response["Response Body"], vars);
|
|
157
157
|
},
|
|
158
158
|
);
|
|
159
159
|
|
|
160
160
|
When(
|
|
161
161
|
"User saves {string} variable from response as {string}",
|
|
162
162
|
async function (vars, customVarName) {
|
|
163
|
-
extractVarsFromResponse(vars, customVarName);
|
|
163
|
+
await extractVarsFromResponse(context.response["Response Body"], vars, customVarName);
|
|
164
164
|
},
|
|
165
165
|
);
|
|
166
166
|
|
|
@@ -819,7 +819,7 @@ Then("User expects should have {int} {string}", async (count, elements) => {
|
|
|
819
819
|
Then(
|
|
820
820
|
"User expects that response has {string} field with {string} value",
|
|
821
821
|
async (field, value) => {
|
|
822
|
-
extractVarsFromResponse(
|
|
822
|
+
extractVarsFromResponse(context.response["Response Body"], field);
|
|
823
823
|
|
|
824
824
|
expect(context.vars[field]).toBe(value);
|
|
825
825
|
},
|
|
@@ -14,12 +14,12 @@ Given(
|
|
|
14
14
|
);
|
|
15
15
|
|
|
16
16
|
Given(
|
|
17
|
-
"User sends GET request to {string} and save {string} variable as a {string} randomly",
|
|
18
|
-
async (
|
|
19
|
-
|
|
20
|
-
const
|
|
17
|
+
"User sends GET request to {string} and save {string} variable from {string} array as a {string} randomly",
|
|
18
|
+
async (endPoint, varName, fromArray, variableKey) => {
|
|
19
|
+
await api.get(endPoint);
|
|
20
|
+
const responseBody = await context.response["Response Body"][fromArray]
|
|
21
21
|
const randomContent =
|
|
22
|
-
|
|
22
|
+
responseBody[random.number.int({ min: 0, max: responseBody.length - 1 })];
|
|
23
23
|
context.vars[variableKey] = randomContent[varName];
|
|
24
24
|
},
|
|
25
25
|
);
|