codeceptjs 3.5.2 → 3.5.4-beta.1

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.
@@ -1,1258 +0,0 @@
1
- ---
2
- permalink: /helpers/Nightmare
3
- editLink: false
4
- sidebar: auto
5
- title: Nightmare
6
- ---
7
-
8
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
9
-
10
- ## Nightmare
11
-
12
- **Extends Helper**
13
-
14
- Nightmare helper wraps [Nightmare][1] library to provide
15
- fastest headless testing using Electron engine. Unlike Selenium-based drivers this uses
16
- Chromium-based browser with Electron with lots of client side scripts, thus should be less stable and
17
- less trusted.
18
-
19
- Requires `nightmare` package to be installed.
20
-
21
- ## Configuration
22
-
23
- This helper should be configured in codecept.conf.ts or codecept.conf.js
24
-
25
- - `url` - base url of website to be tested
26
- - `restart` - restart browser between tests.
27
- - `disableScreenshots` - don't save screenshot on failure.
28
- - `uniqueScreenshotNames` - option to prevent screenshot override if you have scenarios with the same name in different suites.
29
- - `fullPageScreenshots` - make full page screenshots on failure.
30
- - `keepBrowserState` - keep browser state between tests when `restart` set to false.
31
- - `keepCookies` - keep cookies between tests when `restart` set to false.
32
- - `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 500.
33
- - `waitForTimeout`: (optional) default wait* timeout in ms. Default: 1000.
34
- - `windowSize`: (optional) default window size. Set a dimension like `640x480`.
35
-
36
-
37
- - options from [Nightmare configuration][2]
38
-
39
- ## Methods
40
-
41
- ### Parameters
42
-
43
- - `config`
44
-
45
- ### _locate
46
-
47
- Locate elements by different locator types, including strict locator.
48
- Should be used in custom helpers.
49
-
50
- This method return promise with array of IDs of found elements.
51
- Actual elements can be accessed inside `evaluate` by using `codeceptjs.fetchElement()`
52
- client-side function:
53
-
54
- ```js
55
- // get an inner text of an element
56
-
57
- let browser = this.helpers['Nightmare'].browser;
58
- let value = this.helpers['Nightmare']._locate({name: 'password'}).then(function(els) {
59
- return browser.evaluate(function(el) {
60
- return codeceptjs.fetchElement(el).value;
61
- }, els[0]);
62
- });
63
- ```
64
-
65
- #### Parameters
66
-
67
- - `locator`
68
-
69
- ### amOnPage
70
-
71
- Opens a web page in a browser. Requires relative or absolute url.
72
- If url starts with `/`, opens a web page of a site defined in `url` config parameter.
73
-
74
- ```js
75
- I.amOnPage('/'); // opens main page of website
76
- I.amOnPage('https://github.com'); // opens github
77
- I.amOnPage('/login'); // opens a login page
78
- ```
79
-
80
- #### Parameters
81
-
82
- - `url` **[string][3]** url path or global url.
83
- - `headers` **[object][4]?** list of request headers can be passed
84
-
85
- Returns **void** automatically synchronized promise with recorder #!
86
-
87
- ### appendField
88
-
89
- Appends text to a input field or textarea.
90
- Field is located by name, label, CSS or XPath
91
-
92
- ```js
93
- I.appendField('#myTextField', 'appended');
94
- // typing secret
95
- I.appendField('password', secret('123456'));
96
- ```
97
-
98
- #### Parameters
99
-
100
- - `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator
101
- - `value` **[string][3]** text value to append.
102
- ⚠️ returns a _promise_ which is synchronized internally by recorder
103
-
104
- ### attachFile
105
-
106
- Attaches a file to element located by label, name, CSS or XPath
107
- Path to file is relative current codecept directory (where codecept.conf.ts or codecept.conf.js is located).
108
- File will be uploaded to remote system (if tests are running remotely).
109
-
110
- ```js
111
- I.attachFile('Avatar', 'data/avatar.jpg');
112
- I.attachFile('form input[name=avatar]', 'data/avatar.jpg');
113
- ```
114
-
115
- #### Parameters
116
-
117
- - `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator.
118
- - `pathToFile` **[string][3]** local file path relative to codecept.conf.ts or codecept.conf.js config file.
119
- ⚠️ returns a _promise_ which is synchronized internally by recorderDoesn't work if the Chromium DevTools panel is open (as Chromium allows only one attachment to the debugger at a time. [See more][5])
120
-
121
- ### checkOption
122
-
123
- Selects a checkbox or radio button.
124
- Element is located by label or name or CSS or XPath.
125
-
126
- The second parameter is a context (CSS or XPath locator) to narrow the search.
127
-
128
- ```js
129
- I.checkOption('#agree');
130
- I.checkOption('I Agree to Terms and Conditions');
131
- I.checkOption('agree', '//form');
132
- ```
133
-
134
- #### Parameters
135
-
136
- - `field` **([string][3] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator.
137
- - `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator.
138
- ⚠️ returns a _promise_ which is synchronized internally by recorder
139
-
140
- ### clearCookie
141
-
142
- Clears a cookie by name,
143
- if none provided clears all cookies.
144
-
145
- ```js
146
- I.clearCookie();
147
- I.clearCookie('test');
148
- ```
149
-
150
- #### Parameters
151
-
152
- - `cookie` **[string][3]?** (optional, `null` by default) cookie name
153
- ⚠️ returns a _promise_ which is synchronized internally by recorder
154
-
155
- ### clearField
156
-
157
- Clears a `<textarea>` or text `<input>` element's value.
158
-
159
- ```js
160
- I.clearField('Email');
161
- I.clearField('user[email]');
162
- I.clearField('#email');
163
- ```
164
-
165
- #### Parameters
166
-
167
- - `field`
168
- - `editable` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator.
169
- ⚠️ returns a _promise_ which is synchronized internally by recorder.
170
-
171
- ### click
172
-
173
- Perform a click on a link or a button, given by a locator.
174
- If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string.
175
- For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched.
176
- For images, the "alt" attribute and inner text of any parent links are searched.
177
-
178
- The second parameter is a context (CSS or XPath locator) to narrow the search.
179
-
180
- ```js
181
- // simple link
182
- I.click('Logout');
183
- // button of form
184
- I.click('Submit');
185
- // CSS button
186
- I.click('#form input[type=submit]');
187
- // XPath
188
- I.click('//form/*[@type=submit]');
189
- // link in context
190
- I.click('Logout', '#nav');
191
- // using strict locator
192
- I.click({css: 'nav a.login'});
193
- ```
194
-
195
- #### Parameters
196
-
197
- - `locator` **([string][3] | [object][4])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
198
- - `context` **([string][3]? | [object][4] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
199
- ⚠️ returns a _promise_ which is synchronized internally by recorder
200
-
201
- ### dontSee
202
-
203
- Opposite to `see`. Checks that a text is not present on a page.
204
- Use context parameter to narrow down the search.
205
-
206
- ```js
207
- I.dontSee('Login'); // assume we are already logged in.
208
- I.dontSee('Login', '.nav'); // no login inside .nav element
209
- ```
210
-
211
- #### Parameters
212
-
213
- - `text` **[string][3]** which is not present.
214
- - `context` **([string][3] | [object][4])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search.
215
- ⚠️ returns a _promise_ which is synchronized internally by recorder
216
-
217
- ### dontSeeCheckboxIsChecked
218
-
219
- Verifies that the specified checkbox is not checked.
220
-
221
- ```js
222
- I.dontSeeCheckboxIsChecked('#agree'); // located by ID
223
- I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label
224
- I.dontSeeCheckboxIsChecked('agree'); // located by name
225
- ```
226
-
227
- #### Parameters
228
-
229
- - `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
230
- ⚠️ returns a _promise_ which is synchronized internally by recorder
231
-
232
- ### dontSeeCookie
233
-
234
- Checks that cookie with given name does not exist.
235
-
236
- ```js
237
- I.dontSeeCookie('auth'); // no auth cookie
238
- ```
239
-
240
- #### Parameters
241
-
242
- - `name` **[string][3]** cookie name.
243
- ⚠️ returns a _promise_ which is synchronized internally by recorder
244
-
245
- ### dontSeeCurrentUrlEquals
246
-
247
- Checks that current url is not equal to provided one.
248
- If a relative url provided, a configured url will be prepended to it.
249
-
250
- ```js
251
- I.dontSeeCurrentUrlEquals('/login'); // relative url are ok
252
- I.dontSeeCurrentUrlEquals('http://mysite.com/login'); // absolute urls are also ok
253
- ```
254
-
255
- #### Parameters
256
-
257
- - `url` **[string][3]** value to check.
258
- ⚠️ returns a _promise_ which is synchronized internally by recorder
259
-
260
- ### dontSeeElement
261
-
262
- Opposite to `seeElement`. Checks that element is not visible (or in DOM)
263
-
264
- ```js
265
- I.dontSeeElement('.modal'); // modal is not shown
266
- ```
267
-
268
- #### Parameters
269
-
270
- - `locator` **([string][3] | [object][4])** located by CSS|XPath|Strict locator.
271
- ⚠️ returns a _promise_ which is synchronized internally by recorder
272
-
273
- ### dontSeeElementInDOM
274
-
275
- Opposite to `seeElementInDOM`. Checks that element is not on page.
276
-
277
- ```js
278
- I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not
279
- ```
280
-
281
- #### Parameters
282
-
283
- - `locator` **([string][3] | [object][4])** located by CSS|XPath|Strict locator.
284
- ⚠️ returns a _promise_ which is synchronized internally by recorder
285
-
286
- ### dontSeeInCurrentUrl
287
-
288
- Checks that current url does not contain a provided fragment.
289
-
290
- #### Parameters
291
-
292
- - `url` **[string][3]** value to check.
293
- ⚠️ returns a _promise_ which is synchronized internally by recorder
294
-
295
- ### dontSeeInField
296
-
297
- Checks that value of input field or textarea doesn't equal to given value
298
- Opposite to `seeInField`.
299
-
300
- ```js
301
- I.dontSeeInField('email', 'user@user.com'); // field by name
302
- I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS
303
- ```
304
-
305
- #### Parameters
306
-
307
- - `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
308
- - `value` **[string][3]** value to check.
309
- ⚠️ returns a _promise_ which is synchronized internally by recorder
310
-
311
- ### dontSeeInSource
312
-
313
- Checks that the current page does not contains the given string in its raw source code.
314
-
315
- ```js
316
- I.dontSeeInSource('<!--'); // no comments in source
317
- ```
318
-
319
- #### Parameters
320
-
321
- - `text`
322
- - `value` **[string][3]** to check.
323
- ⚠️ returns a _promise_ which is synchronized internally by recorder
324
-
325
- ### dontSeeInTitle
326
-
327
- Checks that title does not contain text.
328
-
329
- ```js
330
- I.dontSeeInTitle('Error');
331
- ```
332
-
333
- #### Parameters
334
-
335
- - `text` **[string][3]** value to check.
336
- ⚠️ returns a _promise_ which is synchronized internally by recorder
337
-
338
- ### doubleClick
339
-
340
- Performs a double-click on an element matched by link|button|label|CSS or XPath.
341
- Context can be specified as second parameter to narrow search.
342
-
343
- ```js
344
- I.doubleClick('Edit');
345
- I.doubleClick('Edit', '.actions');
346
- I.doubleClick({css: 'button.accept'});
347
- I.doubleClick('.btn.edit');
348
- ```
349
-
350
- #### Parameters
351
-
352
- - `locator` **([string][3] | [object][4])** clickable link or button located by text, or any element located by CSS|XPath|strict locator.
353
- - `context` **([string][3]? | [object][4])** (optional, `null` by default) element to search in CSS|XPath|Strict locator.
354
- ⚠️ returns a _promise_ which is synchronized internally by recorder
355
-
356
- ### executeAsyncScript
357
-
358
- Executes async script on page.
359
- Provided function should execute a passed callback (as first argument) to signal it is finished.
360
-
361
- Example: In Vue.js to make components completely rendered we are waiting for [nextTick][6].
362
-
363
- ```js
364
- I.executeAsyncScript(function(done) {
365
- Vue.nextTick(done); // waiting for next tick
366
- });
367
- ```
368
-
369
- By passing value to `done()` function you can return values.
370
- Additional arguments can be passed as well, while `done` function is always last parameter in arguments list.
371
-
372
- ```js
373
- let val = await I.executeAsyncScript(function(url, done) {
374
- // in browser context
375
- $.ajax(url, { success: (data) => done(data); }
376
- }, 'http://ajax.callback.url/');
377
- ```
378
-
379
- #### Parameters
380
-
381
- - `args` **...any** to be passed to function.
382
- ⚠️ returns a _promise_ which is synchronized internally by recorderWrapper for asynchronous [evaluate][7].
383
- Unlike NightmareJS implementation calling `done` will return its first argument.
384
- - `fn` **([string][3] | [function][8])** function to be executed in browser context.
385
-
386
- ### executeScript
387
-
388
- Executes sync script on a page.
389
- Pass arguments to function as additional parameters.
390
- Will return execution result to a test.
391
- In this case you should use async function and await to receive results.
392
-
393
- Example with jQuery DatePicker:
394
-
395
- ```js
396
- // change date of jQuery DatePicker
397
- I.executeScript(function() {
398
- // now we are inside browser context
399
- $('date').datetimepicker('setDate', new Date());
400
- });
401
- ```
402
-
403
- Can return values. Don't forget to use `await` to get them.
404
-
405
- ```js
406
- let date = await I.executeScript(function(el) {
407
- // only basic types can be returned
408
- return $(el).datetimepicker('getDate').toString();
409
- }, '#date'); // passing jquery selector
410
- ```
411
-
412
- #### Parameters
413
-
414
- - `args` **...any** to be passed to function.
415
- ⚠️ returns a _promise_ which is synchronized internally by recorderWrapper for synchronous [evaluate][7]
416
- - `fn` **([string][3] | [function][8])** function to be executed in browser context.
417
-
418
- ### fillField
419
-
420
- Fills a text field or textarea, after clearing its value, with the given string.
421
- Field is located by name, label, CSS, or XPath.
422
-
423
- ```js
424
- // by label
425
- I.fillField('Email', 'hello@world.com');
426
- // by name
427
- I.fillField('password', secret('123456'));
428
- // by CSS
429
- I.fillField('form#login input[name=username]', 'John');
430
- // or by strict locator
431
- I.fillField({css: 'form#login input[name=username]'}, 'John');
432
- ```
433
-
434
- #### Parameters
435
-
436
- - `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
437
- - `value` **([string][3] | [object][4])** text value to fill.
438
- ⚠️ returns a _promise_ which is synchronized internally by recorder
439
-
440
- ### grabAttributeFrom
441
-
442
- Retrieves an attribute from an element located by CSS or XPath and returns it to test.
443
- Resumes test execution, so **should be used inside async with `await`** operator.
444
- If more than one element is found - attribute of first element is returned.
445
-
446
- ```js
447
- let hint = await I.grabAttributeFrom('#tooltip', 'title');
448
- ```
449
-
450
- #### Parameters
451
-
452
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
453
- - `attr` **[string][3]** attribute name.
454
-
455
- Returns **[Promise][9]&lt;[string][3]>** attribute value
456
-
457
- ### grabAttributeFromAll
458
-
459
- Retrieves an array of attributes from elements located by CSS or XPath and returns it to test.
460
- Resumes test execution, so **should be used inside async with `await`** operator.
461
-
462
- ```js
463
- let hints = await I.grabAttributeFromAll('.tooltip', 'title');
464
- ```
465
-
466
- #### Parameters
467
-
468
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
469
- - `attr` **[string][3]** attribute name.
470
-
471
- Returns **[Promise][9]&lt;[Array][10]&lt;[string][3]>>** attribute value
472
-
473
- ### grabCookie
474
-
475
- Gets a cookie object by name.
476
- If none provided gets all cookies.
477
- Resumes test execution, so **should be used inside async function with `await`** operator.
478
-
479
- ```js
480
- let cookie = await I.grabCookie('auth');
481
- assert(cookie.value, '123456');
482
- ```
483
-
484
- #### Parameters
485
-
486
- - `name` **[string][3]?** cookie name.
487
-
488
- Returns **([Promise][9]&lt;[string][3]> | [Promise][9]&lt;[Array][10]&lt;[string][3]>>)** attribute valueCookie in JSON format. If name not passed returns all cookies for this domain.Multiple cookies can be received by passing query object `I.grabCookie({ secure: true});`. If you'd like get all cookies for all urls, use: `.grabCookie({ url: null }).`
489
-
490
- ### grabCssPropertyFrom
491
-
492
- Grab CSS property for given locator
493
- Resumes test execution, so **should be used inside an async function with `await`** operator.
494
- If more than one element is found - value of first element is returned.
495
-
496
- ```js
497
- const value = await I.grabCssPropertyFrom('h3', 'font-weight');
498
- ```
499
-
500
- #### Parameters
501
-
502
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
503
- - `cssProperty` **[string][3]** CSS property name.
504
-
505
- Returns **[Promise][9]&lt;[string][3]>** CSS value
506
-
507
- ### grabCurrentUrl
508
-
509
- Get current URL from browser.
510
- Resumes test execution, so should be used inside an async function.
511
-
512
- ```js
513
- let url = await I.grabCurrentUrl();
514
- console.log(`Current URL is [${url}]`);
515
- ```
516
-
517
- Returns **[Promise][9]&lt;[string][3]>** current URL
518
-
519
- ### grabElementBoundingRect
520
-
521
- Grab the width, height, location of given locator.
522
- Provide `width` or `height`as second param to get your desired prop.
523
- Resumes test execution, so **should be used inside an async function with `await`** operator.
524
-
525
- Returns an object with `x`, `y`, `width`, `height` keys.
526
-
527
- ```js
528
- const value = await I.grabElementBoundingRect('h3');
529
- // value is like { x: 226.5, y: 89, width: 527, height: 220 }
530
- ```
531
-
532
- To get only one metric use second parameter:
533
-
534
- ```js
535
- const width = await I.grabElementBoundingRect('h3', 'width');
536
- // width == 527
537
- ```
538
-
539
- #### Parameters
540
-
541
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
542
- - `prop`
543
- - `elementSize` **[string][3]?** x, y, width or height of the given element.
544
-
545
- Returns **([Promise][9]&lt;DOMRect> | [Promise][9]&lt;[number][11]>)** Element bounding rectangle
546
-
547
- ### grabHAR
548
-
549
- Get HAR
550
-
551
- ```js
552
- let har = await I.grabHAR();
553
- fs.writeFileSync('sample.har', JSON.stringify({log: har}));
554
- ```
555
-
556
- ### grabHTMLFrom
557
-
558
- Retrieves the innerHTML from an element located by CSS or XPath and returns it to test.
559
- Resumes test execution, so **should be used inside async function with `await`** operator.
560
- If more than one element is found - HTML of first element is returned.
561
-
562
- ```js
563
- let postHTML = await I.grabHTMLFrom('#post');
564
- ```
565
-
566
- #### Parameters
567
-
568
- - `locator`
569
- - `element` **([string][3] | [object][4])** located by CSS|XPath|strict locator.
570
-
571
- Returns **[Promise][9]&lt;[string][3]>** HTML code for an element
572
-
573
- ### grabHTMLFromAll
574
-
575
- Retrieves all the innerHTML from elements located by CSS or XPath and returns it to test.
576
- Resumes test execution, so **should be used inside async function with `await`** operator.
577
-
578
- ```js
579
- let postHTMLs = await I.grabHTMLFromAll('.post');
580
- ```
581
-
582
- #### Parameters
583
-
584
- - `locator`
585
- - `element` **([string][3] | [object][4])** located by CSS|XPath|strict locator.
586
-
587
- Returns **[Promise][9]&lt;[Array][10]&lt;[string][3]>>** HTML code for an element
588
-
589
- ### grabNumberOfVisibleElements
590
-
591
- Grab number of visible elements by locator.
592
- Resumes test execution, so **should be used inside async function with `await`** operator.
593
-
594
- ```js
595
- let numOfElements = await I.grabNumberOfVisibleElements('p');
596
- ```
597
-
598
- #### Parameters
599
-
600
- - `locator` **([string][3] | [object][4])** located by CSS|XPath|strict locator.
601
-
602
- Returns **[Promise][9]&lt;[number][11]>** number of visible elements
603
-
604
- ### grabPageScrollPosition
605
-
606
- Retrieves a page scroll position and returns it to test.
607
- Resumes test execution, so **should be used inside an async function with `await`** operator.
608
-
609
- ```js
610
- let { x, y } = await I.grabPageScrollPosition();
611
- ```
612
-
613
- Returns **[Promise][9]&lt;PageScrollPosition>** scroll position
614
-
615
- ### grabTextFrom
616
-
617
- Retrieves a text from an element located by CSS or XPath and returns it to test.
618
- Resumes test execution, so **should be used inside async with `await`** operator.
619
-
620
- ```js
621
- let pin = await I.grabTextFrom('#pin');
622
- ```
623
-
624
- If multiple elements found returns first element.
625
-
626
- #### Parameters
627
-
628
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
629
-
630
- Returns **[Promise][9]&lt;[string][3]>** attribute value
631
-
632
- ### grabTextFromAll
633
-
634
- Retrieves all texts from an element located by CSS or XPath and returns it to test.
635
- Resumes test execution, so **should be used inside async with `await`** operator.
636
-
637
- ```js
638
- let pins = await I.grabTextFromAll('#pin li');
639
- ```
640
-
641
- #### Parameters
642
-
643
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
644
-
645
- Returns **[Promise][9]&lt;[Array][10]&lt;[string][3]>>** attribute value
646
-
647
- ### grabTitle
648
-
649
- Retrieves a page title and returns it to test.
650
- Resumes test execution, so **should be used inside async with `await`** operator.
651
-
652
- ```js
653
- let title = await I.grabTitle();
654
- ```
655
-
656
- Returns **[Promise][9]&lt;[string][3]>** title
657
-
658
- ### grabValueFrom
659
-
660
- Retrieves a value from a form element located by CSS or XPath and returns it to test.
661
- Resumes test execution, so **should be used inside async function with `await`** operator.
662
- If more than one element is found - value of first element is returned.
663
-
664
- ```js
665
- let email = await I.grabValueFrom('input[name=email]');
666
- ```
667
-
668
- #### Parameters
669
-
670
- - `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator.
671
-
672
- Returns **[Promise][9]&lt;[string][3]>** attribute value
673
-
674
- ### grabValueFromAll
675
-
676
- Retrieves an array of value from a form located by CSS or XPath and returns it to test.
677
- Resumes test execution, so **should be used inside async function with `await`** operator.
678
-
679
- ```js
680
- let inputs = await I.grabValueFromAll('//form/input');
681
- ```
682
-
683
- #### Parameters
684
-
685
- - `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator.
686
-
687
- Returns **[Promise][9]&lt;[Array][10]&lt;[string][3]>>** attribute value
688
-
689
- ### haveHeader
690
-
691
- Add a header override for all HTTP requests. If header is undefined, the header overrides will be reset.
692
-
693
- ```js
694
- I.haveHeader('x-my-custom-header', 'some value');
695
- I.haveHeader(); // clear headers
696
- ```
697
-
698
- #### Parameters
699
-
700
- - `header`
701
- - `value`
702
-
703
- ### moveCursorTo
704
-
705
- Moves cursor to element matched by locator.
706
- Extra shift can be set with offsetX and offsetY options.
707
-
708
- ```js
709
- I.moveCursorTo('.tooltip');
710
- I.moveCursorTo('#submit', 5,5);
711
- ```
712
-
713
- #### Parameters
714
-
715
- - `locator` **([string][3] | [object][4])** located by CSS|XPath|strict locator.
716
- - `offsetX` **[number][11]** (optional, `0` by default) X-axis offset.
717
- - `offsetY` **[number][11]** (optional, `0` by default) Y-axis offset.
718
- ⚠️ returns a _promise_ which is synchronized internally by recorder
719
-
720
- ### pressKey
721
-
722
- Sends [input event][12] on a page.
723
- Can submit special keys like 'Enter', 'Backspace', etc
724
-
725
- #### Parameters
726
-
727
- - `key`
728
-
729
- ### refresh
730
-
731
- Reload the page
732
-
733
- ### refreshPage
734
-
735
- Reload the current page.
736
-
737
- ```js
738
- I.refreshPage();
739
- ```
740
-
741
- ⚠️ returns a _promise_ which is synchronized internally by recorder
742
-
743
- ### resizeWindow
744
-
745
- Resize the current window to provided width and height.
746
- First parameter can be set to `maximize`.
747
-
748
- #### Parameters
749
-
750
- - `width` **[number][11]** width in pixels or `maximize`.
751
- - `height` **[number][11]** height in pixels.
752
- ⚠️ returns a _promise_ which is synchronized internally by recorder
753
-
754
- ### rightClick
755
-
756
- Performs right click on a clickable element matched by semantic locator, CSS or XPath.
757
-
758
- ```js
759
- // right click element with id el
760
- I.rightClick('#el');
761
- // right click link or button with text "Click me"
762
- I.rightClick('Click me');
763
- // right click button with text "Click me" inside .context
764
- I.rightClick('Click me', '.context');
765
- ```
766
-
767
- #### Parameters
768
-
769
- - `locator` **([string][3] | [object][4])** clickable element located by CSS|XPath|strict locator.
770
- - `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS|XPath|strict locator.
771
- ⚠️ returns a _promise_ which is synchronized internally by recorder
772
-
773
- ### saveElementScreenshot
774
-
775
- Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
776
- Filename is relative to output folder.
777
-
778
- ```js
779
- I.saveElementScreenshot(`#submit`,'debug.png');
780
- ```
781
-
782
- #### Parameters
783
-
784
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
785
- - `fileName` **[string][3]** file name to save.
786
- ⚠️ returns a _promise_ which is synchronized internally by recorder
787
-
788
- ### saveScreenshot
789
-
790
- Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
791
- Filename is relative to output folder.
792
- Optionally resize the window to the full available page `scrollHeight` and `scrollWidth` to capture the entire page by passing `true` in as the second argument.
793
-
794
- ```js
795
- I.saveScreenshot('debug.png');
796
- I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
797
- ```
798
-
799
- #### Parameters
800
-
801
- - `fileName` **[string][3]** file name to save.
802
- - `fullPage` **[boolean][13]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
803
- ⚠️ returns a _promise_ which is synchronized internally by recorder
804
-
805
- ### scrollPageToBottom
806
-
807
- Scroll page to the bottom.
808
-
809
- ```js
810
- I.scrollPageToBottom();
811
- ```
812
-
813
- ⚠️ returns a _promise_ which is synchronized internally by recorder
814
-
815
- ### scrollPageToTop
816
-
817
- Scroll page to the top.
818
-
819
- ```js
820
- I.scrollPageToTop();
821
- ```
822
-
823
- ⚠️ returns a _promise_ which is synchronized internally by recorder
824
-
825
- ### scrollTo
826
-
827
- Scrolls to element matched by locator.
828
- Extra shift can be set with offsetX and offsetY options.
829
-
830
- ```js
831
- I.scrollTo('footer');
832
- I.scrollTo('#submit', 5, 5);
833
- ```
834
-
835
- #### Parameters
836
-
837
- - `locator` **([string][3] | [object][4])** located by CSS|XPath|strict locator.
838
- - `offsetX` **[number][11]** (optional, `0` by default) X-axis offset.
839
- - `offsetY` **[number][11]** (optional, `0` by default) Y-axis offset.
840
- ⚠️ returns a _promise_ which is synchronized internally by recorder
841
-
842
- ### see
843
-
844
- Checks that a page contains a visible text.
845
- Use context parameter to narrow down the search.
846
-
847
- ```js
848
- I.see('Welcome'); // text welcome on a page
849
- I.see('Welcome', '.content'); // text inside .content div
850
- I.see('Register', {css: 'form.register'}); // use strict locator
851
- ```
852
-
853
- #### Parameters
854
-
855
- - `text` **[string][3]** expected on page.
856
- - `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text.
857
- ⚠️ returns a _promise_ which is synchronized internally by recorder
858
-
859
- ### seeCheckboxIsChecked
860
-
861
- Verifies that the specified checkbox is checked.
862
-
863
- ```js
864
- I.seeCheckboxIsChecked('Agree');
865
- I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
866
- I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'});
867
- ```
868
-
869
- #### Parameters
870
-
871
- - `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
872
- ⚠️ returns a _promise_ which is synchronized internally by recorder
873
-
874
- ### seeCookie
875
-
876
- Checks that cookie with given name exists.
877
-
878
- ```js
879
- I.seeCookie('Auth');
880
- ```
881
-
882
- #### Parameters
883
-
884
- - `name` **[string][3]** cookie name.
885
- ⚠️ returns a _promise_ which is synchronized internally by recorder
886
-
887
- ### seeCurrentUrlEquals
888
-
889
- Checks that current url is equal to provided one.
890
- If a relative url provided, a configured url will be prepended to it.
891
- So both examples will work:
892
-
893
- ```js
894
- I.seeCurrentUrlEquals('/register');
895
- I.seeCurrentUrlEquals('http://my.site.com/register');
896
- ```
897
-
898
- #### Parameters
899
-
900
- - `url` **[string][3]** value to check.
901
- ⚠️ returns a _promise_ which is synchronized internally by recorder
902
-
903
- ### seeElement
904
-
905
- Checks that a given Element is visible
906
- Element is located by CSS or XPath.
907
-
908
- ```js
909
- I.seeElement('#modal');
910
- ```
911
-
912
- #### Parameters
913
-
914
- - `locator` **([string][3] | [object][4])** located by CSS|XPath|strict locator.
915
- ⚠️ returns a _promise_ which is synchronized internally by recorder
916
-
917
- ### seeElementInDOM
918
-
919
- Checks that a given Element is present in the DOM
920
- Element is located by CSS or XPath.
921
-
922
- ```js
923
- I.seeElementInDOM('#modal');
924
- ```
925
-
926
- #### Parameters
927
-
928
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
929
- ⚠️ returns a _promise_ which is synchronized internally by recorder
930
-
931
- ### seeInCurrentUrl
932
-
933
- Checks that current url contains a provided fragment.
934
-
935
- ```js
936
- I.seeInCurrentUrl('/register'); // we are on registration page
937
- ```
938
-
939
- #### Parameters
940
-
941
- - `url` **[string][3]** a fragment to check
942
- ⚠️ returns a _promise_ which is synchronized internally by recorder
943
-
944
- ### seeInField
945
-
946
- Checks that the given input field or textarea equals to given value.
947
- For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
948
-
949
- ```js
950
- I.seeInField('Username', 'davert');
951
- I.seeInField({css: 'form textarea'},'Type your comment here');
952
- I.seeInField('form input[type=hidden]','hidden_value');
953
- I.seeInField('#searchform input','Search');
954
- ```
955
-
956
- #### Parameters
957
-
958
- - `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator.
959
- - `value` **[string][3]** value to check.
960
- ⚠️ returns a _promise_ which is synchronized internally by recorder
961
-
962
- ### seeInSource
963
-
964
- Checks that the current page contains the given string in its raw source code.
965
-
966
- ```js
967
- I.seeInSource('<h1>Green eggs &amp; ham</h1>');
968
- ```
969
-
970
- #### Parameters
971
-
972
- - `text` **[string][3]** value to check.
973
- ⚠️ returns a _promise_ which is synchronized internally by recorder
974
-
975
- ### seeInTitle
976
-
977
- Checks that title contains text.
978
-
979
- ```js
980
- I.seeInTitle('Home Page');
981
- ```
982
-
983
- #### Parameters
984
-
985
- - `text` **[string][3]** text value to check.
986
- ⚠️ returns a _promise_ which is synchronized internally by recorder
987
-
988
- ### seeNumberOfElements
989
-
990
- Asserts that an element appears a given number of times in the DOM.
991
- Element is located by label or name or CSS or XPath.
992
-
993
- ```js
994
- I.seeNumberOfElements('#submitBtn', 1);
995
- ```
996
-
997
- #### Parameters
998
-
999
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1000
- - `num` **[number][11]** number of elements.
1001
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1002
-
1003
- ### seeNumberOfVisibleElements
1004
-
1005
- Asserts that an element is visible a given number of times.
1006
- Element is located by CSS or XPath.
1007
-
1008
- ```js
1009
- I.seeNumberOfVisibleElements('.buttons', 3);
1010
- ```
1011
-
1012
- #### Parameters
1013
-
1014
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1015
- - `num` **[number][11]** number of elements.
1016
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1017
-
1018
- ### selectOption
1019
-
1020
- Selects an option in a drop-down select.
1021
- Field is searched by label | name | CSS | XPath.
1022
- Option is selected by visible text or by value.
1023
-
1024
- ```js
1025
- I.selectOption('Choose Plan', 'Monthly'); // select by label
1026
- I.selectOption('subscription', 'Monthly'); // match option by text
1027
- I.selectOption('subscription', '0'); // or by value
1028
- I.selectOption('//form/select[@name=account]','Premium');
1029
- I.selectOption('form select[name=account]', 'Premium');
1030
- I.selectOption({css: 'form select[name=account]'}, 'Premium');
1031
- ```
1032
-
1033
- Provide an array for the second argument to select multiple options.
1034
-
1035
- ```js
1036
- I.selectOption('Which OS do you use?', ['Android', 'iOS']);
1037
- ```
1038
-
1039
- #### Parameters
1040
-
1041
- - `select` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator.
1042
- - `option` **([string][3] | [Array][10]&lt;any>)** visible text or value of option.
1043
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1044
-
1045
- ### setCookie
1046
-
1047
- Sets cookie(s).
1048
-
1049
- Can be a single cookie object or an array of cookies:
1050
-
1051
- ```js
1052
- I.setCookie({name: 'auth', value: true});
1053
-
1054
- // as array
1055
- I.setCookie([
1056
- {name: 'auth', value: true},
1057
- {name: 'agree', value: true}
1058
- ]);
1059
- ```
1060
-
1061
- #### Parameters
1062
-
1063
- - `cookie` **(Cookie | [Array][10]&lt;Cookie>)** a cookie object or array of cookie objects.
1064
- ⚠️ returns a _promise_ which is synchronized internally by recorderWrapper for `.cookies.set(cookie)`.
1065
- [See more][14]
1066
-
1067
- ### triggerMouseEvent
1068
-
1069
- Sends [input event][15] on a page.
1070
- Should be a mouse event like:
1071
- {
1072
- type: 'mouseDown',
1073
- x: args.x,
1074
- y: args.y,
1075
- button: "left"
1076
- }
1077
-
1078
- #### Parameters
1079
-
1080
- - `event`
1081
-
1082
- ### uncheckOption
1083
-
1084
- Unselects a checkbox or radio button.
1085
- Element is located by label or name or CSS or XPath.
1086
-
1087
- The second parameter is a context (CSS or XPath locator) to narrow the search.
1088
-
1089
- ```js
1090
- I.uncheckOption('#agree');
1091
- I.uncheckOption('I Agree to Terms and Conditions');
1092
- I.uncheckOption('agree', '//form');
1093
- ```
1094
-
1095
- #### Parameters
1096
-
1097
- - `field` **([string][3] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator.
1098
- - `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator.
1099
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1100
-
1101
- ### wait
1102
-
1103
- Pauses execution for a number of seconds.
1104
-
1105
- ```js
1106
- I.wait(2); // wait 2 secs
1107
- ```
1108
-
1109
- #### Parameters
1110
-
1111
- - `sec` **[number][11]** number of second to wait.
1112
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1113
-
1114
- ### waitForDetached
1115
-
1116
- Waits for an element to become not attached to the DOM on a page (by default waits for 1sec).
1117
- Element can be located by CSS or XPath.
1118
-
1119
- ```js
1120
- I.waitForDetached('#popup');
1121
- ```
1122
-
1123
- #### Parameters
1124
-
1125
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1126
- - `sec` **[number][11]** (optional, `1` by default) time in seconds to wait
1127
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1128
-
1129
- ### waitForElement
1130
-
1131
- Waits for element to be present on page (by default waits for 1sec).
1132
- Element can be located by CSS or XPath.
1133
-
1134
- ```js
1135
- I.waitForElement('.btn.continue');
1136
- I.waitForElement('.btn.continue', 5); // wait for 5 secs
1137
- ```
1138
-
1139
- #### Parameters
1140
-
1141
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1142
- - `sec` **[number][11]?** (optional, `1` by default) time in seconds to wait
1143
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1144
-
1145
- ### waitForFunction
1146
-
1147
- Waits for a function to return true (waits for 1 sec by default).
1148
- Running in browser context.
1149
-
1150
- ```js
1151
- I.waitForFunction(fn[, [args[, timeout]])
1152
- ```
1153
-
1154
- ```js
1155
- I.waitForFunction(() => window.requests == 0);
1156
- I.waitForFunction(() => window.requests == 0, 5); // waits for 5 sec
1157
- I.waitForFunction((count) => window.requests == count, [3], 5) // pass args and wait for 5 sec
1158
- ```
1159
-
1160
- #### Parameters
1161
-
1162
- - `fn` **([string][3] | [function][8])** to be executed in browser context.
1163
- - `argsOrSec` **([Array][10]&lt;any> | [number][11])?** (optional, `1` by default) arguments for function or seconds.
1164
- - `sec` **[number][11]?** (optional, `1` by default) time in seconds to wait
1165
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1166
-
1167
- ### waitForInvisible
1168
-
1169
- Waits for an element to be removed or become invisible on a page (by default waits for 1sec).
1170
- Element can be located by CSS or XPath.
1171
-
1172
- ```js
1173
- I.waitForInvisible('#popup');
1174
- ```
1175
-
1176
- #### Parameters
1177
-
1178
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1179
- - `sec` **[number][11]** (optional, `1` by default) time in seconds to wait
1180
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1181
-
1182
- ### waitForText
1183
-
1184
- Waits for a text to appear (by default waits for 1sec).
1185
- Element can be located by CSS or XPath.
1186
- Narrow down search results by providing context.
1187
-
1188
- ```js
1189
- I.waitForText('Thank you, form has been submitted');
1190
- I.waitForText('Thank you, form has been submitted', 5, '#modal');
1191
- ```
1192
-
1193
- #### Parameters
1194
-
1195
- - `text` **[string][3]** to wait for.
1196
- - `sec` **[number][11]** (optional, `1` by default) time in seconds to wait
1197
- - `context` **([string][3] | [object][4])?** (optional) element located by CSS|XPath|strict locator.
1198
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1199
-
1200
- ### waitForVisible
1201
-
1202
- Waits for an element to become visible on a page (by default waits for 1sec).
1203
- Element can be located by CSS or XPath.
1204
-
1205
- ```js
1206
- I.waitForVisible('#popup');
1207
- ```
1208
-
1209
- #### Parameters
1210
-
1211
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1212
- - `sec` **[number][11]** (optional, `1` by default) time in seconds to wait
1213
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1214
-
1215
- ### waitToHide
1216
-
1217
- Waits for an element to hide (by default waits for 1sec).
1218
- Element can be located by CSS or XPath.
1219
-
1220
- ```js
1221
- I.waitToHide('#popup');
1222
- ```
1223
-
1224
- #### Parameters
1225
-
1226
- - `locator` **([string][3] | [object][4])** element located by CSS|XPath|strict locator.
1227
- - `sec` **[number][11]** (optional, `1` by default) time in seconds to wait
1228
- ⚠️ returns a _promise_ which is synchronized internally by recorder
1229
-
1230
- [1]: https://github.com/segmentio/nightmare
1231
-
1232
- [2]: https://github.com/segmentio/nightmare#api
1233
-
1234
- [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
1235
-
1236
- [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
1237
-
1238
- [5]: https://github.com/rosshinkley/nightmare-upload#important-note-about-setting-file-upload-inputs
1239
-
1240
- [6]: https://vuejs.org/v2/api/#Vue-nextTick
1241
-
1242
- [7]: https://github.com/segmentio/nightmare#evaluatefn-arg1-arg2
1243
-
1244
- [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
1245
-
1246
- [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
1247
-
1248
- [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
1249
-
1250
- [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
1251
-
1252
- [12]: http://electron.atom.io/docs/api/web-contents/#webcontentssendinputeventevent
1253
-
1254
- [13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
1255
-
1256
- [14]: https://github.com/segmentio/nightmare/blob/master/Readme.md#cookiessetcookie
1257
-
1258
- [15]: http://electron.atom.io/docs/api/web-contents/#contentssendinputeventevent