1 | import { expectType } from 'tsd';
|
2 | import { JSON_WEB_OBJECT, NightwatchSizeAndPosition, ElementResult, NightwatchAPI, NightwatchCallbackResult, ElementGlobal } from '..';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | describe('clearValue Command demo', function () {
|
8 | test('demo test', function () {
|
9 | browser
|
10 | .url('https://google.com')
|
11 | .waitForElementVisible('input[type=text]')
|
12 | .setValue('input[type=text]', 'nightwatch.js')
|
13 | .clearValue('input[type=text]', function (result) {
|
14 | expectType<NightwatchAPI>(this);
|
15 | expectType<NightwatchCallbackResult<null>>(result);
|
16 | })
|
17 | .expect.element('input[type=text]')
|
18 | .text.to.equal('');
|
19 | });
|
20 |
|
21 | test('async demo test', async function (browser) {
|
22 | const result = await browser
|
23 | .url('https://google.com')
|
24 | .waitForElementVisible('input[type=text]')
|
25 | .setValue('input[type=text]', 'nightwatch.js')
|
26 | .clearValue('input[type=text]');
|
27 | expectType<null>(result);
|
28 | });
|
29 | });
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | describe('click Command demo', function () {
|
35 | test('demo test', function () {
|
36 | browser
|
37 | .url('https://google.com')
|
38 | .waitForElementVisible('input[type=text]')
|
39 | .setValue('input[type=text]', 'nightwatch.js')
|
40 | .click('input[type=submit]', function (result) {
|
41 | expectType<NightwatchAPI>(this);
|
42 | expectType<NightwatchCallbackResult<null>>(result);
|
43 | });
|
44 | });
|
45 |
|
46 | test('async demo test', async function (browser) {
|
47 | const result = await browser
|
48 | .url('https://google.com')
|
49 | .waitForElementVisible('input[type=text]')
|
50 | .setValue('input[type=text]', 'nightwatch.js')
|
51 | .click('input[type=submit]');
|
52 | expectType<null>(result);
|
53 | });
|
54 | });
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | describe('getAttribute command demo', function () {
|
60 | before((browser) => browser.url('https://www.google.com/'));
|
61 |
|
62 | test('demo test', function () {
|
63 | browser.getAttribute('input[type=text]', 'title', function (result) {
|
64 | expectType<NightwatchAPI>(this);
|
65 | expectType<NightwatchCallbackResult<string | null>>(result);
|
66 | });
|
67 | });
|
68 |
|
69 | test('async demo test', async function (browser) {
|
70 | const result = await browser.getAttribute('input[type=text]', 'title');
|
71 | expectType<string | null>(result);
|
72 | });
|
73 |
|
74 | after((browser) => browser.end());
|
75 | });
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | describe('getCssProperty command demo', function () {
|
81 | before((browser) => browser.url('https://www.google.com/'));
|
82 |
|
83 | test('demo test', function () {
|
84 | browser.getCssProperty('input[type=text]', 'background-color', function (result) {
|
85 | expectType<NightwatchAPI>(this);
|
86 | expectType<NightwatchCallbackResult<string>>(result);
|
87 | });
|
88 | });
|
89 |
|
90 | test('async demo test', async function (browser) {
|
91 | const result = await browser.getCssProperty('input[type=text]', 'background-color');
|
92 | expectType<string>(result);
|
93 | });
|
94 |
|
95 | after((browser) => browser.end());
|
96 | });
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | describe('getElementSize command demo', function () {
|
102 | test('demo test', function () {
|
103 | browser.url('https://www.ecosia.org/').getElementSize('#navbartop', function (result) {
|
104 | expectType<NightwatchAPI>(this);
|
105 | expectType<NightwatchCallbackResult<NightwatchSizeAndPosition>>(result);
|
106 | });
|
107 | });
|
108 |
|
109 | test('async demo test', async function (browser) {
|
110 | const result = await browser.url('https://www.ecosia.org/').getElementSize('#__nuxt');
|
111 | expectType<NightwatchSizeAndPosition>(result);
|
112 | });
|
113 | });
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | describe('getLocation command demo', function () {
|
119 | test('demo test', function () {
|
120 | browser.url('https://www.ecosia.org/').getLocation('#__nuxt', function (result) {
|
121 | expectType<NightwatchAPI>(this);
|
122 | expectType<NightwatchCallbackResult<NightwatchSizeAndPosition>>(result);
|
123 | });
|
124 | });
|
125 |
|
126 | test('async demo test', async function (browser) {
|
127 | const result = await browser.url('https://www.ecosia.org/').getLocation('#__nuxt');
|
128 | expectType<NightwatchSizeAndPosition>(result);
|
129 | });
|
130 | });
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | describe('getTagName command demo', function () {
|
136 | before((browser) => browser.url('https://www.ecosia.org/'));
|
137 |
|
138 | test('demo test', function () {
|
139 | browser.getTagName('#__nuxt', function (result) {
|
140 | expectType<NightwatchAPI>(this);
|
141 | expectType<NightwatchCallbackResult<string>>(result);
|
142 | });
|
143 | });
|
144 |
|
145 | test('async demo test', async function (browser) {
|
146 | const result = await browser.getTagName('#__nuxt');
|
147 | expectType<string>(result);
|
148 | });
|
149 |
|
150 | after((browser) => browser.end());
|
151 | });
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | describe('getText command demo', function () {
|
157 | before((browser) => browser.url('https://nightwatchjs.org/'));
|
158 |
|
159 | test('demo test', function () {
|
160 | browser.getText('#top-section', function (result) {
|
161 | expectType<NightwatchAPI>(this);
|
162 | expectType<NightwatchCallbackResult<string>>(result);
|
163 | });
|
164 | });
|
165 |
|
166 | test('async demo test', async function (browser) {
|
167 | const result = await browser.getText('#top-section');
|
168 | expectType<string>(result);
|
169 | });
|
170 |
|
171 | after((browser) => browser.end());
|
172 | });
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | describe('getValue command demo', function () {
|
178 | before((browser) => browser.url('https://google.com/'));
|
179 |
|
180 | test('demo test', function () {
|
181 | browser.setValue('input[type=text]', 'nightwatchjs').getValue('input[type=text]', function (result) {
|
182 | expectType<NightwatchAPI>(this);
|
183 | expectType<NightwatchCallbackResult<string>>(result);
|
184 | });
|
185 | });
|
186 |
|
187 | test('async demo test', async function (browser) {
|
188 | const result = await browser.getValue('input[type=text]');
|
189 | expectType<string>(result);
|
190 | });
|
191 |
|
192 | after((browser) => browser.end());
|
193 | });
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | describe('getShadowRoot command demo', function () {
|
199 | test('demo test', function () {
|
200 | browser.getShadowRoot('input[type=text]', function (result) {
|
201 | expectType<NightwatchAPI>(this);
|
202 | expectType<NightwatchCallbackResult<ElementGlobal | null>>(result);
|
203 | });
|
204 | });
|
205 |
|
206 | test('async demo test', async function (browser) {
|
207 | const result = await browser.getShadowRoot('input[type=text]');
|
208 | expectType<ElementGlobal | null>(result);
|
209 |
|
210 | const result2 = await browser.getShadowRoot(await element('selector').getWebElement());
|
211 | expectType<ElementGlobal | null>(result2);
|
212 | });
|
213 | });
|
214 |
|
215 |
|
216 |
|
217 |
|
218 | describe('isVisible command demo', function () {
|
219 | before((browser) => browser.url('https://google.com/'));
|
220 | test('demo test', function () {
|
221 | browser.isVisible('input[type=text]', function (result) {
|
222 | expectType<NightwatchAPI>(this);
|
223 | expectType<NightwatchCallbackResult<boolean>>(result);
|
224 | });
|
225 | });
|
226 |
|
227 | test('async demo test', async function (browser) {
|
228 | const result = await browser.isVisible('input[type=text]');
|
229 | expectType<boolean>(result);
|
230 | });
|
231 |
|
232 | after((browser) => browser.end());
|
233 | });
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | describe('isPresent command demo', function () {
|
239 | before((browser) => browser.url('https://google.com/'));
|
240 | test('demo test', function () {
|
241 | browser.isPresent('input[type=text]', function (result) {
|
242 | expectType<NightwatchAPI>(this);
|
243 | expectType<NightwatchCallbackResult<boolean>>(result);
|
244 | });
|
245 | });
|
246 |
|
247 | test('async demo test', async function (browser) {
|
248 | const result = await browser.isPresent('input[type=text]');
|
249 | expectType<boolean>(result);
|
250 | });
|
251 |
|
252 | after((browser) => browser.end());
|
253 | });
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | describe('setValue command demo', function () {
|
259 | before((browser) => browser.url('https://google.com/'));
|
260 | test('demo test', function () {
|
261 | browser.setValue('input[type=text]', 'nightwatchjs', function (result) {
|
262 | expectType<NightwatchAPI>(this);
|
263 | expectType<NightwatchCallbackResult<null>>(result);
|
264 | });
|
265 | });
|
266 |
|
267 | test('async demo test', async function (browser) {
|
268 | const result = await browser.setValue('input[type=text]', 'nightwatchjs');
|
269 | expectType<null>(result);
|
270 | });
|
271 |
|
272 | after((browser) => browser.end());
|
273 | });
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | describe('sendKeys command demo', function () {
|
279 | before((browser) => browser.url('https://google.com/'));
|
280 |
|
281 | test('demo test', function () {
|
282 | browser.sendKeys('input[type=text]', 'nightwatchjs', function (result) {
|
283 | expectType<NightwatchAPI>(this);
|
284 | expectType<NightwatchCallbackResult<null>>(result);
|
285 | });
|
286 | });
|
287 |
|
288 | test('async demo test', async function (browser) {
|
289 | const result = await browser.setValue('input[type=text]', ['nightwatchjs', browser.Keys.ENTER]);
|
290 | expectType<null>(result);
|
291 | });
|
292 | after((browser) => browser.end());
|
293 | });
|
294 |
|
295 |
|
296 |
|
297 |
|
298 | describe('setPassword command demo', function () {
|
299 | before((browser) => browser.url('https://google.com/'));
|
300 | test('demo test', function () {
|
301 | browser.setPassword('input[type=text]', 'nightwatchjs', function (result) {
|
302 | expectType<NightwatchAPI>(this);
|
303 | expectType<NightwatchCallbackResult<null>>(result);
|
304 | });
|
305 | });
|
306 |
|
307 | test('async demo test', async function (browser) {
|
308 | const result = await browser.setPassword('input[type=text]', ['nightwatchjs', browser.Keys.ENTER]);
|
309 | expectType<null>(result);
|
310 | });
|
311 |
|
312 | after((browser) => browser.end());
|
313 | });
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | describe('setAttribute command demo', function () {
|
319 | before((browser) => browser.url('https://google.com/'));
|
320 | test('demo test', function () {
|
321 | browser.setAttribute('input[type=text]', 'disabled', 'true', function (result) {
|
322 | expectType<NightwatchAPI>(this);
|
323 | expectType<NightwatchCallbackResult<boolean>>(result);
|
324 | });
|
325 | });
|
326 |
|
327 | test('async demo test', async function (browser) {
|
328 | const result = await browser.setAttribute('input[type=text]', 'disabled', 'false');
|
329 | expectType<boolean>(result);
|
330 | });
|
331 |
|
332 | after((browser) => browser.end());
|
333 | });
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | describe('isEnabled command demo', function () {
|
339 | before((browser) => browser.url('https://google.com/'));
|
340 | test('demo test', function () {
|
341 | browser.setAttribute('input[type=text]', 'disabled', 'true').isEnabled('input[type=text]', function (result) {
|
342 | expectType<NightwatchAPI>(this);
|
343 | expectType<NightwatchCallbackResult<boolean>>(result);
|
344 | });
|
345 | });
|
346 |
|
347 | test('async demo test', async function (browser) {
|
348 | const result = await browser.isEnabled('input[type=text]');
|
349 | expectType<boolean>(result);
|
350 | });
|
351 |
|
352 | after((browser) => browser.end());
|
353 | });
|
354 |
|
355 |
|
356 |
|
357 |
|
358 | describe('getElementProperty command demo', function () {
|
359 | before((browser) => browser.url('https://google.com/'));
|
360 | test('demo test', function () {
|
361 | browser.getElementProperty('input[type=text]', 'disabled', function (result) {
|
362 | expectType<NightwatchAPI>(this);
|
363 | expectType<NightwatchCallbackResult<any>>(result);
|
364 | });
|
365 | });
|
366 |
|
367 | test('async demo test', async function (browser) {
|
368 | const result = await browser.getElementProperty('input[type=text]', 'disabled');
|
369 | expectType<any>(result);
|
370 | });
|
371 |
|
372 | after((browser) => browser.end());
|
373 | });
|
374 |
|
375 |
|
376 |
|
377 |
|
378 | describe('findElement command demo', function () {
|
379 | before((browser) => browser.url('https://google.com/'));
|
380 | test('demo test', function () {
|
381 | browser.findElement('input[type=text]', function (result) {
|
382 | expectType<NightwatchAPI>(this);
|
383 | expectType<NightwatchCallbackResult<JSON_WEB_OBJECT>>(result);
|
384 | });
|
385 | });
|
386 |
|
387 | test('async demo test', async function (browser) {
|
388 | const result = await browser.findElement('input[type=text]');
|
389 | expectType<JSON_WEB_OBJECT>(result);
|
390 | });
|
391 |
|
392 | after((browser) => browser.end());
|
393 | });
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | describe('getElementRect command demo', function () {
|
399 | before((browser) => browser.url('https://www.ecosia.org/'));
|
400 |
|
401 | test('demo test', function () {
|
402 | browser.getElementRect('#__nuxt', function (result) {
|
403 | expectType<NightwatchAPI>(this);
|
404 | expectType<NightwatchCallbackResult<NightwatchSizeAndPosition>>(result);
|
405 | });
|
406 | });
|
407 |
|
408 | test('async demo test', async function (browser) {
|
409 | const result = await browser.getElementRect('#__nuxt');
|
410 | expectType<NightwatchSizeAndPosition>(result);
|
411 | });
|
412 |
|
413 | after((browser) => browser.end());
|
414 | });
|
415 |
|
416 |
|
417 |
|
418 |
|
419 | describe('getAriaRole command demo', function () {
|
420 | before((browser) => browser.url('https://www.ecosia.org/'));
|
421 |
|
422 | test('demo test', function () {
|
423 | browser.getAriaRole('#__nuxt', function (result) {
|
424 | expectType<NightwatchAPI>(this);
|
425 | expectType<NightwatchCallbackResult<string>>(result);
|
426 | });
|
427 | });
|
428 |
|
429 | test('async demo test', async function (browser) {
|
430 | const result = await browser.getAriaRole('#__nuxt');
|
431 | expectType<string>(result);
|
432 | });
|
433 |
|
434 | after((browser) => browser.end());
|
435 | });
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | describe('getAccessibleName command demo', function () {
|
441 | before((browser) => browser.url('https://www.google.com/'));
|
442 |
|
443 | test('demo test', function () {
|
444 | browser.getAccessibleName('input[type=text]', function (result) {
|
445 | expectType<NightwatchAPI>(this);
|
446 | expectType<NightwatchCallbackResult<string>>(result);
|
447 | });
|
448 | });
|
449 |
|
450 | test('async demo test', async function (browser) {
|
451 | const result = await browser.getAccessibleName('input[type=text]');
|
452 | expectType<string>(result);
|
453 | });
|
454 |
|
455 | after((browser) => browser.end());
|
456 | });
|
457 |
|
458 |
|
459 |
|
460 |
|
461 | describe('waitForElementVisible command demo', function () {
|
462 | before((browser) => browser.url('https://www.google.com/'));
|
463 |
|
464 | test('demo test', function () {
|
465 | browser.waitForElementVisible('input[type=text]', undefined, undefined, true, function (result) {
|
466 | expectType<NightwatchAPI>(this);
|
467 | expectType<NightwatchCallbackResult<boolean>>(result);
|
468 | });
|
469 |
|
470 |
|
471 | browser.waitForElementVisible('body');
|
472 |
|
473 |
|
474 | browser.waitForElementVisible('css selector', '#dialog');
|
475 |
|
476 |
|
477 | browser.waitForElementVisible('css selector', '#dialog', 'The dialog container is removed.');
|
478 |
|
479 |
|
480 | browser.waitForElementVisible('body', function() {});
|
481 |
|
482 |
|
483 | browser.waitForElementVisible('body', function() {}, 'test message');
|
484 |
|
485 |
|
486 | browser.waitForElementVisible('body', 'test message');
|
487 |
|
488 |
|
489 | browser.waitForElementVisible('body', 500);
|
490 |
|
491 |
|
492 | browser.waitForElementVisible('body', 500, 'test message');
|
493 |
|
494 |
|
495 | browser.waitForElementVisible('body', 500, function() {});
|
496 |
|
497 |
|
498 | browser.waitForElementVisible('body', 500, true);
|
499 |
|
500 |
|
501 | browser.waitForElementVisible('body', 500, true, 'test message');
|
502 |
|
503 |
|
504 | browser.waitForElementVisible('body', 500, true, function() {});
|
505 |
|
506 |
|
507 | browser.waitForElementVisible('body', 500, true, function() {}, 'test message');
|
508 |
|
509 |
|
510 | browser.waitForElementVisible('body', 500, 100, function() {});
|
511 |
|
512 |
|
513 | browser.waitForElementVisible('body', 500, 100, false);
|
514 |
|
515 |
|
516 | browser.waitForElementVisible('body', 500, 100, false, 'test message');
|
517 | });
|
518 |
|
519 | test('async demo test', async function (browser) {
|
520 | const result = await browser.waitForElementVisible('input[type=text]', undefined, undefined, true);
|
521 | expectType<true | Error>(result);
|
522 | });
|
523 |
|
524 | after((browser) => browser.end());
|
525 | });
|
526 |
|
527 |
|
528 |
|
529 |
|
530 | describe('waitForElementPresent command demo', function () {
|
531 | before((browser) => browser.url('https://www.google.com/'));
|
532 |
|
533 | test('demo test', function () {
|
534 | browser.waitForElementPresent('input[type=text]', undefined, undefined, undefined, function (result) {
|
535 | expectType<NightwatchAPI>(this);
|
536 |
|
537 | expectType<NightwatchCallbackResult<null | ElementResult[]>>(result);
|
538 | });
|
539 |
|
540 |
|
541 | browser.waitForElementPresent('body');
|
542 |
|
543 |
|
544 | browser.waitForElementPresent('css selector', '#dialog');
|
545 |
|
546 |
|
547 | browser.waitForElementPresent('css selector', '#dialog', 'The dialog container is removed.');
|
548 |
|
549 |
|
550 | browser.waitForElementPresent('body', function() {});
|
551 |
|
552 |
|
553 | browser.waitForElementPresent('body', function() {}, 'test message');
|
554 |
|
555 |
|
556 | browser.waitForElementPresent('body', 'test message');
|
557 |
|
558 |
|
559 | browser.waitForElementPresent('body', 500);
|
560 |
|
561 |
|
562 | browser.waitForElementPresent('body', 500, 'test message');
|
563 |
|
564 |
|
565 | browser.waitForElementPresent('body', 500, function() {});
|
566 |
|
567 |
|
568 | browser.waitForElementPresent('body', 500, true);
|
569 |
|
570 |
|
571 | browser.waitForElementPresent('body', 500, true, 'test message');
|
572 |
|
573 |
|
574 | browser.waitForElementPresent('body', 500, true, function() {});
|
575 |
|
576 |
|
577 | browser.waitForElementPresent('body', 500, true, function() {}, 'test message');
|
578 |
|
579 |
|
580 | browser.waitForElementPresent('body', 500, 100, function() {});
|
581 |
|
582 |
|
583 | browser.waitForElementPresent('body', 500, 100, false);
|
584 |
|
585 |
|
586 | browser.waitForElementPresent('body', 500, 100, false, 'test message');
|
587 | });
|
588 |
|
589 | test('async demo test', async function (browser) {
|
590 | const result = await browser.waitForElementPresent('input[type=text]');
|
591 | expectType<ElementResult[] | Error>(result);
|
592 | });
|
593 |
|
594 | after((browser) => browser.end());
|
595 | });
|
596 |
|
597 |
|
598 |
|
599 |
|
600 | describe('dragAndDrop command demo', function () {
|
601 | before((browser) => browser.url('https://www.google.com/'));
|
602 |
|
603 | test('hello', function () {
|
604 | browser.dragAndDrop('input[type=text]', { x: 50, y: 50 }, function (result) {
|
605 | expectType<NightwatchAPI>(this);
|
606 | expectType<NightwatchCallbackResult<null>>(result);
|
607 | });
|
608 | });
|
609 |
|
610 | test('async demo test', async function (browser) {
|
611 | const result = await browser.dragAndDrop('input[type=text]', { x: 50, y: 50 });
|
612 | expectType<null>(result);
|
613 | });
|
614 |
|
615 | after((browser) => browser.end());
|
616 | });
|