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,44 +1,39 @@
|
|
|
1
1
|
const { context } = require("../../hooks/context");
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
static elements = {};
|
|
3
|
+
let elements = {};
|
|
5
4
|
|
|
6
|
-
static addElements(elements) {
|
|
7
|
-
this.elements = { ...this.elements, ...elements };
|
|
8
|
-
}
|
|
9
5
|
|
|
10
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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(
|
|
41
|
-
const waitTime =
|
|
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
|
-
|
|
83
|
-
const selector =
|
|
84
|
-
this.elements?.[element]?.selector || this.elements?.[element] || element;
|
|
85
|
-
return selector;
|
|
86
|
-
}
|
|
77
|
+
|
|
87
78
|
|
|
88
|
-
|
|
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
|
-
|
|
99
|
+
saveVar(value, customVarName, path);
|
|
109
100
|
}
|
|
110
101
|
});
|
|
111
102
|
}
|
|
112
103
|
|
|
113
|
-
|
|
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
|
-
|
|
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
|
|
145
|
-
addElements
|
|
146
|
-
getSelector
|
|
147
|
-
extractVarsFromResponse
|
|
148
|
-
saveVar
|
|
149
|
-
resolveVariable
|
|
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 (
|
|
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
|
|
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 (
|
|
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,
|
|
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
|
});
|