artes 1.1.4 → 1.1.5

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.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "The simplest way to automate UI and API tests using Cucumber-style steps.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,44 +1,39 @@
1
1
  const { context } = require("../../hooks/context");
2
2
 
3
- class Elements {
4
- static elements = {};
3
+ let elements = {};
5
4
 
6
- static addElements(elements) {
7
- this.elements = { ...this.elements, ...elements };
8
- }
9
5
 
10
- // static async locatorExistenceChecker(locator){
6
+ function addElements(newElements) {
7
+ elements = { ...elements, ...newElements };
8
+ }
9
+
10
+ // async function locatorExistenceChecker(locator){
11
11
  // const locatorCount = await locator.count();
12
12
  // console.log(locator, locatorCount)
13
13
  // return locatorCount ==0 ? false : true;
14
14
  // }
15
15
 
16
- static getElement(element) {
17
- if (!context.page) {
18
- throw new Error("Page context is not initialized.");
19
- }
16
+ function selectorSeperator(element) {
17
+ const selector = element?.split("=");
18
+ return [
19
+ selector[0]?.trim(),
20
+ selector[1] !== undefined ? selector[1].trim() : "",
21
+ ];
22
+ }
20
23
 
21
- function selectorSeperator(element) {
22
- const selector = element?.split("=");
23
- return [
24
- selector[0]?.trim(),
25
- selector[1] !== undefined ? selector[1].trim() : "",
26
- ];
27
- }
24
+ function getSelector(element) {
25
+ const selector =
26
+ elements?.[element]?.selector || elements?.[element] || element;
27
+ return resolveVariable(selectorSeperator(selector));
28
+ }
28
29
 
29
- function getSelector(elements, element) {
30
- if (elements?.[element]?.selector) {
31
- return selectorSeperator(elements[element].selector);
32
- } else if (elements?.[element]) {
33
- return selectorSeperator(elements[element]);
34
- } else if (typeof element === "string") {
35
- return selectorSeperator(element);
36
- }
37
- return null;
30
+ function getElement(element) {
31
+ if (!context.page) {
32
+ throw new Error("Page context is not initialized.");
38
33
  }
39
34
 
40
- const selector = getSelector(this.elements, element);
41
- const waitTime = this.elements[element]?.waitTime * 1000 || 0;
35
+ const selector = getSelector(element);
36
+ const waitTime = elements[element]?.waitTime * 1000 || 0;
42
37
 
43
38
  let locator;
44
39
  switch (selector[0]) {
@@ -79,13 +74,9 @@ class Elements {
79
74
  return locator;
80
75
  }
81
76
 
82
- static getSelector(element) {
83
- const selector =
84
- this.elements?.[element]?.selector || this.elements?.[element] || element;
85
- return selector;
86
- }
77
+
87
78
 
88
- static extractVarsFromResponse(responseBody, vars, customVarName) {
79
+ function extractVarsFromResponse(responseBody, vars, customVarName) {
89
80
  function getValueByPath(obj, path) {
90
81
  const keys = path.split(".");
91
82
  let current = obj;
@@ -105,12 +96,12 @@ class Elements {
105
96
  const path = v.trim();
106
97
  const value = getValueByPath(responseBody, path);
107
98
  if (value !== undefined) {
108
- this.saveVar(value, customVarName, path);
99
+ saveVar(value, customVarName, path);
109
100
  }
110
101
  });
111
102
  }
112
103
 
113
- static saveVar(value, customName, path) {
104
+ function saveVar(value, customName, path) {
114
105
  if (!customName) {
115
106
  const flatKey = path
116
107
  .split(".")
@@ -125,7 +116,7 @@ class Elements {
125
116
  }
126
117
  }
127
118
 
128
- static resolveVariable(template) {
119
+ function resolveVariable(template) {
129
120
  if (typeof template !== "string") return template;
130
121
  return template.replace(/{{\s*(\w+)\s*}}/g, (_, varName) => {
131
122
  let value = context.vars[varName];
@@ -138,13 +129,13 @@ class Elements {
138
129
  return value !== undefined ? value : `{{${varName}}}`;
139
130
  });
140
131
  }
141
- }
132
+
142
133
 
143
134
  module.exports = {
144
- getElement: Elements.getElement.bind(Elements),
145
- addElements: Elements.addElements.bind(Elements),
146
- getSelector: Elements.getSelector.bind(Elements),
147
- extractVarsFromResponse: Elements.extractVarsFromResponse.bind(Elements),
148
- saveVar: Elements.saveVar.bind(Elements),
149
- resolveVariable: Elements.resolveVariable.bind(Elements),
135
+ getElement,
136
+ addElements,
137
+ getSelector,
138
+ extractVarsFromResponse,
139
+ saveVar,
140
+ resolveVariable
150
141
  };
@@ -6,12 +6,12 @@ Given("User sets random word as {string} variable", async (key) => {
6
6
  context.vars[key] = word;
7
7
  });
8
8
 
9
- Given("User sets random word that has {int} character as {string} variable", async (count, key) => {
9
+ Given("User sets random word that has {int} character as {string} variable", async (key, count) => {
10
10
  const word = random.lorem.word(count);
11
11
  context.vars[key] = word;
12
12
  });
13
13
 
14
- Given("User sets random word that has character between {int} and {int} as {string} variable", async (from, to, key) => {
14
+ Given("User sets random word that has character between {int} and {int} as {string} variable", async (key, from, to) => {
15
15
  const word = random.lorem.word({length: { min: from, max: to }});
16
16
  context.vars[key] = word;
17
17
  });
@@ -21,12 +21,12 @@ Given("User sets random words as {string} variable", async (key) => {
21
21
  context.vars[key] = words;
22
22
  });
23
23
 
24
- Given("User sets random {int} words as {string} variable", async (count, key) => {
24
+ Given("User sets random {int} words as {string} variable", async (key, count) => {
25
25
  const words = random.lorem.words({ wordCount: count });
26
26
  context.vars[key] = words;
27
27
  });
28
28
 
29
- Given("User sets random words that range between {int} and {int} as {string} variable", async (from, to, key) => {
29
+ Given("User sets random words that range between {int} and {int} as {string} variable", async (key,from,to) => {
30
30
  const words = random.lorem.words({ min: from, max: to });
31
31
  context.vars[key] = words;
32
32
  });