@cuppet/core 1.3.7 → 2.0.0
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.
|
@@ -40,12 +40,10 @@ Given('that I have a multipart request body', async function (docString) {
|
|
|
40
40
|
const body = JSON.parse(docString);
|
|
41
41
|
await apiSteps.buildMultipartFormData(body);
|
|
42
42
|
});
|
|
43
|
-
Given(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
);
|
|
43
|
+
Given('I put {string} to {string} property in the request body', async function (value, objectPath) {
|
|
44
|
+
const checkedValue = await dataStorage.checkForSavedVariable(value);
|
|
45
|
+
await apiSteps.iPutValuesInRequestBody(checkedValue, objectPath);
|
|
46
|
+
});
|
|
49
47
|
|
|
50
48
|
Given('I create json object from {string} file', async function (filePath) {
|
|
51
49
|
const checkedPath = await dataStorage.checkForSavedVariable(filePath);
|
|
@@ -56,5 +54,7 @@ Given('I validate that the page is a valid XML', async function () {
|
|
|
56
54
|
await apiSteps.validateXMLEndpoint(currentPath);
|
|
57
55
|
});
|
|
58
56
|
Then('the response header {string} should be {string}', async function (header, value) {
|
|
59
|
-
await
|
|
57
|
+
const checkedHeader = await dataStorage.checkForSavedVariable(header);
|
|
58
|
+
const checkedValue = await dataStorage.checkForSavedVariable(value);
|
|
59
|
+
await apiSteps.validateResponseHeader(checkedHeader, checkedValue);
|
|
60
60
|
});
|
|
@@ -14,4 +14,4 @@ Feature: Open DEMO QA (as base site) and use the elements section
|
|
|
14
14
|
And I wait for element with "#output" selector to appear within "2" seconds
|
|
15
15
|
And I should see the element with selector "#name"
|
|
16
16
|
And I should see the element with selector "#email"
|
|
17
|
-
And I should see the element with selector "p#currentAddress"
|
|
17
|
+
And I should see the element with selector "p#currentAddress"
|
package/package.json
CHANGED
package/src/apiFunctions.js
CHANGED
|
@@ -148,17 +148,28 @@ module.exports = {
|
|
|
148
148
|
* }
|
|
149
149
|
* @async
|
|
150
150
|
* @function prepareRequestBody
|
|
151
|
-
* @param value - the value
|
|
152
|
-
* @param
|
|
153
|
-
* @param object - parent object name
|
|
151
|
+
* @param value - the value to set
|
|
152
|
+
* @param objectPath - the path in dot notation (e.g., "home.user.firstName")
|
|
154
153
|
* @returns {Promise<Object>} - returns the request body object
|
|
155
154
|
*/
|
|
156
|
-
iPutValuesInRequestBody: async function (value,
|
|
157
|
-
const preparedValue = await storage.checkForVariable(value);
|
|
155
|
+
iPutValuesInRequestBody: async function (value, objectPath) {
|
|
158
156
|
if (!this.request) {
|
|
159
157
|
this.request = {};
|
|
160
158
|
}
|
|
161
|
-
|
|
159
|
+
|
|
160
|
+
const keys = objectPath.split('.');
|
|
161
|
+
let current = this.request;
|
|
162
|
+
|
|
163
|
+
// Navigate/create the path, stopping before the last key
|
|
164
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
165
|
+
if (!current[keys[i]]) {
|
|
166
|
+
current[keys[i]] = {};
|
|
167
|
+
}
|
|
168
|
+
current = current[keys[i]];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Set the final value
|
|
172
|
+
current[keys[keys.length - 1]] = value;
|
|
162
173
|
return this.request;
|
|
163
174
|
},
|
|
164
175
|
|
|
@@ -272,15 +283,9 @@ module.exports = {
|
|
|
272
283
|
validateResponseHeader: async function (header, value) {
|
|
273
284
|
// Resolve header and value from variables or user input.
|
|
274
285
|
// The header is checked directly for faster execution as it is less likely to contain variables.
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
assert.isDefined(actualValue, `The response header "${resolveHeader}" is not found!`);
|
|
279
|
-
assert.strictEqual(
|
|
280
|
-
actualValue,
|
|
281
|
-
resolveValue,
|
|
282
|
-
`The response header "${resolveHeader}" does not have the expected value`
|
|
283
|
-
);
|
|
286
|
+
const actualValue = this.response.headers[header.toLowerCase()];
|
|
287
|
+
assert.isDefined(actualValue, `The response header "${header}" is not found!`);
|
|
288
|
+
assert.strictEqual(actualValue, value, `The response header "${header}" does not have the expected value`);
|
|
284
289
|
},
|
|
285
290
|
|
|
286
291
|
/**
|
package/src/dataStorage.js
CHANGED
|
@@ -94,7 +94,7 @@ module.exports = {
|
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* Check for variable existence or return the inputted value.
|
|
97
|
-
*
|
|
97
|
+
* Do not use separately in step definitions, use checkForSavedVariable instead.
|
|
98
98
|
* @param variable
|
|
99
99
|
* @returns {*}
|
|
100
100
|
*/
|
|
@@ -110,7 +110,11 @@ module.exports = {
|
|
|
110
110
|
* @returns {Promise<*>}
|
|
111
111
|
*/
|
|
112
112
|
checkForSavedVariable: async function (data) {
|
|
113
|
-
|
|
113
|
+
// First check if the whole variable is stored
|
|
114
|
+
const resolvedData = this.checkForVariable(data);
|
|
115
|
+
|
|
116
|
+
// Then check for %% pattern replacements
|
|
117
|
+
return resolvedData.replace(/%([a-zA-Z_-]+)%/g, (match, p1) => {
|
|
114
118
|
return this.checkForVariable(p1);
|
|
115
119
|
});
|
|
116
120
|
},
|