UNPKG

32.2 kBPlain TextView Raw
1import { expectError, expectType } from 'tsd';
2import {
3 NightwatchSizeAndPosition,
4 Cookie,
5 JSON_WEB_OBJECT,
6 NightwatchLogEntry,
7 WindowPosition,
8 WindowSizeAndPosition,
9 NightwatchLogTypes,
10 ElementResult,
11 NightwatchCallbackResult,
12 NightwatchAPI,
13} from '..';
14import { WebElement } from 'selenium-webdriver';
15
16//
17// .elementIdAttribute
18//
19describe('elementIdAttribute command demo', function () {
20 before((browser) => browser.url('https://www.google.com/'));
21
22 test('demo test', function (browser) {
23 browser.findElement('input[type=text]', function (result) {
24 const webElement = result.value as JSON_WEB_OBJECT;
25 browser.elementIdAttribute(webElement.getId(), 'title', function (result) {
26 expectType<NightwatchAPI>(this);
27 expectType<NightwatchCallbackResult<string | null>>(result);
28 });
29 });
30 });
31
32 test('async demo test', async function (browser) {
33 const webElement = await browser.findElement('input[type=text]');
34 const result = await browser.elementIdAttribute(webElement.getId(), 'title');
35 expectType<string | null>(result);
36 });
37
38 after((browser) => browser.end());
39});
40
41//
42// .elementIdCssProperty
43//
44describe('elementIdCssProperty command demo', function () {
45 before((browser) => browser.url('https://www.google.com/'));
46
47 test('demo test', function (browser) {
48 browser.findElement('input[type=text]', function (result) {
49 const webElement = result.value as JSON_WEB_OBJECT;
50 browser.elementIdCssProperty(webElement.getId(), 'background-color', function (result) {
51 expectType<NightwatchAPI>(this);
52 expectType<NightwatchCallbackResult<string>>(result);
53 });
54 });
55 });
56
57 test('async demo test', async function (browser) {
58 const webElement = await browser.findElement('input[type=text]');
59 const result = await browser.elementIdCssProperty(webElement.getId(), 'background-color');
60 expectType<string>(result);
61 });
62
63 after((browser) => browser.end());
64});
65
66//
67// .elementIdDisplayed
68//
69describe('elementIdDisplayed command demo', function () {
70 before((browser) => browser.url('https://www.google.com/'));
71
72 test('demo test', function (browser) {
73 browser.findElement('input[type=text]', function (result) {
74 const webElement = result.value as JSON_WEB_OBJECT;
75 browser.elementIdDisplayed(webElement.getId(), function (result) {
76 expectType<NightwatchAPI>(this);
77 expectType<NightwatchCallbackResult<boolean>>(result);
78 });
79 });
80 });
81
82 test('async demo test', async function (browser) {
83 const webElement = await browser.findElement('input[type=text]');
84 const result = await browser.elementIdDisplayed(webElement.getId());
85 expectType<boolean>(result);
86 });
87
88 after((browser) => browser.end());
89});
90
91//
92// .elementIdEnabled
93//
94describe('elementIdEnabled command demo', function () {
95 before((browser) => browser.url('https://www.google.com/'));
96
97 test('demo test', function (browser) {
98 browser.findElement('input[type=text]', function (result) {
99 const webElement = result.value as JSON_WEB_OBJECT;
100 browser.elementIdEnabled(webElement.getId(), function (result) {
101 expectType<NightwatchAPI>(this);
102 expectType<NightwatchCallbackResult<boolean>>(result);
103 });
104 });
105 });
106
107 test('async demo test', async function (browser) {
108 const webElement = await browser.findElement('input[type=text]');
109 const result = await browser.elementIdEnabled(webElement.getId());
110 expectType<boolean>(result);
111 });
112
113 after((browser) => browser.end());
114});
115
116//
117// .elementIdName
118//
119describe('elementIdName command demo', function () {
120 before((browser) => browser.url('https://www.google.com/'));
121
122 test('demo test', function (browser) {
123 browser.findElement('input[type=text]', function (result) {
124 const webElement = result.value as JSON_WEB_OBJECT;
125 browser.elementIdName(webElement.getId(), function (result) {
126 expectType<NightwatchAPI>(this);
127 expectType<NightwatchCallbackResult<string>>(result);
128 });
129 });
130 });
131
132 test('async demo test', async function (browser) {
133 const webElement = await browser.findElement('input[type=text]');
134 const result = await browser.elementIdName(webElement.getId());
135 expectType<string>(result);
136 });
137
138 after((browser) => browser.end());
139});
140
141//
142// .elementIdSelected
143//
144describe('elementIdSelected command demo', function () {
145 before((browser) => browser.url('https://www.google.com/'));
146
147 test('demo test', function (browser) {
148 browser.findElement('input[type=text]', function (result) {
149 const webElement = result.value as JSON_WEB_OBJECT;
150 browser.elementIdSelected(webElement.getId(), function (result) {
151 expectType<NightwatchAPI>(this);
152 expectType<NightwatchCallbackResult<boolean>>(result);
153 });
154 });
155 });
156
157 test('async demo test', async function (browser) {
158 const webElement = await browser.findElement('input[type=text]');
159 const result = await browser.elementIdSelected(webElement.getId());
160 expectType<boolean>(result);
161 });
162
163 after((browser) => browser.end());
164});
165
166//
167// .submit
168//
169describe('submit command demo', function () {
170 before((browser) => browser.url('https://www.google.com/'));
171
172 test('demo test', function (browser) {
173 browser.findElement('input[type=text]', function (result) {
174 const webElement = result.value as JSON_WEB_OBJECT;
175 browser.submit(webElement.getId(), function (result) {
176 expectType<NightwatchAPI>(this);
177 expectType<NightwatchCallbackResult<null>>(result);
178 });
179 });
180 });
181
182 test('async demo test', async function (browser) {
183 const webElement = await browser.findElement('input[type=text]');
184 const result = await browser.submit(webElement.getId());
185 expectType<null>(result);
186 });
187
188 after((browser) => browser.end());
189});
190
191//
192// .elementIdSize
193//
194describe('elementIdSize command demo', function () {
195 before((browser) => browser.url('https://www.google.com/'));
196
197 test('demo test', function (browser) {
198 browser.findElement('input[type=text]', function (result) {
199 const webElement = result.value as JSON_WEB_OBJECT;
200 browser.elementIdSize(webElement.getId(), function (result) {
201 expectType<NightwatchAPI>(this);
202 expectType<NightwatchCallbackResult<NightwatchSizeAndPosition>>(result);
203 });
204 });
205 });
206
207 test('async demo test', async function (browser) {
208 const webElement = await browser.findElement('input[type=text]');
209 const result = await browser.elementIdSize(webElement.getId());
210 expectType<NightwatchSizeAndPosition>(result);
211 });
212
213 after((browser) => browser.end());
214});
215
216//
217// .elementIdText
218//
219describe('elementIdText command demo', function () {
220 before((browser) => browser.url('https://www.google.com/'));
221
222 test('demo test', function (browser) {
223 browser.findElement('input[type=text]', function (result) {
224 const webElement = result.value as JSON_WEB_OBJECT;
225 browser.elementIdText(webElement.getId(), function (result) {
226 expectType<NightwatchAPI>(this);
227 expectType<NightwatchCallbackResult<string>>(result);
228 });
229 });
230 });
231
232 test('async demo test', async function (browser) {
233 const webElement = await browser.findElement('input[type=text]');
234 const result = await browser.elementIdText(webElement.getId());
235 expectType<string>(result);
236 });
237
238 after((browser) => browser.end());
239});
240
241//
242// .elementIdClear
243//
244describe('elementIdClear command demo', function () {
245 before((browser) => browser.url('https://www.google.com/'));
246
247 test('demo test', function (browser) {
248 browser.findElement('input[type=text]', function (result) {
249 const webElement = result.value as JSON_WEB_OBJECT;
250 browser.elementIdClear(webElement.getId(), function (result) {
251 expectType<NightwatchAPI>(this);
252 expectType<NightwatchCallbackResult<null>>(result);
253 });
254 });
255 });
256
257 test('async demo test', async function (browser) {
258 const webElement = await browser.findElement('input[type=text]');
259 const result = await browser.elementIdClear(webElement.getId());
260 expectType<null>(result);
261 });
262
263 after((browser) => browser.end());
264});
265
266//
267// .elementIdClick
268//
269describe('elementIdClick command demo', function () {
270 before((browser) => browser.url('https://www.google.com/'));
271
272 test('demo test', function (browser) {
273 browser.findElement('input[type=text]', function (result) {
274 const webElement = result.value as JSON_WEB_OBJECT;
275 browser.elementIdClick(webElement.getId(), function (result) {
276 expectType<NightwatchAPI>(this);
277 expectType<NightwatchCallbackResult<null>>(result);
278 });
279 });
280 });
281
282 test('async demo test', async function (browser) {
283 const webElement = await browser.findElement('input[type=text]');
284 const result = await browser.elementIdClick(webElement.getId());
285 expectType<null>(result);
286 });
287
288 after((browser) => browser.end());
289});
290
291//
292// .elementIdValue
293//
294describe('elementIdValue command demo', function () {
295 before((browser) => browser.url('https://www.google.com/'));
296
297 test('demo test', function (browser) {
298 browser.findElement('input[type=text]', function (result) {
299 const webElement = result.value as JSON_WEB_OBJECT;
300 browser.elementIdValue(webElement.getId(), function (result) {
301 expectType<NightwatchAPI>(this);
302 expectType<NightwatchCallbackResult<string>>(result);
303 });
304 });
305 });
306
307 test('async demo test', async function (browser) {
308 const webElement = await browser.findElement('input[type=text]');
309 const result = await browser.elementIdValue(webElement.getId());
310 expectType<string>(result);
311 });
312
313 after((browser) => browser.end());
314});
315
316//
317// .elementIdLocation
318//
319describe('elementIdLocation command demo', function () {
320 before((browser) => browser.url('https://www.google.com/'));
321
322 test('demo test', function (browser) {
323 browser.findElement('input[type=text]', function (result) {
324 const webElement = result.value as JSON_WEB_OBJECT;
325 browser.elementIdLocation(webElement.getId(), function (result) {
326 expectType<NightwatchAPI>(this);
327 expectType<NightwatchCallbackResult<NightwatchSizeAndPosition>>(result);
328 });
329 });
330 });
331
332 test('async demo test', async function (browser) {
333 const webElement = await browser.findElement('input[type=text]');
334 const result = await browser.elementIdLocation(webElement.getId());
335 expectType<NightwatchSizeAndPosition>(result);
336 });
337
338 after((browser) => browser.end());
339});
340
341//
342// .source
343//
344describe('source command demo', function () {
345 before((browser) => browser.url('https://www.google.com/'));
346
347 test('demo test', function (browser) {
348 browser.source(function (result) {
349 expectType<NightwatchAPI>(this);
350 expectType<NightwatchCallbackResult<string>>(result);
351 });
352 });
353
354 test('async demo test', async function (browser) {
355 const result = await browser.source();
356 expectType<string>(result);
357 });
358
359 after((browser) => browser.end());
360});
361
362//
363// .doubleClick
364//
365describe('doubleClick command demo', function () {
366 before((browser) => browser.url('https://www.google.com/'));
367
368 test('demo test', function (browser) {
369 browser.doubleClick('input[type=text]', function (result) {
370 expectType<NightwatchAPI>(this);
371 expectType<NightwatchCallbackResult<null>>(result);
372 });
373 });
374
375 test('async demo test', async function (browser) {
376 const result = await browser.doubleClick('input[type=text]');
377 expectType<null>(result);
378 });
379
380 after((browser) => browser.end());
381});
382
383//
384// .clickAndHold
385//
386describe('clickAndHold command demo', function () {
387 before((browser) => browser.url('https://www.google.com/'));
388
389 test('demo test', function (browser) {
390 browser.clickAndHold('input[type=text]', function (result) {
391 expectType<NightwatchAPI>(this);
392 expectType<NightwatchCallbackResult<null>>(result);
393 });
394 });
395
396 test('async demo test', async function (browser) {
397 const result = await browser.clickAndHold('input[type=text]');
398 expectType<null>(result);
399 });
400
401 after((browser) => browser.end());
402});
403
404//
405// .moveTo
406//
407describe('moveTo command demo', function () {
408 before((browser) => browser.url('https://www.google.com/'));
409
410 test('demo test', function (browser) {
411 browser.moveTo(null, 100, 100, function (result) {
412 expectType<NightwatchAPI>(this);
413 expectType<NightwatchCallbackResult<null>>(result);
414 });
415 });
416
417 test('async demo test', async function (browser) {
418 const result = await browser.moveTo(100, 100);
419 expectType<null>(result);
420 });
421
422 after((browser) => browser.end());
423});
424
425//
426// .rightClick
427//
428describe('rightClick command demo', function () {
429 before((browser) => browser.url('https://www.google.com/'));
430
431 test('demo test', function (browser) {
432 browser.rightClick('input[type=text]', function (result) {
433 expectType<NightwatchAPI>(this);
434 expectType<NightwatchCallbackResult<null>>(result);
435 });
436 });
437
438 test('async demo test', async function (browser) {
439 const result = await browser.rightClick('input[type=text]');
440 expectType<null>(result);
441 });
442
443 after((browser) => browser.end());
444});
445
446//
447// .acceptAlert
448//
449describe('acceptAlert command demo', function () {
450 before((browser) => browser.url('https://nightwatchjs.org/__e2e/window/alerts.html/'));
451
452 test('demo test', function (browser) {
453 browser.click('#show-alert').acceptAlert(function (result) {
454 expectType<NightwatchAPI>(this);
455 expectType<NightwatchCallbackResult<null>>(result);
456 });
457 });
458
459 test('async demo test', async function (browser) {
460 const result = await browser.click('#show-alert').acceptAlert();
461 expectType<null>(result);
462 });
463
464 after((browser) => browser.end());
465});
466
467//
468// .dismissAlert
469//
470describe('dismissAlert command demo', function () {
471 before((browser) => browser.url('https://nightwatchjs.org/__e2e/window/alerts.html/'));
472
473 test('demo test', function (browser) {
474 browser.click('#show-alert').dismissAlert(function (result) {
475 expectType<NightwatchAPI>(this);
476 expectType<NightwatchCallbackResult<null>>(result);
477 });
478 });
479
480 test('async demo test', async function (browser) {
481 const result = await browser.click('#show-alert').dismissAlert();
482 expectType<null>(result);
483 });
484
485 after((browser) => browser.end());
486});
487
488//
489// .getAlertText
490//
491describe('getAlertText command demo', function () {
492 before((browser) => browser.url('https://nightwatchjs.org/__e2e/window/alerts.html/'));
493
494 test('demo test', function (browser) {
495 browser.click('#show-alert').getAlertText(function (result) {
496 expectType<NightwatchAPI>(this);
497 expectType<NightwatchCallbackResult<string>>(result);
498 });
499 });
500
501 test('async demo test', async function (browser) {
502 const result = await browser.click('#show-alert').getAlertText();
503 expectType<string>(result);
504 });
505
506 after((browser) => browser.end());
507});
508
509//
510// .setAlertText
511//
512describe('setAlertText command demo', function () {
513 before((browser) => browser.url('https://nightwatchjs.org/__e2e/window/alerts.html/'));
514
515 test('demo test', function (browser) {
516 browser.click('#show-alert').setAlertText('nightwatch', function (result) {
517 expectType<NightwatchAPI>(this);
518 expectType<NightwatchCallbackResult<null>>(result);
519 });
520 });
521
522 test('async demo test', async function (browser) {
523 const result = await browser.click('#show-alert').setAlertText('nightwatch');
524 expectType<null>(result);
525 });
526
527 after((browser) => browser.end());
528});
529
530//
531// .registerBasicAuth
532//
533describe('registerBasicAuth command demo', function () {
534 test('demo test', function (browser) {
535 browser.registerBasicAuth('test', 'test', function (result) {
536 expectType<NightwatchAPI>(this);
537 expectType<NightwatchCallbackResult<null>>(result);
538 });
539 });
540
541 test('async demo test', async function (browser) {
542 const result = await browser.registerBasicAuth('test', 'test');
543 expectType<null>(result);
544 });
545});
546
547//
548// .cookie
549//
550describe('cookie command demo', function () {
551 test('demo test', function (browser) {
552 browser.cookie('GET', function (result) {
553 expectType<NightwatchAPI>(this);
554 expectType<NightwatchCallbackResult<Cookie[] | null>>(result);
555 });
556 });
557
558 test('async demo test', async function (browser) {
559 const result = await browser.cookie('DELETE', 'sample');
560 expectType<null>(result);
561 });
562});
563
564//
565// .session
566//
567describe('session command demo', function () {
568 test('demo test', function (browser) {
569 browser.session(function (result) {
570 expectType<NightwatchAPI>(this);
571 expectType<NightwatchCallbackResult<Record<string, any>>>(result);
572 });
573 });
574
575 test('async demo test', async function (browser) {
576 const result = await browser.session();
577 expectType<Record<string, any>>(result);
578 });
579});
580
581//
582// .sessionLog
583//
584describe('sessionLog command demo', function () {
585 test('demo test', function (browser) {
586 browser.sessionLog('driver', function (result) {
587 expectType<NightwatchAPI>(this);
588 expectType<NightwatchCallbackResult<NightwatchLogEntry[]>>(result);
589 });
590 });
591
592 test('async demo test', async function (browser) {
593 const result = await browser.sessionLog('driver');
594 expectType<NightwatchLogEntry[]>(result);
595 });
596});
597
598//
599// .sessionLogTypes
600//
601describe('sessionLogTypes command demo', function () {
602 test('demo test', function (browser) {
603 browser.sessionLogTypes(function (result) {
604 expectType<NightwatchAPI>(this);
605 expectType<NightwatchCallbackResult<NightwatchLogTypes[]>>(result);
606 });
607 });
608
609 test('async demo test', async function (browser) {
610 const result = await browser.sessionLogTypes();
611 expectType<NightwatchLogTypes[]>(result);
612 });
613});
614
615//
616// .url
617//
618describe('url command demo', function () {
619 before((browser) => browser.url('https://www.google.com/'));
620
621 test('demo test', function (browser) {
622 browser.url(function (result) {
623 expectType<NightwatchAPI>(this);
624 expectType<NightwatchCallbackResult<string>>(result);
625 });
626 });
627
628 test('async demo test', async function (browser) {
629 const result = await browser.url();
630 expectType<string>(result);
631 });
632
633 after((browser) => browser.end());
634});
635
636//
637// .title
638//
639describe('title command demo', function () {
640 before((browser) => browser.url('https://www.google.com/'));
641
642 test('demo test', function (browser) {
643 browser.title(function (result) {
644 expectType<NightwatchAPI>(this);
645 expectType<NightwatchCallbackResult<string>>(result);
646 });
647 });
648
649 test('async demo test', async function (browser) {
650 const result = await browser.title();
651 expectType<string>(result);
652 });
653
654 after((browser) => browser.end());
655});
656
657//
658// .back
659//
660describe('back command demo', function () {
661 before((browser) => browser.url('https://www.google.com/'));
662
663 test('demo test', function (browser) {
664 browser.back(function (result) {
665 expectType<NightwatchAPI>(this);
666 expectType<NightwatchCallbackResult<null>>(result);
667 });
668 });
669
670 test('async demo test', async function (browser) {
671 const result = await browser.back();
672 expectType<null>(result);
673 });
674
675 after((browser) => browser.end());
676});
677
678//
679// .forward
680//
681describe('forward command demo', function () {
682 before((browser) => browser.url('https://www.google.com/'));
683
684 test('demo test', function (browser) {
685 browser.forward(function (result) {
686 expectType<NightwatchAPI>(this);
687 expectType<NightwatchCallbackResult<null>>(result);
688 });
689 });
690
691 test('async demo test', async function (browser) {
692 const result = await browser.forward();
693 expectType<null>(result);
694 });
695
696 after((browser) => browser.end());
697});
698
699//
700// .refresh
701//
702describe('refresh command demo', function () {
703 before((browser) => browser.url('https://www.google.com/'));
704
705 test('demo test', function (browser) {
706 browser.refresh(function (result) {
707 expectType<NightwatchAPI>(this);
708 expectType<NightwatchCallbackResult<null>>(result);
709 });
710 });
711
712 test('async demo test', async function (browser) {
713 const result = await browser.refresh();
714 expectType<null>(result);
715 });
716
717 after((browser) => browser.end());
718});
719
720//
721// .windowHandle
722//
723describe('windowHandle command demo', function () {
724 before((browser) => browser.url('https://www.google.com/'));
725
726 test('demo test', function (browser) {
727 browser.windowHandle(function (result) {
728 expectType<NightwatchAPI>(this);
729 expectType<NightwatchCallbackResult<string>>(result);
730 });
731 });
732
733 test('async demo test', async function (browser) {
734 const result = await browser.windowHandle();
735 expectType<string>(result);
736 });
737
738 after((browser) => browser.end());
739});
740
741//
742// .windowMaximize
743//
744describe('windowMaximize command demo', function () {
745 before((browser) => browser.url('https://www.google.com/'));
746
747 test('demo test', function (browser) {
748 browser.windowMaximize('current', function (result) {
749 expectType<NightwatchAPI>(this);
750 expectType<NightwatchCallbackResult<null>>(result);
751 });
752 });
753
754 test('async demo test', async function (browser) {
755 const result = await browser.windowMaximize();
756 expectType<null>(result);
757 });
758
759 after((browser) => browser.end());
760});
761
762//
763// .windowPosition
764//
765describe('windowPosition command demo', function () {
766 before((browser) => browser.url('https://www.google.com/'));
767
768 test('demo test', function (browser) {
769 browser.windowPosition('current', function (result) {
770 expectType<NightwatchAPI>(this);
771 expectType<NightwatchCallbackResult<WindowPosition>>(result);
772 });
773 });
774
775 test('async demo test', async function (browser) {
776 const result = await browser.windowPosition('current', 22, 47);
777 expectType<null>(result);
778 });
779
780 after((browser) => browser.end());
781});
782
783//
784// .windowSize
785//
786describe('windowSize command demo', function () {
787 before((browser) => browser.url('https://www.google.com/'));
788
789 test('demo test', function (browser) {
790 browser.windowSize('current', function (result) {
791 expectType<NightwatchAPI>(this);
792 expectType<NightwatchCallbackResult<WindowSizeAndPosition>>(result);
793 });
794 });
795
796 test('async demo test', async function (browser) {
797 const result = await browser.windowSize('current', 746, 1200);
798 expectType<null>(result);
799 });
800
801 after((browser) => browser.end());
802});
803
804//
805// .windowRect
806//
807describe('windowRect command demo', function () {
808 before((browser) => browser.url('https://www.google.com/'));
809
810 test('demo test', function (browser) {
811 browser.windowRect({ width: 100, height: 100 }, function (result) {
812 expectType<NightwatchAPI>(this);
813 expectType<NightwatchCallbackResult<null>>(result);
814 });
815 });
816
817 test('async demo test', async function (browser) {
818 const result = await browser.windowRect(null);
819 expectType<WindowSizeAndPosition>(result);
820 });
821
822 after((browser) => browser.end());
823});
824
825//
826// .frame
827//
828describe('frame command demo', function () {
829 before((browser) => browser.url('https://www.google.com/'));
830
831 test('demo test', function (browser) {
832 browser.frame(null, function (result) {
833 expectType<NightwatchAPI>(this);
834 expectType<NightwatchCallbackResult<null>>(result);
835 });
836 });
837
838 test('async demo test', async function (browser) {
839 const result = await browser.frame(null);
840 expectType<null>(result);
841 });
842
843 after((browser) => browser.end());
844});
845
846//
847// .frameParent
848//
849describe('frameParent command demo', function () {
850 before((browser) => browser.url('https://www.google.com/'));
851
852 test('demo test', function (browser) {
853 browser.frame(null).frameParent(function (result) {
854 expectType<NightwatchAPI>(this);
855 expectType<NightwatchCallbackResult<null>>(result);
856 });
857 });
858
859 test('async demo test', async function (browser) {
860 const result = await browser.frame(null).frameParent();
861 expectType<null>(result);
862 });
863
864 after((browser) => browser.end());
865});
866
867//
868// .elementIdElement
869//
870describe('elementIdElement command demo', function () {
871 before((browser) => browser.url('https://www.google.com/'));
872
873 test('demo test', function (browser) {
874 browser.findElement('input[type=text]', function (result) {
875 const webElement = result.value as JSON_WEB_OBJECT;
876 browser.elementIdElement(webElement.getId(), 'css selector', 'body', function (result) {
877 expectType<NightwatchAPI>(this);
878 expectType<NightwatchCallbackResult<ElementResult | []>>(result);
879 });
880 });
881 });
882
883 test('async demo test', async function (browser) {
884 const webElement = await browser.findElement('input[type=text]');
885 const result = await browser.elementIdElement(webElement.getId(), 'css selector', 'body');
886 expectType<ElementResult | []>(result);
887 });
888
889 after((browser) => browser.end());
890});
891
892//
893// .elementIdDoubleClick
894//
895describe('elementIdDoubleClick command demo', function () {
896 before((browser) => browser.url('https://www.google.com/'));
897
898 test('demo test', function (browser) {
899 browser.findElement('input[type=text]', function (result) {
900 const webElement = result.value as JSON_WEB_OBJECT;
901 browser.elementIdDoubleClick(webElement.getId(), function (result) {
902 expectType<NightwatchAPI>(this);
903 expectType<NightwatchCallbackResult<null>>(result);
904 });
905 });
906 });
907
908 test('async demo test', async function (browser) {
909 const webElement = await browser.findElement('input[type=text]');
910 const result = await browser.elementIdDoubleClick(webElement.getId());
911 expectType<null>(result);
912 });
913
914 after((browser) => browser.end());
915});
916
917//
918// .elementActive
919//
920describe('elementActive command demo', function () {
921 before((browser) => browser.url('https://www.google.com/'));
922
923 test('demo test', function (browser) {
924 browser.elementActive(function (result) {
925 expectType<NightwatchAPI>(this);
926 expectType<NightwatchCallbackResult<string>>(result);
927 });
928 });
929
930 test('async demo test', async function (browser) {
931 const result = await browser.elementActive();
932 expectType<string>(result);
933 });
934
935 after((browser) => browser.end());
936});
937
938//
939// .element
940//
941describe('element command demo', function() {
942 before(browser => browser.url('https://www.google.com/'));
943
944 test('demo test', function() {
945 browser.element('css selector', 'body');
946 });
947
948 test('async demo test', async function() {
949 const result = await browser.element('css selector', 'body');
950 expectType<WebElement>(result);
951 });
952
953 after(browser => browser.end());
954});
955
956//
957// .execute
958//
959describe('execute command demo', function () {
960 before((browser) => browser.url('https://www.google.com/'));
961
962 test('demo test', async function (browser) {
963 const result1 = await browser.execute(function () {});
964 expectType<null>(result1);
965
966 const result2 = await browser.execute(function () {
967 return 'nightwatch';
968 });
969 expectType<string>(result2);
970
971 expectError(await browser.execute(function (arg1: string) {
972 return 'nightwatch';
973 }))
974
975 await browser.execute(
976 function (arg1: string) {
977 return 'nightwatch';
978 },
979 ['js']
980 );
981
982 expectError(await browser.execute(
983 function (arg1: string) {
984 return 'nightwatch';
985 },
986 [123]
987 ))
988
989 expectError(await browser.execute(
990 function (arg1: string) {
991 return 'nightwatch';
992 },
993 ['js', 123]
994 ))
995
996 const result3 = await browser.execute('something');
997 expectType<unknown>(result3)
998
999 const result4 = await browser.execute('something', ['something', 5]);
1000 expectType<unknown>(result4)
1001 });
1002
1003 after((browser) => browser.end());
1004});
1005
1006//
1007// .executeScript
1008//
1009describe('executeScript command demo', function () {
1010 before((browser) => browser.url('https://www.google.com/'));
1011
1012 test('demo test', async function (browser) {
1013 const result1 = await browser.executeScript(function () {});
1014 expectType<null>(result1);
1015
1016 const result2 = await browser.executeScript(function () {
1017 return 'nightwatch';
1018 });
1019 expectType<string>(result2);
1020
1021 const result3 = await browser.executeScript(
1022 function (arg1) {
1023 return arg1;
1024 },
1025 ['nightwatch']
1026 );
1027 expectType<string>(result3);
1028
1029 expectError(await browser.executeScript(function (arg1: string) {
1030 return 'nightwatch';
1031 }))
1032
1033 await browser.executeScript(
1034 function (arg1: string) {
1035 return 'nightwatch';
1036 },
1037 ['js']
1038 );
1039
1040 expectError(await browser.executeScript(
1041 function (arg1: string) {
1042 return 'nightwatch';
1043 },
1044 [123]
1045 ))
1046
1047 expectError(await browser.executeScript(
1048 function (arg1: string) {
1049 return 'nightwatch';
1050 },
1051 ['js', 123]
1052 ))
1053
1054 const result4 = await browser.execute('something');
1055 expectType<unknown>(result4)
1056
1057 const result5 = await browser.execute('something', ['something', 5]);
1058 expectType<unknown>(result5)
1059 });
1060
1061 after((browser) => browser.end());
1062});
1063
1064//
1065// .executeAsyncScript
1066//
1067describe('executeAsyncScript command demo', function () {
1068 before((browser) => browser.url('https://www.google.com/'));
1069
1070 test('demo test', async function (browser) {
1071 const result = await browser.executeAsyncScript(
1072 function (arg1: string, arg2: number, done: (arg: string) => void) {
1073 return 'nightwatch';
1074 },
1075 ['js', 1]
1076 );
1077 expectType<string>(result);
1078
1079 const result1 = await browser.executeAsyncScript(function (done: () => void) {
1080 return 'nightwatch';
1081 });
1082 expectType<unknown>(result1)
1083
1084 const result2 = await browser.executeAsyncScript(function () {});
1085 expectType<unknown>(result2)
1086
1087 const result3 = await browser.executeAsyncScript(
1088 function (arg1: number, done) {
1089 return 'nightwatch';
1090 },
1091 [2]
1092 );
1093 expectType<unknown>(result3)
1094
1095 expectError(await browser.executeAsyncScript(function (arg1: string) {
1096 return 'nightwatch';
1097 }))
1098
1099 expectError(await browser.executeAsyncScript(
1100 function (arg1: string, done: (result: string) => void) {
1101 return 'nightwatch';
1102 },
1103 [123]
1104 ))
1105
1106 expectError(await browser.executeAsyncScript(
1107 function (arg1: string, done) {
1108 return 'nightwatch';
1109 },
1110 ['js', 123]
1111 ))
1112
1113 const result4 = await browser.executeAsyncScript('something');
1114 expectType<unknown>(result4)
1115
1116 const result5 = await browser.executeAsyncScript('something', ['something', 5]);
1117 expectType<unknown>(result5)
1118 });
1119
1120 after((browser) => browser.end());
1121});
1122
1123//
1124// .executeAsync
1125//
1126describe('executeAsync command demo', function () {
1127 before((browser) => browser.url('https://www.google.com/'));
1128
1129 test('demo test', async function (browser) {
1130 const result = await browser.executeAsync(
1131 function (arg1: string, arg2: number, done: (arg: string) => void) {
1132 return 'nightwatch';
1133 },
1134 ['js', 1]
1135 );
1136 expectType<string>(result);
1137
1138 const result1 = await browser.executeAsync(function (done: () => void) {
1139 return 'nightwatch';
1140 });
1141 expectType<unknown>(result1)
1142
1143 const result2 = await browser.executeAsync(function () {});
1144 expectType<unknown>(result2)
1145
1146 const result3 = await browser.executeAsync(
1147 function (arg1: number, done) {
1148 return 'nightwatch';
1149 },
1150 [2]
1151 );
1152 expectType<unknown>(result3)
1153
1154 expectError(await browser.executeAsync(function (arg1: string) {
1155 return 'nightwatch';
1156 }))
1157
1158 expectError(await browser.executeAsync(
1159 function (arg1: string, done: (result: string) => void) {
1160 return 'nightwatch';
1161 },
1162 [123]
1163 ))
1164
1165 expectError(await browser.executeAsync(
1166 function (arg1: string, done) {
1167 return 'nightwatch';
1168 },
1169 ['js', 123]
1170 ))
1171
1172 const result4 = await browser.executeAsync('something');
1173 expectType<unknown>(result4)
1174
1175 const result5 = await browser.executeAsync('something', ['something', 5]);
1176 expectType<unknown>(result5)
1177 });
1178
1179 after((browser) => browser.end());
1180});