expect-webdriverio 4.4.0 → 4.5.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.
- package/lib/utils.js +33 -22
- package/package.json +18 -18
- package/types/expect-webdriverio.d.ts +447 -466
package/lib/utils.js
CHANGED
|
@@ -4,6 +4,9 @@ import { wrapExpectedWithArray, updateElementsArray } from './util/elementsUtil.
|
|
|
4
4
|
import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
|
|
5
5
|
import { DEFAULT_OPTIONS } from './constants.js';
|
|
6
6
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
+
const asymmetricMatcher = typeof Symbol === 'function' && Symbol.for
|
|
8
|
+
? Symbol.for('jest.asymmetricMatcher')
|
|
9
|
+
: 1267621;
|
|
7
10
|
const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
|
|
8
11
|
if (wait === 0) {
|
|
9
12
|
return await condition();
|
|
@@ -12,12 +15,12 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
12
15
|
let error;
|
|
13
16
|
const start = Date.now();
|
|
14
17
|
while (true) {
|
|
15
|
-
if (
|
|
18
|
+
if (Date.now() - start > wait) {
|
|
16
19
|
throw new Error('timeout');
|
|
17
20
|
}
|
|
18
21
|
error = undefined;
|
|
19
22
|
try {
|
|
20
|
-
const result = isNot !== await condition();
|
|
23
|
+
const result = isNot !== (await condition());
|
|
21
24
|
if (result) {
|
|
22
25
|
break;
|
|
23
26
|
}
|
|
@@ -50,7 +53,7 @@ async function executeCommandBe(received, command, options) {
|
|
|
50
53
|
const message = enhanceErrorBe(el, pass, this, verb, expectation, options);
|
|
51
54
|
return {
|
|
52
55
|
pass,
|
|
53
|
-
message: () => message
|
|
56
|
+
message: () => message,
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
const compareNumbers = (actual, options = {}) => {
|
|
@@ -68,13 +71,21 @@ const compareNumbers = (actual, options = {}) => {
|
|
|
68
71
|
}
|
|
69
72
|
return false;
|
|
70
73
|
};
|
|
71
|
-
export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false, atStart = false, atEnd = false, atIndex, replace }) => {
|
|
74
|
+
export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false, atStart = false, atEnd = false, atIndex, replace, }) => {
|
|
72
75
|
if (typeof actual !== 'string') {
|
|
73
76
|
return {
|
|
74
77
|
value: actual,
|
|
75
|
-
result: false
|
|
78
|
+
result: false,
|
|
76
79
|
};
|
|
77
80
|
}
|
|
81
|
+
if (typeof expected === 'object' && '$$typeof' in expected && expected.$$typeof === asymmetricMatcher) {
|
|
82
|
+
const result = expected.asymmetricMatch(actual);
|
|
83
|
+
return {
|
|
84
|
+
value: actual,
|
|
85
|
+
result
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
expected = expected;
|
|
78
89
|
if (trim) {
|
|
79
90
|
actual = actual.trim();
|
|
80
91
|
}
|
|
@@ -90,43 +101,43 @@ export const compareText = (actual, expected, { ignoreCase = false, trim = true,
|
|
|
90
101
|
if (expected instanceof RegExp) {
|
|
91
102
|
return {
|
|
92
103
|
value: actual,
|
|
93
|
-
result: !!actual.match(expected)
|
|
104
|
+
result: !!actual.match(expected),
|
|
94
105
|
};
|
|
95
106
|
}
|
|
96
107
|
if (containing) {
|
|
97
108
|
return {
|
|
98
109
|
value: actual,
|
|
99
|
-
result: actual.includes(expected)
|
|
110
|
+
result: actual.includes(expected),
|
|
100
111
|
};
|
|
101
112
|
}
|
|
102
113
|
if (atStart) {
|
|
103
114
|
return {
|
|
104
115
|
value: actual,
|
|
105
|
-
result: actual.startsWith(expected)
|
|
116
|
+
result: actual.startsWith(expected),
|
|
106
117
|
};
|
|
107
118
|
}
|
|
108
119
|
if (atEnd) {
|
|
109
120
|
return {
|
|
110
121
|
value: actual,
|
|
111
|
-
result: actual.endsWith(expected)
|
|
122
|
+
result: actual.endsWith(expected),
|
|
112
123
|
};
|
|
113
124
|
}
|
|
114
125
|
if (atIndex) {
|
|
115
126
|
return {
|
|
116
127
|
value: actual,
|
|
117
|
-
result: actual.substring(atIndex, actual.length).startsWith(expected)
|
|
128
|
+
result: actual.substring(atIndex, actual.length).startsWith(expected),
|
|
118
129
|
};
|
|
119
130
|
}
|
|
120
131
|
return {
|
|
121
132
|
value: actual,
|
|
122
|
-
result: actual === expected
|
|
133
|
+
result: actual === expected,
|
|
123
134
|
};
|
|
124
135
|
};
|
|
125
|
-
export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false, atStart = false, atEnd = false, atIndex, replace }) => {
|
|
136
|
+
export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false, atStart = false, atEnd = false, atIndex, replace, }) => {
|
|
126
137
|
if (typeof actual !== 'string') {
|
|
127
138
|
return {
|
|
128
139
|
value: actual,
|
|
129
|
-
result: false
|
|
140
|
+
result: false,
|
|
130
141
|
};
|
|
131
142
|
}
|
|
132
143
|
if (trim) {
|
|
@@ -137,7 +148,7 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
|
|
|
137
148
|
}
|
|
138
149
|
if (ignoreCase) {
|
|
139
150
|
actual = actual.toLowerCase();
|
|
140
|
-
expectedArray = expectedArray.map(item => (item instanceof RegExp
|
|
151
|
+
expectedArray = expectedArray.map((item) => (item instanceof RegExp ? item : item.toLowerCase()));
|
|
141
152
|
}
|
|
142
153
|
const textInArray = expectedArray.some((expected) => {
|
|
143
154
|
if (expected instanceof RegExp) {
|
|
@@ -159,19 +170,19 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
|
|
|
159
170
|
});
|
|
160
171
|
return {
|
|
161
172
|
value: actual,
|
|
162
|
-
result: textInArray
|
|
173
|
+
result: textInArray,
|
|
163
174
|
};
|
|
164
175
|
};
|
|
165
176
|
export const compareObject = (actual, expected) => {
|
|
166
177
|
if (typeof actual !== 'object' || Array.isArray(actual)) {
|
|
167
178
|
return {
|
|
168
179
|
value: actual,
|
|
169
|
-
result: false
|
|
180
|
+
result: false,
|
|
170
181
|
};
|
|
171
182
|
}
|
|
172
183
|
return {
|
|
173
184
|
value: actual,
|
|
174
|
-
result: isEqual(actual, expected)
|
|
185
|
+
result: isEqual(actual, expected),
|
|
175
186
|
};
|
|
176
187
|
};
|
|
177
188
|
export const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
|
|
@@ -194,21 +205,21 @@ export const compareStyle = async (actualEl, style, { ignoreCase = true, trim =
|
|
|
194
205
|
}
|
|
195
206
|
return {
|
|
196
207
|
value: actual,
|
|
197
|
-
result
|
|
208
|
+
result,
|
|
198
209
|
};
|
|
199
210
|
};
|
|
200
|
-
function aliasFn(fn, { verb, expectation } = {}, ...args) {
|
|
211
|
+
function aliasFn(fn, { verb, expectation, } = {}, ...args) {
|
|
201
212
|
this.verb = verb;
|
|
202
213
|
this.expectation = expectation;
|
|
203
214
|
return fn.apply(this, args);
|
|
204
215
|
}
|
|
205
|
-
export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn };
|
|
216
|
+
export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn, };
|
|
206
217
|
function replaceActual(replace, actual) {
|
|
207
|
-
const hasMultipleReplacers = replace.every(r => Array.isArray(r));
|
|
218
|
+
const hasMultipleReplacers = replace.every((r) => Array.isArray(r));
|
|
208
219
|
const replacers = hasMultipleReplacers
|
|
209
220
|
? replace
|
|
210
221
|
: [replace];
|
|
211
|
-
if (replacers.some(r => Array.isArray(r) && r.length !== 2)) {
|
|
222
|
+
if (replacers.some((r) => Array.isArray(r) && r.length !== 2)) {
|
|
212
223
|
throw new Error('Replacers need to have a searchValue and a replaceValue');
|
|
213
224
|
}
|
|
214
225
|
for (const replacer of replacers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
|
|
5
5
|
"description": "WebdriverIO Assertion Library",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,30 +58,30 @@
|
|
|
58
58
|
"prepare": "husky install"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@types/debug": "^4.1.
|
|
62
|
-
"@types/jest": "^29.5.
|
|
63
|
-
"@types/lodash.isequal": "^4.5.
|
|
64
|
-
"@types/node": "^20.
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
66
|
-
"@typescript-eslint/parser": "^6.
|
|
67
|
-
"@vitest/coverage-v8": "^0.34.
|
|
68
|
-
"@wdio/globals": "^8.
|
|
61
|
+
"@types/debug": "^4.1.12",
|
|
62
|
+
"@types/jest": "^29.5.8",
|
|
63
|
+
"@types/lodash.isequal": "^4.5.8",
|
|
64
|
+
"@types/node": "^20.9.0",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
66
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
67
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
68
|
+
"@wdio/globals": "^8.22.1",
|
|
69
69
|
"c8": "^8.0.1",
|
|
70
|
-
"eslint": "^8.
|
|
71
|
-
"eslint-plugin-import": "^2.
|
|
72
|
-
"eslint-plugin-unicorn": "^
|
|
70
|
+
"eslint": "^8.53.0",
|
|
71
|
+
"eslint-plugin-import": "^2.29.0",
|
|
72
|
+
"eslint-plugin-unicorn": "^49.0.0",
|
|
73
73
|
"husky": "^8.0.3",
|
|
74
74
|
"npm-run-all": "^4.1.5",
|
|
75
|
-
"release-it": "^16.1
|
|
76
|
-
"rimraf": "^5.0.
|
|
75
|
+
"release-it": "^16.2.1",
|
|
76
|
+
"rimraf": "^5.0.5",
|
|
77
77
|
"shelljs": "^0.8.5",
|
|
78
78
|
"typescript": "^5.2.2",
|
|
79
|
-
"vitest": "0.34.
|
|
80
|
-
"webdriverio": "
|
|
79
|
+
"vitest": "0.34.6",
|
|
80
|
+
"webdriverio": "8.22.1"
|
|
81
81
|
},
|
|
82
82
|
"optionalDependencies": {
|
|
83
|
-
"@wdio/globals": "^8.
|
|
84
|
-
"webdriverio": "^8.
|
|
83
|
+
"@wdio/globals": "^8.22.1",
|
|
84
|
+
"webdriverio": "^8.22.1"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"expect": "^29.7.0",
|
|
@@ -1,469 +1,450 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
| ExpectWebdriverIO.JsonCompatible
|
|
449
|
-
| ExpectWebdriverIO.PartialMatcher
|
|
450
|
-
| ((r: string | undefined) => boolean)
|
|
451
|
-
response?:
|
|
452
|
-
| string
|
|
453
|
-
| ExpectWebdriverIO.JsonCompatible
|
|
454
|
-
| ExpectWebdriverIO.PartialMatcher
|
|
455
|
-
| ((r: string) => boolean)
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
type jsonPrimitive = string | number | boolean | null
|
|
459
|
-
type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
|
|
460
|
-
type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
|
|
461
|
-
type JsonCompatible = jsonObject | jsonArray
|
|
462
|
-
|
|
463
|
-
interface PartialMatcher {
|
|
464
|
-
sample?: any
|
|
465
|
-
asymmetricMatch?(...args: any[]): boolean
|
|
466
|
-
}
|
|
1
|
+
declare namespace ExpectWebdriverIO {
|
|
2
|
+
function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
|
|
3
|
+
actual: T
|
|
4
|
+
): Matchers<R, T>
|
|
5
|
+
function setOptions(options: DefaultOptions): void
|
|
6
|
+
function getConfig(): any
|
|
7
|
+
const matchers: Record<
|
|
8
|
+
string,
|
|
9
|
+
(
|
|
10
|
+
actual: any,
|
|
11
|
+
...expected: any[]
|
|
12
|
+
) => Promise<{
|
|
13
|
+
pass: boolean
|
|
14
|
+
message(): string
|
|
15
|
+
}>
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
interface DefaultOptions {
|
|
19
|
+
/**
|
|
20
|
+
* time in ms to wait for expectation to succeed. Default: 3000
|
|
21
|
+
*/
|
|
22
|
+
wait?: number
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* interval between attempts. Default: 100
|
|
26
|
+
*/
|
|
27
|
+
interval?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface CommandOptions extends DefaultOptions {
|
|
31
|
+
/**
|
|
32
|
+
* user message to prepend before assertion error
|
|
33
|
+
*/
|
|
34
|
+
message?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface HTMLOptions extends StringOptions {
|
|
38
|
+
/**
|
|
39
|
+
* return the HTML with the selector tag included
|
|
40
|
+
*/
|
|
41
|
+
includeSelectorTag?: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface StringOptions extends CommandOptions {
|
|
45
|
+
/**
|
|
46
|
+
* apply `toLowerCase` to both actual and expected values
|
|
47
|
+
*/
|
|
48
|
+
ignoreCase?: boolean
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* apply `trim` to actual value
|
|
52
|
+
*/
|
|
53
|
+
trim?: boolean
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* expect actual value to contain expected value.
|
|
57
|
+
* Otherwise strict equal
|
|
58
|
+
*/
|
|
59
|
+
containing?: boolean
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* expect actual value to start with the expected value
|
|
63
|
+
* Otherwise strict equal
|
|
64
|
+
*/
|
|
65
|
+
atStart?: boolean
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* expect actual value to end with the expected value
|
|
69
|
+
* Otherwise strict equal
|
|
70
|
+
*/
|
|
71
|
+
atEnd?: boolean
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* expect actual value to have the expected value at the given index (index starts at 0 not 1)
|
|
75
|
+
* Otherwise strict equal
|
|
76
|
+
*/
|
|
77
|
+
atIndex?: number
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* replace the actual value (example: strip newlines from the value) and expect it to match the expected value
|
|
81
|
+
* Otherwise strict equal
|
|
82
|
+
*/
|
|
83
|
+
replace?: [string | RegExp, string | Function] | Array<[string | RegExp, string | Function]>
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* might be helpful to force converting property value to string
|
|
87
|
+
*/
|
|
88
|
+
asString?: boolean
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface NumberOptions extends CommandOptions {
|
|
92
|
+
/**
|
|
93
|
+
* equals
|
|
94
|
+
*/
|
|
95
|
+
eq?: number
|
|
96
|
+
/**
|
|
97
|
+
* less than or equals
|
|
98
|
+
*/
|
|
99
|
+
lte?: number
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* greater than or equals
|
|
103
|
+
*/
|
|
104
|
+
gte?: number
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
+
interface Matchers<R, T> {
|
|
109
|
+
// ===== $ or $$ =====
|
|
110
|
+
/**
|
|
111
|
+
* `WebdriverIO.Element` -> `isDisplayed`
|
|
112
|
+
*/
|
|
113
|
+
toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* `WebdriverIO.Element` -> `isExisting`
|
|
117
|
+
*/
|
|
118
|
+
toExist(options?: ExpectWebdriverIO.CommandOptions): R
|
|
119
|
+
/**
|
|
120
|
+
* `WebdriverIO.Element` -> `isExisting`
|
|
121
|
+
*/
|
|
122
|
+
toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
|
|
123
|
+
/**
|
|
124
|
+
* `WebdriverIO.Element` -> `isExisting`
|
|
125
|
+
*/
|
|
126
|
+
toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* `WebdriverIO.Element` -> `getAttribute`
|
|
130
|
+
*/
|
|
131
|
+
toHaveAttribute(
|
|
132
|
+
attribute: string,
|
|
133
|
+
value?: string | RegExp,
|
|
134
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
135
|
+
): R
|
|
136
|
+
/**
|
|
137
|
+
* `WebdriverIO.Element` -> `getAttribute`
|
|
138
|
+
*/
|
|
139
|
+
toHaveAttr(attribute: string, value?: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* `WebdriverIO.Element` -> `getAttribute`
|
|
143
|
+
* Element's attribute includes the value.
|
|
144
|
+
*/
|
|
145
|
+
toHaveAttributeContaining(
|
|
146
|
+
attribute: string,
|
|
147
|
+
contains: string | RegExp,
|
|
148
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
149
|
+
): R
|
|
150
|
+
/**
|
|
151
|
+
* `WebdriverIO.Element` -> `getAttribute`
|
|
152
|
+
* Element's attribute includes the value.
|
|
153
|
+
*/
|
|
154
|
+
toHaveAttrContaining(
|
|
155
|
+
attribute: string,
|
|
156
|
+
contains: string | RegExp,
|
|
157
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
158
|
+
): R
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* `WebdriverIO.Element` -> `getAttribute` class
|
|
162
|
+
* @deprecated since v1.3.1 - use `toHaveElementClass` instead.
|
|
163
|
+
*/
|
|
164
|
+
toHaveClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* `WebdriverIO.Element` -> `getAttribute` class
|
|
168
|
+
*/
|
|
169
|
+
toHaveElementClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* `WebdriverIO.Element` -> `getAttribute` class
|
|
173
|
+
* @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
|
|
174
|
+
* Element's class includes the className.
|
|
175
|
+
*/
|
|
176
|
+
toHaveClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* `WebdriverIO.Element` -> `getAttribute` class
|
|
180
|
+
* Element's class includes the className.
|
|
181
|
+
*/
|
|
182
|
+
toHaveElementClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* `WebdriverIO.Element` -> `getProperty`
|
|
186
|
+
*/
|
|
187
|
+
toHaveElementProperty(
|
|
188
|
+
property: string | RegExp,
|
|
189
|
+
value?: any,
|
|
190
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
191
|
+
): R
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* `WebdriverIO.Element` -> `getProperty` value
|
|
195
|
+
*/
|
|
196
|
+
toHaveValue(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
197
|
+
/**
|
|
198
|
+
* `WebdriverIO.Element` -> `getProperty` value
|
|
199
|
+
* Element's value includes the value.
|
|
200
|
+
*/
|
|
201
|
+
toHaveValueContaining(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* `WebdriverIO.Element` -> `isClickable`
|
|
205
|
+
*/
|
|
206
|
+
toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* `WebdriverIO.Element` -> `!isEnabled`
|
|
210
|
+
*/
|
|
211
|
+
toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* `WebdriverIO.Element` -> `isDisplayedInViewport`
|
|
215
|
+
*/
|
|
216
|
+
toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* `WebdriverIO.Element` -> `isEnabled`
|
|
220
|
+
*/
|
|
221
|
+
toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* `WebdriverIO.Element` -> `isFocused`
|
|
225
|
+
*/
|
|
226
|
+
toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* `WebdriverIO.Element` -> `isSelected`
|
|
230
|
+
*/
|
|
231
|
+
toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* `WebdriverIO.Element` -> `isSelected`
|
|
235
|
+
*/
|
|
236
|
+
toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* `WebdriverIO.Element` -> `$$('./*').length`
|
|
240
|
+
* supports less / greater then or equals to be passed in options
|
|
241
|
+
*/
|
|
242
|
+
toHaveChildren(
|
|
243
|
+
size?: number | ExpectWebdriverIO.NumberOptions,
|
|
244
|
+
options?: ExpectWebdriverIO.NumberOptions
|
|
245
|
+
): R
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* `WebdriverIO.Element` -> `getAttribute` href
|
|
249
|
+
*/
|
|
250
|
+
toHaveHref(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
251
|
+
/**
|
|
252
|
+
* `WebdriverIO.Element` -> `getAttribute` href
|
|
253
|
+
*/
|
|
254
|
+
toHaveLink(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* `WebdriverIO.Element` -> `getAttribute` href
|
|
258
|
+
* Element's href includes the value provided
|
|
259
|
+
*/
|
|
260
|
+
toHaveHrefContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
261
|
+
/**
|
|
262
|
+
* `WebdriverIO.Element` -> `getAttribute` href
|
|
263
|
+
* Element's href includes the value provided
|
|
264
|
+
*/
|
|
265
|
+
toHaveLinkContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* `WebdriverIO.Element` -> `getProperty` value
|
|
269
|
+
*/
|
|
270
|
+
toHaveId(id: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* `WebdriverIO.Element` -> `getText`
|
|
274
|
+
* Element's text equals the text provided
|
|
275
|
+
*/
|
|
276
|
+
toHaveText(
|
|
277
|
+
text: string | RegExp | Array<string | RegExp>,
|
|
278
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
279
|
+
): R
|
|
280
|
+
/**
|
|
281
|
+
* `WebdriverIO.Element` -> `getText`
|
|
282
|
+
* Element's text includes the text provided
|
|
283
|
+
*/
|
|
284
|
+
toHaveTextContaining(
|
|
285
|
+
text: string | RegExp | Array<string | RegExp>,
|
|
286
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
287
|
+
): R
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* `WebdriverIO.Element` -> `getHTML`
|
|
291
|
+
* Element's html equals the html provided
|
|
292
|
+
*/
|
|
293
|
+
toHaveHTML(html: string | RegExp | Array<string | RegExp>, options?: ExpectWebdriverIO.HTMLOptions): R
|
|
294
|
+
/**
|
|
295
|
+
* `WebdriverIO.Element` -> `getHTML`
|
|
296
|
+
* Element's html includes the html provided
|
|
297
|
+
*/
|
|
298
|
+
toHaveHTMLContaining(
|
|
299
|
+
html: string | RegExp | Array<string | RegExp>,
|
|
300
|
+
options?: ExpectWebdriverIO.HTMLOptions
|
|
301
|
+
): R
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* `WebdriverIO.Element` -> `getComputedLabel`
|
|
305
|
+
* Element's computed label equals the computed label provided
|
|
306
|
+
*/
|
|
307
|
+
toHaveComputedLabel(
|
|
308
|
+
computedLabel: string | RegExp | Array<string | RegExp>,
|
|
309
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
310
|
+
): R
|
|
311
|
+
/**
|
|
312
|
+
* `WebdriverIO.Element` -> `getComputedLabel`
|
|
313
|
+
* Element's computed label includes the computed label provided
|
|
314
|
+
*/
|
|
315
|
+
toHaveComputedLabelContaining(
|
|
316
|
+
computedLabel: string | RegExp | Array<string | RegExp>,
|
|
317
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
318
|
+
): R
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* `WebdriverIO.Element` -> `getComputedRole`
|
|
322
|
+
* Element's computed role equals the computed role provided
|
|
323
|
+
*/
|
|
324
|
+
toHaveComputedRole(
|
|
325
|
+
computedRole: string | RegExp | Array<string | RegExp>,
|
|
326
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
327
|
+
): R
|
|
328
|
+
/**
|
|
329
|
+
* `WebdriverIO.Element` -> `getComputedRole`
|
|
330
|
+
* Element's computed role includes the computed role provided
|
|
331
|
+
*/
|
|
332
|
+
toHaveComputedRoleContaining(
|
|
333
|
+
computedRole: string | RegExp | Array<string | RegExp>,
|
|
334
|
+
options?: ExpectWebdriverIO.StringOptions
|
|
335
|
+
): R
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* `WebdriverIO.Element` -> `getSize('width')`
|
|
339
|
+
* Element's width equals the width provided
|
|
340
|
+
*/
|
|
341
|
+
toHaveWidth(width: number, options?: ExpectWebdriverIO.CommandOptions): R
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* `WebdriverIO.Element` -> `getSize('height')`
|
|
345
|
+
* Element's height equals the height provided
|
|
346
|
+
*/
|
|
347
|
+
toHaveHeight(height: number, options?: ExpectWebdriverIO.CommandOptions): R
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* `WebdriverIO.Element` -> `getSize()`
|
|
351
|
+
* Element's size equals the size provided
|
|
352
|
+
*/
|
|
353
|
+
toHaveHeight(size: { height: number; width: number }, options?: ExpectWebdriverIO.CommandOptions): R
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* `WebdriverIO.Element` -> `getAttribute("style")`
|
|
357
|
+
*/
|
|
358
|
+
toHaveStyle(style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions): R
|
|
359
|
+
|
|
360
|
+
// ===== browser only =====
|
|
361
|
+
/**
|
|
362
|
+
* `WebdriverIO.Browser` -> `getUrl`
|
|
363
|
+
*/
|
|
364
|
+
toHaveUrl(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
365
|
+
|
|
366
|
+
// ===== browser only =====
|
|
367
|
+
/**
|
|
368
|
+
* `WebdriverIO.Browser` -> `getUrl`
|
|
369
|
+
* Browser's url includes the provided text
|
|
370
|
+
*/
|
|
371
|
+
toHaveUrlContaining(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* `WebdriverIO.Browser` -> `getTitle`
|
|
375
|
+
*/
|
|
376
|
+
toHaveTitle(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
377
|
+
|
|
378
|
+
// ===== browser only =====
|
|
379
|
+
/**
|
|
380
|
+
* `WebdriverIO.Browser` -> `getTitle`
|
|
381
|
+
* Browser's title includes the provided text
|
|
382
|
+
*/
|
|
383
|
+
toHaveTitleContaining(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
|
|
384
|
+
|
|
385
|
+
// ===== $$ only =====
|
|
386
|
+
/**
|
|
387
|
+
* `WebdriverIO.ElementArray` -> `$$('...').length`
|
|
388
|
+
* supports less / greater then or equals to be passed in options
|
|
389
|
+
*/
|
|
390
|
+
toBeElementsArrayOfSize(
|
|
391
|
+
size: number | ExpectWebdriverIO.NumberOptions,
|
|
392
|
+
options?: ExpectWebdriverIO.NumberOptions
|
|
393
|
+
): R
|
|
394
|
+
|
|
395
|
+
// ==== network mock ====
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Check that `WebdriverIO.Mock` was called
|
|
399
|
+
*/
|
|
400
|
+
toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Check that `WebdriverIO.Mock` was called N times
|
|
404
|
+
*/
|
|
405
|
+
toBeRequestedTimes(
|
|
406
|
+
times: number | ExpectWebdriverIO.NumberOptions,
|
|
407
|
+
options?: ExpectWebdriverIO.NumberOptions
|
|
408
|
+
): R
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Check that `WebdriverIO.Mock` was called with the specific parameters
|
|
412
|
+
*/
|
|
413
|
+
toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
type RequestedWith = {
|
|
417
|
+
url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
|
|
418
|
+
method?: string | Array<string>
|
|
419
|
+
statusCode?: number | Array<number>
|
|
420
|
+
requestHeaders?:
|
|
421
|
+
| Record<string, string>
|
|
422
|
+
| ExpectWebdriverIO.PartialMatcher
|
|
423
|
+
| ((headers: Record<string, string>) => boolean)
|
|
424
|
+
responseHeaders?:
|
|
425
|
+
| Record<string, string>
|
|
426
|
+
| ExpectWebdriverIO.PartialMatcher
|
|
427
|
+
| ((headers: Record<string, string>) => boolean)
|
|
428
|
+
postData?:
|
|
429
|
+
| string
|
|
430
|
+
| ExpectWebdriverIO.JsonCompatible
|
|
431
|
+
| ExpectWebdriverIO.PartialMatcher
|
|
432
|
+
| ((r: string | undefined) => boolean)
|
|
433
|
+
response?:
|
|
434
|
+
| string
|
|
435
|
+
| ExpectWebdriverIO.JsonCompatible
|
|
436
|
+
| ExpectWebdriverIO.PartialMatcher
|
|
437
|
+
| ((r: string) => boolean)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
type jsonPrimitive = string | number | boolean | null
|
|
441
|
+
type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
|
|
442
|
+
type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
|
|
443
|
+
type JsonCompatible = jsonObject | jsonArray
|
|
444
|
+
|
|
445
|
+
interface PartialMatcher {
|
|
446
|
+
sample?: any
|
|
447
|
+
asymmetricMatch?(...args: any[]): boolean
|
|
467
448
|
}
|
|
468
449
|
}
|
|
469
450
|
|