codeceptjs 3.5.12-beta.2 → 3.5.12-beta.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/lib/locator.js +7 -12
- package/package.json +3 -4
- package/lib/css2xpath/js/css_to_xpath.js +0 -20
- package/lib/css2xpath/js/expression.js +0 -23
- package/lib/css2xpath/js/renderer.js +0 -239
package/lib/locator.js
CHANGED
|
@@ -162,22 +162,17 @@ class Locator {
|
|
|
162
162
|
* @returns {string}
|
|
163
163
|
*/
|
|
164
164
|
toXPath(pseudoSelector = '') {
|
|
165
|
+
const locator = `${this.value}${pseudoSelector}`;
|
|
165
166
|
const limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang'];
|
|
166
167
|
|
|
167
|
-
if (
|
|
168
|
-
cssToXPath = require('
|
|
169
|
-
} else if (this.value.includes('-')) {
|
|
170
|
-
if (!limitation.some(item => this.value.includes(item))) {
|
|
171
|
-
cssToXPath = require('csstoxpath');
|
|
172
|
-
}
|
|
173
|
-
} else if (limitation.some(item => this.value.includes(item))) {
|
|
174
|
-
cssToXPath = require('./css2xpath/js/css_to_xpath');
|
|
168
|
+
if (limitation.some(item => locator.includes(item))) {
|
|
169
|
+
cssToXPath = require('css-to-xpath');
|
|
175
170
|
} else {
|
|
176
|
-
cssToXPath = require('
|
|
171
|
+
cssToXPath = require('csstoxpath');
|
|
177
172
|
}
|
|
178
173
|
|
|
179
174
|
if (this.isXPath()) return this.value;
|
|
180
|
-
if (this.isCSS()) return cssToXPath(
|
|
175
|
+
if (this.isCSS()) return cssToXPath(locator);
|
|
181
176
|
|
|
182
177
|
throw new Error('Can\'t be converted to XPath');
|
|
183
178
|
}
|
|
@@ -264,7 +259,7 @@ class Locator {
|
|
|
264
259
|
*/
|
|
265
260
|
withText(text) {
|
|
266
261
|
text = xpathLocator.literal(text);
|
|
267
|
-
const xpath = this.toXPath(
|
|
262
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), `contains(., ${text})`);
|
|
268
263
|
return new Locator({ xpath });
|
|
269
264
|
}
|
|
270
265
|
|
|
@@ -275,7 +270,7 @@ class Locator {
|
|
|
275
270
|
*/
|
|
276
271
|
withTextEquals(text) {
|
|
277
272
|
text = xpathLocator.literal(text);
|
|
278
|
-
const xpath = this.toXPath(
|
|
273
|
+
const xpath = sprintf('%s[%s]', this.toXPath(), `.= ${text}`);
|
|
279
274
|
return new Locator({ xpath });
|
|
280
275
|
}
|
|
281
276
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeceptjs",
|
|
3
|
-
"version": "3.5.12-beta.
|
|
3
|
+
"version": "3.5.12-beta.5",
|
|
4
4
|
"description": "Supercharged End 2 End Testing Framework for NodeJS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"acceptance",
|
|
@@ -75,7 +75,6 @@
|
|
|
75
75
|
"acorn": "8.11.2",
|
|
76
76
|
"arrify": "2.0.1",
|
|
77
77
|
"axios": "1.6.3",
|
|
78
|
-
"bo-selector": "0.0.10",
|
|
79
78
|
"chai": "4.3.8",
|
|
80
79
|
"chai-deep-match": "1.2.1",
|
|
81
80
|
"chai-exclude": "2.1.0",
|
|
@@ -86,6 +85,7 @@
|
|
|
86
85
|
"chalk": "4.1.2",
|
|
87
86
|
"commander": "11.1.0",
|
|
88
87
|
"cross-spawn": "7.0.3",
|
|
88
|
+
"css-to-xpath": "0.1.0",
|
|
89
89
|
"csstoxpath": "1.6.0",
|
|
90
90
|
"devtools": "8.27.2",
|
|
91
91
|
"envinfo": "7.11.0",
|
|
@@ -110,8 +110,7 @@
|
|
|
110
110
|
"promise-retry": "1.1.1",
|
|
111
111
|
"resq": "1.11.0",
|
|
112
112
|
"sprintf-js": "1.1.1",
|
|
113
|
-
"uuid": "9.0"
|
|
114
|
-
"xpath-builder": "0.0.7"
|
|
113
|
+
"uuid": "9.0"
|
|
115
114
|
},
|
|
116
115
|
"optionalDependencies": {
|
|
117
116
|
"@codeceptjs/detox-helper": "1.0.2"
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
var self = this;
|
|
3
|
-
var parser, xpathBuilder, Expression, parse, convertToXpath;
|
|
4
|
-
parser = require("bo-selector").parser;
|
|
5
|
-
xpathBuilder = require("xpath-builder").dsl();
|
|
6
|
-
Expression = require("./expression");
|
|
7
|
-
parser.yy.create = function(data) {
|
|
8
|
-
var self = this;
|
|
9
|
-
return new Expression(data);
|
|
10
|
-
};
|
|
11
|
-
parse = function(selector) {
|
|
12
|
-
return parser.parse(selector).render(xpathBuilder, "descendant");
|
|
13
|
-
};
|
|
14
|
-
convertToXpath = function(selector) {
|
|
15
|
-
return parse(selector).toXPath();
|
|
16
|
-
};
|
|
17
|
-
convertToXpath.parse = parse;
|
|
18
|
-
convertToXpath.xPathBuilder = xpathBuilder;
|
|
19
|
-
module.exports = convertToXpath;
|
|
20
|
-
}).call(this);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
var self = this;
|
|
3
|
-
var Renderer, Expression, extend;
|
|
4
|
-
Renderer = require("./renderer");
|
|
5
|
-
Expression = function(data) {
|
|
6
|
-
extend(this, data);
|
|
7
|
-
return this;
|
|
8
|
-
};
|
|
9
|
-
Expression.prototype.render = function(xpath, combinator) {
|
|
10
|
-
var self = this;
|
|
11
|
-
return new Renderer().render(self, xpath, combinator);
|
|
12
|
-
};
|
|
13
|
-
extend = function(o, d) {
|
|
14
|
-
var k;
|
|
15
|
-
for (k in d) {
|
|
16
|
-
(function(k) {
|
|
17
|
-
o[k] = d[k];
|
|
18
|
-
})(k);
|
|
19
|
-
}
|
|
20
|
-
return void 0;
|
|
21
|
-
};
|
|
22
|
-
module.exports = Expression;
|
|
23
|
-
}).call(this);
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
var self = this;
|
|
3
|
-
var xpathBuilder, Renderer;
|
|
4
|
-
xpathBuilder = require("xpath-builder").dsl();
|
|
5
|
-
Renderer = function() {
|
|
6
|
-
return this;
|
|
7
|
-
};
|
|
8
|
-
Renderer.prototype = {
|
|
9
|
-
render: function(node, xpath, combinator) {
|
|
10
|
-
var self = this;
|
|
11
|
-
var fn;
|
|
12
|
-
fn = self[node.type];
|
|
13
|
-
if (!fn) {
|
|
14
|
-
throw new Error("No renderer for '" + node.type + "'");
|
|
15
|
-
}
|
|
16
|
-
return fn.call(self, node, xpath, combinator);
|
|
17
|
-
},
|
|
18
|
-
selector_list: function(node, xpath, combinator) {
|
|
19
|
-
var self = this;
|
|
20
|
-
var x, i;
|
|
21
|
-
x = self.render(node.selectors[0], xpath, combinator);
|
|
22
|
-
for (i = 1; i < node.selectors.length; ++i) {
|
|
23
|
-
x = x.union(self.render(node.selectors[i], xpath, combinator));
|
|
24
|
-
}
|
|
25
|
-
return x;
|
|
26
|
-
},
|
|
27
|
-
constraint_list: function(node, xpath, combinator) {
|
|
28
|
-
var self = this;
|
|
29
|
-
return self.element(node, xpath, combinator);
|
|
30
|
-
},
|
|
31
|
-
element: function(node, xpath, combinator) {
|
|
32
|
-
var self = this;
|
|
33
|
-
return self.applyConstraints(node, xpath[combinator].call(xpath, node.name || "*"));
|
|
34
|
-
},
|
|
35
|
-
combinator_selector: function(node, xpath, combinator) {
|
|
36
|
-
var self = this;
|
|
37
|
-
var left;
|
|
38
|
-
left = self.render(node.left, xpath, combinator);
|
|
39
|
-
return self.render(node.right, left, node.combinator);
|
|
40
|
-
},
|
|
41
|
-
immediate_child: function(node, xpath) {
|
|
42
|
-
var self = this;
|
|
43
|
-
return self.render(node.child, xpath, "child");
|
|
44
|
-
},
|
|
45
|
-
pseudo_func: function(node, xpath) {
|
|
46
|
-
var self = this;
|
|
47
|
-
var fn;
|
|
48
|
-
fn = self[node.func.name.replace(/-/g, "_")];
|
|
49
|
-
if (fn) {
|
|
50
|
-
return fn.call(self, node, xpath);
|
|
51
|
-
} else {
|
|
52
|
-
throw new Error("Unsupported pseudo function :" + node.func.name + "()");
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
pseudo_class: function(node, xpath) {
|
|
56
|
-
var self = this;
|
|
57
|
-
var fn;
|
|
58
|
-
fn = self[node.name.replace(/-/g, "_")];
|
|
59
|
-
if (fn) {
|
|
60
|
-
return fn.call(self, node, xpath);
|
|
61
|
-
} else {
|
|
62
|
-
throw new Error("Unsupported pseudo class :" + node.name);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
has: function(node, xpath) {
|
|
66
|
-
var self = this;
|
|
67
|
-
return self.render(node.func.args, xpathBuilder, "descendant");
|
|
68
|
-
},
|
|
69
|
-
not: function(node, xpath) {
|
|
70
|
-
var self = this;
|
|
71
|
-
var firstChild, childType;
|
|
72
|
-
firstChild = node.func.args.selectors[0];
|
|
73
|
-
childType = firstChild.type;
|
|
74
|
-
if (childType === "constraint_list") {
|
|
75
|
-
return self.combineConstraints(firstChild, xpath).inverse();
|
|
76
|
-
} else {
|
|
77
|
-
return self.matchesSelectorList(node.func.args, xpath).inverse();
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
nth_child: function(node, xpath) {
|
|
81
|
-
var self = this;
|
|
82
|
-
return xpath.nthChild(Number(node.func.args));
|
|
83
|
-
},
|
|
84
|
-
first_child: function(node, xpath) {
|
|
85
|
-
var self = this;
|
|
86
|
-
return xpath.firstChild();
|
|
87
|
-
},
|
|
88
|
-
last_child: function(node, xpath) {
|
|
89
|
-
var self = this;
|
|
90
|
-
return xpath.lastChild();
|
|
91
|
-
},
|
|
92
|
-
nth_last_child: function(node, xpath) {
|
|
93
|
-
var self = this;
|
|
94
|
-
return xpath.nthLastChild(Number(node.func.args));
|
|
95
|
-
},
|
|
96
|
-
only_child: function(node, xpath) {
|
|
97
|
-
var self = this;
|
|
98
|
-
return xpath.onlyChild();
|
|
99
|
-
},
|
|
100
|
-
only_of_type: function(node, xpath) {
|
|
101
|
-
var self = this;
|
|
102
|
-
return xpath.onlyOfType();
|
|
103
|
-
},
|
|
104
|
-
nth_of_type: function(node, xpath) {
|
|
105
|
-
var self = this;
|
|
106
|
-
var type;
|
|
107
|
-
type = node.func.args.type;
|
|
108
|
-
if (type === "odd") {
|
|
109
|
-
return xpath.nthOfTypeOdd();
|
|
110
|
-
} else if (type === "even") {
|
|
111
|
-
return xpath.nthOfTypeEven();
|
|
112
|
-
} else if (type === "an") {
|
|
113
|
-
return xpath.nthOfTypeMod(Number(node.func.args.a));
|
|
114
|
-
} else if (type === "n_plus_b") {
|
|
115
|
-
return xpath.nthOfTypeMod(1, Number(node.func.args.b));
|
|
116
|
-
} else if (type === "an_plus_b") {
|
|
117
|
-
return xpath.nthOfTypeMod(Number(node.func.args.a), Number(node.func.args.b));
|
|
118
|
-
} else {
|
|
119
|
-
return xpath.nthOfType(Number(node.func.args));
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
nth_last_of_type: function(node, xpath) {
|
|
123
|
-
var self = this;
|
|
124
|
-
var type;
|
|
125
|
-
type = node.func.args.type;
|
|
126
|
-
if (type === "odd") {
|
|
127
|
-
return xpath.nthLastOfTypeOdd();
|
|
128
|
-
} else if (type === "even") {
|
|
129
|
-
return xpath.nthLastOfTypeEven();
|
|
130
|
-
} else if (type === "an") {
|
|
131
|
-
return xpath.nthLastOfTypeMod(Number(node.func.args.a));
|
|
132
|
-
} else if (type === "n_plus_b") {
|
|
133
|
-
return xpath.nthLastOfTypeMod(1, Number(node.func.args.b));
|
|
134
|
-
} else if (type === "an_plus_b") {
|
|
135
|
-
return xpath.nthLastOfTypeMod(Number(node.func.args.a), Number(node.func.args.b));
|
|
136
|
-
} else {
|
|
137
|
-
return xpath.nthLastOfType(Number(node.func.args));
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
last_of_type: function(node, xpath) {
|
|
141
|
-
var self = this;
|
|
142
|
-
return xpath.lastOfType();
|
|
143
|
-
},
|
|
144
|
-
empty: function(node, xpath) {
|
|
145
|
-
var self = this;
|
|
146
|
-
return xpath.empty();
|
|
147
|
-
},
|
|
148
|
-
has_attribute: function(node, xpath) {
|
|
149
|
-
var self = this;
|
|
150
|
-
return xpathBuilder.attr(node.name);
|
|
151
|
-
},
|
|
152
|
-
attribute_equals: function(node, xpath) {
|
|
153
|
-
var self = this;
|
|
154
|
-
return xpathBuilder.attr(node.name).equals(node.value);
|
|
155
|
-
},
|
|
156
|
-
attribute_contains: function(node, xpath) {
|
|
157
|
-
var self = this;
|
|
158
|
-
return xpathBuilder.attr(node.name).contains(node.value);
|
|
159
|
-
},
|
|
160
|
-
attribute_contains_word: function(node, xpath) {
|
|
161
|
-
var self = this;
|
|
162
|
-
return xpath.concat(" ", xpathBuilder.attr(node.name).normalize(), " ").contains(" " + node.value + " ");
|
|
163
|
-
},
|
|
164
|
-
attribute_contains_prefix: function(node) {
|
|
165
|
-
var self = this;
|
|
166
|
-
return xpathBuilder.attr(node.name).startsWith(node.value).or(xpathBuilder.attr(node.name).startsWith(node.value + "-"));
|
|
167
|
-
},
|
|
168
|
-
attribute_starts_with: function(node, xpath) {
|
|
169
|
-
var self = this;
|
|
170
|
-
return xpathBuilder.attr(node.name).startsWith(node.value);
|
|
171
|
-
},
|
|
172
|
-
attribute_ends_with: function(node) {
|
|
173
|
-
var self = this;
|
|
174
|
-
return xpathBuilder.attr(node.name).endsWith(node.value);
|
|
175
|
-
},
|
|
176
|
-
"class": function(node) {
|
|
177
|
-
var self = this;
|
|
178
|
-
return self.attribute_contains_word({
|
|
179
|
-
name: "class",
|
|
180
|
-
value: node.name
|
|
181
|
-
}, xpathBuilder);
|
|
182
|
-
},
|
|
183
|
-
id: function(node) {
|
|
184
|
-
var self = this;
|
|
185
|
-
return xpathBuilder.attr("id").equals(node.name);
|
|
186
|
-
},
|
|
187
|
-
previous_sibling: function(node, xpath, combinator) {
|
|
188
|
-
var self = this;
|
|
189
|
-
var left;
|
|
190
|
-
left = self.render(node.left, xpath, combinator);
|
|
191
|
-
return self.applyConstraints(node.right, left.axis("following-sibling", node.right.name));
|
|
192
|
-
},
|
|
193
|
-
adjacent_sibling: function(node, xpath, combinator) {
|
|
194
|
-
var self = this;
|
|
195
|
-
var left;
|
|
196
|
-
left = self.render(node.left, xpath, combinator);
|
|
197
|
-
return self.applyConstraints(node.right, left.axis("following-sibling::*[1]/self", node.right.name));
|
|
198
|
-
},
|
|
199
|
-
first_of_type: function(node, xpath) {
|
|
200
|
-
var self = this;
|
|
201
|
-
return xpath.firstOfType();
|
|
202
|
-
},
|
|
203
|
-
matchesSelectorList: function(node, xpath) {
|
|
204
|
-
var self = this;
|
|
205
|
-
var condition, i;
|
|
206
|
-
if (node.selectors.length > 0) {
|
|
207
|
-
condition = self.matchesSelector(node.selectors[0], xpathBuilder);
|
|
208
|
-
for (i = 1; i < node.selectors.length; ++i) {
|
|
209
|
-
condition = condition.or(self.matchesSelector(node.selectors[i], xpathBuilder));
|
|
210
|
-
}
|
|
211
|
-
return condition;
|
|
212
|
-
} else {
|
|
213
|
-
return xpath;
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
matchesSelector: function(node, xpath) {
|
|
217
|
-
var self = this;
|
|
218
|
-
return xpath.name().equals(node.name);
|
|
219
|
-
},
|
|
220
|
-
combineConstraints: function(node, xpath) {
|
|
221
|
-
var self = this;
|
|
222
|
-
var condition, i;
|
|
223
|
-
condition = self.render(node.constraints[0], xpath);
|
|
224
|
-
for (i = 1; i < node.constraints.length; ++i) {
|
|
225
|
-
condition = condition.and(self.render(node.constraints[i], condition));
|
|
226
|
-
}
|
|
227
|
-
return condition;
|
|
228
|
-
},
|
|
229
|
-
applyConstraints: function(node, xpath) {
|
|
230
|
-
var self = this;
|
|
231
|
-
if (node.constraints.length > 0) {
|
|
232
|
-
return xpath.where(self.combineConstraints(node, xpath));
|
|
233
|
-
} else {
|
|
234
|
-
return xpath;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
module.exports = Renderer;
|
|
239
|
-
}).call(this);
|