artes 1.0.47 → 1.0.49

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/index.js CHANGED
@@ -6,10 +6,11 @@ const {
6
6
  context,
7
7
  element,
8
8
  selector,
9
- saveVar,extractVarsFromResponse,
9
+ saveVar,
10
+ extractVarsFromResponse,
10
11
  page,
11
12
  request,
12
- random
13
+ random,
13
14
  } = require("./src/helper/imports/commons");
14
15
  const {
15
16
  keyboard,
@@ -26,7 +27,8 @@ module.exports = {
26
27
  Then,
27
28
  element,
28
29
  selector,
29
- saveVar,extractVarsFromResponse,
30
+ saveVar,
31
+ extractVarsFromResponse,
30
32
  context,
31
33
  random,
32
34
  page,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artes",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "The package provide step definitions and user writes feature files, and the package handles automation, with optional POM files and custom step definitions.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -7,7 +7,7 @@ const {
7
7
  saveVar,
8
8
  resolveVariable,
9
9
  } = require("../pomController/elementController");
10
- const { faker } = require('@faker-js/faker');
10
+ const { faker } = require("@faker-js/faker");
11
11
  const { context } = require("../../hooks/context");
12
12
 
13
13
  const element = getElement;
@@ -87,11 +87,11 @@ class Elements {
87
87
 
88
88
  static extractVarsFromResponse(vars, customVarName) {
89
89
  const responseBody = context.response.responseBody;
90
-
90
+
91
91
  function getValueByPath(obj, path) {
92
92
  const keys = path.split(".");
93
93
  let current = obj;
94
-
94
+
95
95
  for (const key of keys) {
96
96
  if (current && typeof current === "object" && key in current) {
97
97
  current = current[key];
@@ -99,15 +99,15 @@ class Elements {
99
99
  return undefined;
100
100
  }
101
101
  }
102
-
102
+
103
103
  return current;
104
104
  }
105
-
105
+
106
106
  vars.split(",").forEach((v) => {
107
107
  const path = v.trim();
108
108
  const value = getValueByPath(responseBody, path);
109
109
  if (value !== undefined) {
110
- saveVar(value, customVarName, path);
110
+ this.saveVar(value, customVarName, path);
111
111
  }
112
112
  });
113
113
  }
@@ -141,7 +141,7 @@ const api = {
141
141
  context.response = response;
142
142
  },
143
143
  vars: () => {
144
- return context.vars
144
+ return context.vars;
145
145
  },
146
146
  };
147
147
 
@@ -4,13 +4,11 @@ const {
4
4
  expect,
5
5
  selector,
6
6
  extractVarsFromResponse,
7
- saveVar
7
+ saveVar,
8
8
  } = require("../helper/imports/commons");
9
9
  const { api } = require("../helper/stepFunctions/exporter");
10
10
  const Ajv = require("ajv");
11
11
 
12
-
13
-
14
12
  When("User sends GET request to {string}", async function (url) {
15
13
  await api.get(url);
16
14
  });
@@ -130,7 +128,6 @@ When(
130
128
 
131
129
  When("User wants to see saved variables", async function () {
132
130
  console.log("\nVariables:", api.vars(), "\n");
133
-
134
131
  });
135
132
 
136
133
  When("User wants to see request body", async function () {
@@ -3,6 +3,8 @@ const {
3
3
  selector,
4
4
  expect,
5
5
  element,
6
+ extractVarsFromResponse,
7
+ context
6
8
  } = require("../helper/imports/commons");
7
9
  const { assert, frame } = require("../helper/stepFunctions/exporter");
8
10
 
@@ -813,3 +815,12 @@ Then("User expects should have {int} {string}", async (count, elements) => {
813
815
  const elementCount = await frame.count(elements);
814
816
  expect(elementCount).toEqual(count);
815
817
  });
818
+
819
+ Then(
820
+ "User expects that response has {string} field with {string} value",
821
+ async (field, value) => {
822
+ extractVarsFromResponse(field, field);
823
+
824
+ expect(context.vars[field]).toBe(value);
825
+ },
826
+ );
@@ -1,24 +1,25 @@
1
- const { Given, context, random, expect, extractVarsFromResponse } = require("../helper/imports/commons");
1
+ const { Given, context, random } = require("../helper/imports/commons");
2
2
 
3
3
  Given("User sets random words as {string} variable", async (key) => {
4
- const words = random.lorem.words({min:2, max: 5})
5
- context.vars[key] = words;
4
+ const words = random.lorem.words({ min: 2, max: 5 });
5
+ context.vars[key] = words;
6
6
  });
7
7
 
8
- Given("User sets random number from {int} to {int} as {string} variable", async (from, to, key) => {
9
- const number = random.number.int({min: from, max: to});
8
+ Given(
9
+ "User sets random number from {int} to {int} as {string} variable",
10
+ async (from, to, key) => {
11
+ const number = random.number.int({ min: from, max: to });
10
12
  context.vars[key] = number;
11
- });
13
+ },
14
+ );
12
15
 
13
- Given('User sends GET request to {string} and save {string} variable as a {string} randomly', async (api, varName, variableKey) => {
14
- const res = await fetch(api)
16
+ Given(
17
+ "User sends GET request to {string} and save {string} variable as a {string} randomly",
18
+ async (api, varName, variableKey) => {
19
+ const res = await fetch(api);
15
20
  const body = await res.json();
16
- const randomContent = body.content[random.number.int({ min: 0, max: body.content.length - 1 })];
17
- context.vars[variableKey] = randomContent[varName];
18
- })
19
-
20
- Given('User expects that response has {string} field with {string} value', async (field, value) => {
21
- extractVarsFromResponse(field, field);
22
-
23
- expect(context.vars[field]).toBe(value);
24
- })
21
+ const randomContent =
22
+ body.content[random.number.int({ min: 0, max: body.content.length - 1 })];
23
+ context.vars[variableKey] = randomContent[varName];
24
+ },
25
+ );