@cuppet/core 1.3.8 → 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,15 +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
- 'I put {string} to {string} property of {string} element in the body',
45
- async function (value, property, parentObj) {
46
- const checkedValue = await dataStorage.checkForSavedVariable(value);
47
- const checkedProperty = await dataStorage.checkForSavedVariable(property);
48
- const checkedParentObj = await dataStorage.checkForSavedVariable(parentObj);
49
- await apiSteps.iPutValuesInRequestBody(checkedValue, checkedProperty, checkedParentObj);
50
- }
51
- );
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
+ });
52
47
 
53
48
  Given('I create json object from {string} file', async function (filePath) {
54
49
  const checkedPath = await dataStorage.checkForSavedVariable(filePath);
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuppet/core",
3
- "version": "1.3.8",
3
+ "version": "2.0.0",
4
4
  "description": "Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -148,16 +148,28 @@ module.exports = {
148
148
  * }
149
149
  * @async
150
150
  * @function prepareRequestBody
151
- * @param value - the value of the new property
152
- * @param property - the name of the property
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, property, object) {
155
+ iPutValuesInRequestBody: async function (value, objectPath) {
157
156
  if (!this.request) {
158
157
  this.request = {};
159
158
  }
160
- this.request[object][property] = value;
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;
161
173
  return this.request;
162
174
  },
163
175