expect-webdriverio 0.2.0 → 1.0.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/README.md +413 -2
- package/lib/utils.js +4 -1
- package/package.json +23 -17
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# expect-webdriverio
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.org/webdriverio/expect-webdriverio) [](https://codecov.io/gh/webdriverio/expect-webdriverio)
|
|
4
4
|
|
|
5
5
|
###### [TypeScript / JS Autocomplete](/docs/Types.md) | [Examples](docs/Examples.md) | [Extending Matchers](/docs/Extend.md)
|
|
6
6
|
|
|
@@ -39,7 +39,7 @@ See more [Examples](docs/Examples.md)
|
|
|
39
39
|
|
|
40
40
|
## API
|
|
41
41
|
|
|
42
|
-
See available [Matchers](https://github.com/
|
|
42
|
+
See available [Matchers](https://github.com/webdriverio/expect-webdriverio/blob/master/types/expect-webdriverio.d.ts#L64)
|
|
43
43
|
|
|
44
44
|
Besides of the `expect-webdriverio` matchers you can use builtin Jest's [expect](https://jestjs.io/docs/en/expect) assertions or [expect/expectAsync](https://jasmine.github.io/api/3.5/global.html#expect) for Jasmine.
|
|
45
45
|
|
|
@@ -59,6 +59,417 @@ beforeSession () { // before hook works as well
|
|
|
59
59
|
},
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
### Matcher Options
|
|
63
|
+
|
|
64
|
+
Every matcher can take several options that allows you to modify the assertion:
|
|
65
|
+
|
|
66
|
+
##### Command Options
|
|
67
|
+
|
|
68
|
+
| Name | Type | Details |
|
|
69
|
+
| ---- | ---- | ------- |
|
|
70
|
+
| <code><var>wait</var></code> | number | time in ms to wait for expectation to succeed. Default: `3000` |
|
|
71
|
+
| <code><var>interval</var></code> | number | interval between attempts. Default: `100` |
|
|
72
|
+
| <code><var>message</var></code> | string | user message to prepend before assertion error |
|
|
73
|
+
|
|
74
|
+
##### String Options
|
|
75
|
+
|
|
76
|
+
This options can be applied in addition to the command options when strings are being asserted.
|
|
77
|
+
|
|
78
|
+
| Name | Type | Details |
|
|
79
|
+
| ---- | ---- | ------- |
|
|
80
|
+
| <code><var>ignoreCase</var></code> | boolean | apply `toLowerCase` to both actual and expected values |
|
|
81
|
+
| <code><var>trim</var></code> | boolean | apply `trim` to actual value |
|
|
82
|
+
| <code><var>containing</var></code> | boolean | expect actual value to contain expected value, otherwise strict equal. |
|
|
83
|
+
| <code><var>asString</var></code> | boolean | might be helpful to force converting property value to string |
|
|
84
|
+
|
|
85
|
+
##### Number Options
|
|
86
|
+
|
|
87
|
+
This options can be applied in addition to the command options when numbers are being asserted.
|
|
88
|
+
|
|
89
|
+
| Name | Type | Details |
|
|
90
|
+
| ---- | ---- | ------- |
|
|
91
|
+
| <code><var>eq</var></code> | number | equals |
|
|
92
|
+
| <code><var>lte</var></code> | number | less then equals |
|
|
93
|
+
| <code><var>gte</var></code> | number | greater than or equals |
|
|
94
|
+
|
|
95
|
+
## Browser Matchers
|
|
96
|
+
|
|
97
|
+
### toHaveUrl
|
|
98
|
+
|
|
99
|
+
Checks if browser is on a specifc page.
|
|
100
|
+
|
|
101
|
+
##### Usage
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
browser.url('https://webdriver.io/')
|
|
105
|
+
expect(browser).toHaveUrl('https://webdriver.io')
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### toHaveTitle
|
|
109
|
+
|
|
110
|
+
Checks if website has a specific title.
|
|
111
|
+
|
|
112
|
+
##### Usage
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
browser.url('https://webdriver.io/')
|
|
116
|
+
expect(browser).toHaveTitle('WebdriverIO · Next-gen WebDriver test framework for Node.js')
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Element Matchers
|
|
120
|
+
|
|
121
|
+
### toBeDisplayed
|
|
122
|
+
|
|
123
|
+
Calls [`isDisplayed`](/docs/api/element/isDisplayed.html) on given element.
|
|
124
|
+
|
|
125
|
+
##### Usage
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
const elem = $('#someElem')
|
|
129
|
+
expect(elem).toBeDisplayed()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### toBeVisible
|
|
133
|
+
|
|
134
|
+
Same as `toBeDisplayed`.
|
|
135
|
+
|
|
136
|
+
##### Usage
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
const elem = $('#someElem')
|
|
140
|
+
expect(elem).toBeVisible()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### toExist
|
|
144
|
+
|
|
145
|
+
Calls [`isExisting`](/docs/api/element/isExisting.html) on given element.
|
|
146
|
+
|
|
147
|
+
##### Usage
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
const elem = $('#someElem')
|
|
151
|
+
expect(elem).toExist()
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### toBePresent
|
|
155
|
+
|
|
156
|
+
Same as `toExist`.
|
|
157
|
+
|
|
158
|
+
##### Usage
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
const elem = $('#someElem')
|
|
162
|
+
expect(elem).toBePresent()
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### toBeExisting
|
|
166
|
+
|
|
167
|
+
Same as `toExist`.
|
|
168
|
+
|
|
169
|
+
##### Usage
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
const elem = $('#someElem')
|
|
173
|
+
expect(elem).toBeExisting()
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### toBeFocused
|
|
177
|
+
|
|
178
|
+
Checks if element has focus. This assertion only works in a web context.
|
|
179
|
+
|
|
180
|
+
##### Usage
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
const elem = $('#someElem')
|
|
184
|
+
expect(elem).toBeFocused()
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### toHaveAttribute
|
|
188
|
+
|
|
189
|
+
Checks if an element has a certain attribute with a specific value.
|
|
190
|
+
|
|
191
|
+
##### Usage
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
const myInput = $('input')
|
|
195
|
+
expect(myInput).toHaveAttribute('class', 'form-control')
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### toHaveAttr
|
|
199
|
+
|
|
200
|
+
Same as `toHaveAttribute`.
|
|
201
|
+
|
|
202
|
+
##### Usage
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
const myInput = $('input')
|
|
206
|
+
expect(myInput).toHaveAttr('class', 'form-control')
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### toHaveAttributeContaining
|
|
210
|
+
|
|
211
|
+
Checks if an element has a certain attribute that contains a value.
|
|
212
|
+
|
|
213
|
+
##### Usage
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
const myInput = $('input')
|
|
217
|
+
expect(myInput).toHaveAttributeContaining('class', 'form')
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### toHaveAttrContaining
|
|
221
|
+
|
|
222
|
+
Same as `toHaveAttributeContaining`.
|
|
223
|
+
|
|
224
|
+
##### Usage
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
const myInput = $('input')
|
|
228
|
+
expect(myInput).toHaveAttrContaining('class', 'form')
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### toHaveClass
|
|
232
|
+
|
|
233
|
+
Checks if an element has a certain class name.
|
|
234
|
+
|
|
235
|
+
##### Usage
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
const myInput = $('input')
|
|
239
|
+
expect(myInput).toHaveClass('form-control', { message: 'Not a form control!', })
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### toHaveClassContaining
|
|
243
|
+
|
|
244
|
+
Checks if an element has a certain class name that contains provided value.
|
|
245
|
+
|
|
246
|
+
##### Usage
|
|
247
|
+
|
|
248
|
+
```js
|
|
249
|
+
const myInput = $('input')
|
|
250
|
+
expect(myInput).toHaveClassContaining('form')
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### toHaveProperty
|
|
254
|
+
|
|
255
|
+
Checks if an element has a certain property.
|
|
256
|
+
|
|
257
|
+
##### Usage
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
const elem = $('#elem')
|
|
261
|
+
expect(elem).toHaveProperty('height', 23)
|
|
262
|
+
expect(elem).not.toHaveProperty('height', 0)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### toHaveValue
|
|
266
|
+
|
|
267
|
+
Checks if an input element has a certain value.
|
|
268
|
+
|
|
269
|
+
##### Usage
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
const myInput = $('input')
|
|
273
|
+
expect(myInput).toHaveValue('user', { ignoreCase: true })
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### toHaveValueContaining
|
|
277
|
+
|
|
278
|
+
Checks if an input element contains a certain value.
|
|
279
|
+
|
|
280
|
+
##### Usage
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
const myInput = $('input')
|
|
284
|
+
expect(myInput).toHaveValue('us')
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### toBeClickable
|
|
288
|
+
|
|
289
|
+
Checks if an element can be clicked by calling [`isClickable`](/docs/api/element/isClickable.html) on the element.
|
|
290
|
+
|
|
291
|
+
##### Usage
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
const elem = $('#elem')
|
|
295
|
+
expect(elem).toBeClickable()
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### toBeDisabled
|
|
299
|
+
|
|
300
|
+
Checks if an element is disabled by calling [`isEnabled`](/docs/api/element/isEnabled.html) on the element.
|
|
301
|
+
|
|
302
|
+
##### Usage
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
const elem = $('#elem')
|
|
306
|
+
expect(elem).toBeDisabled()
|
|
307
|
+
// same as
|
|
308
|
+
expect(elem).not.toBeEnabled()
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### toBeEnabled
|
|
312
|
+
|
|
313
|
+
Checks if an element is enabled by calling [`isEnabled`](/docs/api/element/isEnabled.html) on the element.
|
|
314
|
+
|
|
315
|
+
##### Usage
|
|
316
|
+
|
|
317
|
+
```js
|
|
318
|
+
const elem = $('#elem')
|
|
319
|
+
expect(elem).toBeEnabled()
|
|
320
|
+
// same as
|
|
321
|
+
expect(elem).not.toBeDisabled()
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### toBeSelected
|
|
325
|
+
|
|
326
|
+
Checks if an element is enabled by calling [`isSelected`](/docs/api/element/isSelected.html) on the element.
|
|
327
|
+
|
|
328
|
+
##### Usage
|
|
329
|
+
|
|
330
|
+
```js
|
|
331
|
+
const elem = $('#elem')
|
|
332
|
+
expect(elem).toBeSelected()
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### toBeChecked
|
|
336
|
+
|
|
337
|
+
Same as `toBeSelected`.
|
|
338
|
+
|
|
339
|
+
##### Usage
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
const elem = $('#elem')
|
|
343
|
+
expect(elem).toBeChecked()
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### toHaveHref
|
|
347
|
+
|
|
348
|
+
Checks if link element has a specifc link target.
|
|
349
|
+
|
|
350
|
+
##### Usage
|
|
351
|
+
|
|
352
|
+
```js
|
|
353
|
+
const link = $('a')
|
|
354
|
+
expect(link).toHaveHref('https://webdriver.io')
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### toHaveLink
|
|
358
|
+
|
|
359
|
+
Same as `toHaveHref`.
|
|
360
|
+
|
|
361
|
+
##### Usage
|
|
362
|
+
|
|
363
|
+
```js
|
|
364
|
+
const link = $('a')
|
|
365
|
+
expect(link).toHaveLink('https://webdriver.io')
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### toHaveHrefContaining
|
|
369
|
+
|
|
370
|
+
Checks if link element contains a specifc link target.
|
|
371
|
+
|
|
372
|
+
##### Usage
|
|
373
|
+
|
|
374
|
+
```js
|
|
375
|
+
const link = $('a')
|
|
376
|
+
expect(link).toHaveHrefContaining('webdriver.io')
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### toHaveLinkContaining
|
|
380
|
+
|
|
381
|
+
Same as `toHaveHrefContaining`.
|
|
382
|
+
|
|
383
|
+
##### Usage
|
|
384
|
+
|
|
385
|
+
```js
|
|
386
|
+
const link = $('a')
|
|
387
|
+
expect(link).toHaveLinkContaining('webdriver.io')
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### toHaveId
|
|
391
|
+
|
|
392
|
+
Checks if element has a specific `id` attribute.
|
|
393
|
+
|
|
394
|
+
##### Usage
|
|
395
|
+
|
|
396
|
+
```js
|
|
397
|
+
const elem = $('#elem')
|
|
398
|
+
expect(elem).toHaveId('elem')
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### toHaveText
|
|
402
|
+
|
|
403
|
+
Checks if element has a specific text.
|
|
404
|
+
|
|
405
|
+
##### Usage
|
|
406
|
+
|
|
407
|
+
```js
|
|
408
|
+
browser.url('https://webdriver.io/')
|
|
409
|
+
const elem = $('.tagline')
|
|
410
|
+
expect(elem).toHaveText('Next-gen WebDriver test framework for Node.js')
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### toHaveTextContaining
|
|
414
|
+
|
|
415
|
+
Checks if element contains a specific text.
|
|
416
|
+
|
|
417
|
+
##### Usage
|
|
418
|
+
|
|
419
|
+
```js
|
|
420
|
+
browser.url('https://webdriver.io/')
|
|
421
|
+
const elem = $('.tagline')
|
|
422
|
+
expect(elem).toHaveTextContaining('WebDriver test framework')
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### toBeDisplayedInViewport
|
|
426
|
+
|
|
427
|
+
Checks if an element is within the viewport by calling [`isDisplayedInViewport`](/docs/api/element/isDisplayedInViewport.html) on the element.
|
|
428
|
+
|
|
429
|
+
##### Usage
|
|
430
|
+
|
|
431
|
+
```js
|
|
432
|
+
const elem = $('#elem')
|
|
433
|
+
expect(elem).toBeDisplayedInViewport()
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### toBeVisibleInViewport
|
|
437
|
+
|
|
438
|
+
Same as `toBeDisplayedInViewport`.
|
|
439
|
+
|
|
440
|
+
##### Usage
|
|
441
|
+
|
|
442
|
+
```js
|
|
443
|
+
const elem = $('#elem')
|
|
444
|
+
expect(elem).toBeVisibleInViewport()
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### toHaveChildren
|
|
448
|
+
|
|
449
|
+
Checks amount of fetched elements using [`$$`](/docs/api/browser/$$.html) command.
|
|
450
|
+
|
|
451
|
+
##### Usage
|
|
452
|
+
|
|
453
|
+
```js
|
|
454
|
+
const elems = $$('div')
|
|
455
|
+
expect(elems).toHaveChildren({ gte: 10 })
|
|
456
|
+
// same as
|
|
457
|
+
assert.ok(elems.length >= 10)
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### toBeElementsArrayOfSize
|
|
461
|
+
|
|
462
|
+
Same as `toHaveChildren`.
|
|
463
|
+
|
|
464
|
+
##### Usage
|
|
465
|
+
|
|
466
|
+
```js
|
|
467
|
+
const elems = $$('div')
|
|
468
|
+
expect(elems).toBeElementsArrayOfSize({ gte: 10 })
|
|
469
|
+
// same as
|
|
470
|
+
assert.ok(elems.length >= 10)
|
|
471
|
+
```
|
|
472
|
+
|
|
62
473
|
## Error messages
|
|
63
474
|
|
|
64
475
|
Error messages are informative out of the box and contain:
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"build": "run-s clean compile",
|
|
8
8
|
"clean": "rimraf ./lib",
|
|
9
9
|
"compile": "tsc --build tsconfig.build.json",
|
|
10
|
-
"
|
|
10
|
+
"release": "npm run release:patch",
|
|
11
|
+
"release:patch": "np patch",
|
|
12
|
+
"release:minor": "np minor",
|
|
13
|
+
"release:major": "np major",
|
|
14
|
+
"test": "jest"
|
|
11
15
|
},
|
|
12
16
|
"repository": {
|
|
13
17
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/
|
|
18
|
+
"url": "git+https://github.com/webdriverio/expect-webdriverio.git"
|
|
15
19
|
},
|
|
16
20
|
"keywords": [
|
|
17
21
|
"expect-webdriverio",
|
|
@@ -20,22 +24,23 @@
|
|
|
20
24
|
"wdio"
|
|
21
25
|
],
|
|
22
26
|
"author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
|
|
23
|
-
"license": "
|
|
27
|
+
"license": "MIT",
|
|
24
28
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/
|
|
29
|
+
"url": "https://github.com/webdriverio/expect-webdriverio/issues"
|
|
26
30
|
},
|
|
27
|
-
"homepage": "https://github.com/
|
|
31
|
+
"homepage": "https://github.com/webdriverio/expect-webdriverio#readme",
|
|
28
32
|
"devDependencies": {
|
|
29
|
-
"@types/jest": "^
|
|
30
|
-
"@types/node": "^12.12.
|
|
31
|
-
"codecov": "^3.6.
|
|
32
|
-
"husky": "^4.
|
|
33
|
-
"jest": "^
|
|
33
|
+
"@types/jest": "^25.1.4",
|
|
34
|
+
"@types/node": "^12.12.31",
|
|
35
|
+
"codecov": "^3.6.5",
|
|
36
|
+
"husky": "^4.2.3",
|
|
37
|
+
"jest": "^25.2.2",
|
|
38
|
+
"np": "^6.2.0",
|
|
34
39
|
"npm-run-all": "^4.1.5",
|
|
35
|
-
"rimraf": "^3.0.
|
|
36
|
-
"ts-jest": "^
|
|
37
|
-
"typescript": "^3.
|
|
38
|
-
"webdriverio": "^
|
|
40
|
+
"rimraf": "^3.0.2",
|
|
41
|
+
"ts-jest": "^25.2.1",
|
|
42
|
+
"typescript": "^3.8.3",
|
|
43
|
+
"webdriverio": "^6.0.2"
|
|
39
44
|
},
|
|
40
45
|
"types": "types/jest-global.d.ts",
|
|
41
46
|
"husky": {
|
|
@@ -44,6 +49,7 @@
|
|
|
44
49
|
}
|
|
45
50
|
},
|
|
46
51
|
"dependencies": {
|
|
47
|
-
"
|
|
52
|
+
"expect": "^25.2.1",
|
|
53
|
+
"jest-matcher-utils": "^25.1.0"
|
|
48
54
|
}
|
|
49
55
|
}
|