UNPKG

14.7 kBPlain TextView Raw
1import { expectError, expectType } from 'tsd';
2import { Cookie, NightwatchAPI, NightwatchCallbackResult, NightwatchElement, NightwatchLogEntry } from '..';
3
4//
5// .navigateTo
6//
7describe('Navigation commands demo', function () {
8 test('demoTest', function (browser) {
9 // navigate to new url:
10 browser.navigateTo('https://nightwatchjs.org');
11 // with callback
12 browser.navigateTo('https://nightwatchjs.org', function (result) {
13 expectType<NightwatchAPI>(this);
14 expectType<NightwatchCallbackResult<null>>(result);
15 expectError(this.navigateTo());
16 });
17 });
18
19 test('demoTestAsync', async function (browser) {
20 const result = await browser.navigateTo('https://nightwatchjs.org');
21 expectType<null>(result);
22 });
23});
24
25//
26// .openNewWindow
27//
28describe('openNewWindow demo', function () {
29 test('demo test', function (browser) {
30 // open a new window tab (default)
31 browser.openNewWindow('tab', function (result) {
32 expectType<NightwatchAPI>(this);
33 expectType<NightwatchCallbackResult<null>>(result);
34 });
35
36 // open a new window
37 browser.openNewWindow('window', function (result) {
38 expectType<NightwatchAPI>(this);
39 expectType<NightwatchCallbackResult<null>>(result);
40 });
41 });
42
43 test('async demo test', async function (browser) {
44 const result = await browser.openNewWindow('window');
45 expectType<null>(result);
46 });
47});
48
49//
50// .closeWindow
51//
52describe('closeWindow demo', function () {
53 test('demo test', function (browser) {
54 browser.closeWindow(function (result) {
55 expectType<NightwatchAPI>(this);
56 expectType<NightwatchCallbackResult<null>>(result);
57 });
58 });
59
60 test('async demo test', async function (browser) {
61 const result = await browser.closeWindow();
62 expectType<null>(result);
63 });
64});
65
66//
67// .fullscreenWindow
68//
69describe('fullscreenWindow demo', function () {
70 test('demo test', function (browser) {
71 browser.fullscreenWindow(function (result) {
72 expectType<NightwatchAPI>(this);
73 expectType<NightwatchCallbackResult<null>>(result);
74 });
75 });
76
77 test('async demo test', async function (browser) {
78 const result = await browser.fullscreenWindow();
79 expectType<null>(result);
80 });
81});
82
83//
84// .minimizeWindow
85//
86describe('minimizeWindow demo', function () {
87 test('demo test', function (browser) {
88 browser.minimizeWindow(function (result) {
89 expectType<NightwatchAPI>(this);
90 expectType<NightwatchCallbackResult<null>>(result);
91 });
92 });
93
94 test('async demo test', async function (browser) {
95 const result = await browser.minimizeWindow();
96 expectType<null>(result);
97 });
98});
99
100//
101// .deleteCookie
102//
103describe('deleteCookie demo', function () {
104 test('demo test', function (browser) {
105 browser
106 .navigateTo('https://www.google.com')
107 .setCookie({
108 name: 'test_cookie',
109 value: 'test_value',
110 })
111 .deleteCookie('test_cookie', function (result) {
112 expectType<NightwatchAPI>(this);
113 expectType<NightwatchCallbackResult<null>>(result);
114 });
115 });
116
117 test('async demo test', async function (browser) {
118 const result = await browser.deleteCookie('test_cookie');
119 expectType<null>(result);
120 });
121});
122
123//
124// .deleteCookies
125//
126describe('deleteCookies demo', function () {
127 test('demo test', function (browser) {
128 browser
129 .navigateTo('https://www.google.com')
130 .setCookie({
131 name: 'test_cookie',
132 value: 'test_value',
133 })
134 .deleteCookies(function (result) {
135 expectType<NightwatchAPI>(this);
136 expectType<NightwatchCallbackResult<null>>(result);
137 });
138 });
139
140 test('async demo test', async function (browser) {
141 const result = await browser.deleteCookies();
142 expectType<null>(result);
143 });
144});
145
146//
147// .end
148//
149describe('end command demo', function () {
150 test('demo test', function (browser) {
151 browser.end(function (result) {
152 expectType<NightwatchAPI>(this);
153 expectType<NightwatchCallbackResult<null>>(result);
154 });
155 });
156});
157
158//
159// .getCookie
160//
161describe('getCookie command demo', function () {
162 test('demo test', function (browser) {
163 browser
164 .navigateTo('https://www.google.com')
165 .setCookie({
166 name: 'test_cookie',
167 value: 'test_value',
168 })
169 .getCookie('test_cookie', function (result) {
170 expectType<NightwatchAPI>(this);
171 expectType<NightwatchCallbackResult<Cookie>>(result);
172 });
173 });
174
175 test('async demo test', async function (browser) {
176 const result = await browser.getCookie('test_cookie');
177 expectType<Cookie>(result);
178 });
179});
180
181//
182// .setCookie
183//
184describe('setCookie command demo', function () {
185 test('demo test', function (browser) {
186 browser.navigateTo('https://www.google.com').setCookie(
187 {
188 name: 'test_cookie',
189 value: 'test_value',
190 },
191 function (result) {
192 expectType<NightwatchAPI>(this);
193 expectType<NightwatchCallbackResult<null>>(result);
194 }
195 );
196 });
197
198 test('async demo test', async function (browser) {
199 const result = await browser.setCookie({
200 name: 'test_cookie',
201 value: 'test_value',
202 });
203 expectType<null>(result);
204 });
205});
206
207//
208// .getLog
209//
210describe('getLog command demo', function () {
211 test('demo test', function () {
212 browser.getLog('browser', function (result) {
213 expectType<NightwatchAPI>(this);
214 expectType<NightwatchLogEntry[]>(result);
215 });
216 });
217
218 test('async demo test', async function (browser) {
219 const result = await browser.getLog('browser');
220 expectType<NightwatchLogEntry[]>(result);
221 });
222});
223
224//
225// .getCurrentUrl
226//
227describe('getCurrentUrl command demo', function () {
228 test('demo test', function () {
229 browser.navigateTo('https://www.nightwatchjs.org').getCurrentUrl(function (result) {
230 expectType<NightwatchAPI>(this);
231 expectType<NightwatchCallbackResult<string>>(result);
232 });
233 });
234
235 test('async demo test', async function (browser) {
236 const result = await browser.navigateTo('https://www.nightwatchjs.org').getCurrentUrl();
237 expectType<string>(result);
238 });
239});
240
241//
242// .getTitle
243//
244describe('getTitle command demo', function () {
245 test('demo test', function () {
246 browser.navigateTo('https://www.ecosia.org').getTitle(function (result) {
247 expectType<NightwatchAPI>(this);
248 expectType<string>(result);
249 });
250 });
251
252 test('async demo test', async function (browser) {
253 const result = await browser.navigateTo('https://www.ecosia.org').getTitle();
254 expectType<string>(result);
255 });
256});
257
258//
259// .isLogAvailable
260//
261describe('isLogAvailable command demo', function () {
262 test('demo test', function () {
263 browser.isLogAvailable('browser', function (result) {
264 expectType<NightwatchAPI>(this);
265 expectType<boolean>(result);
266 });
267 });
268
269 test('async demo test', async function (browser) {
270 const result = await browser.isLogAvailable('browser');
271 expectType<boolean>(result);
272 });
273});
274
275//
276// .resizeWindow
277//
278describe('resizeWindow command demo', function () {
279 test('demo test', function () {
280 browser.navigateTo('https://www.ecosia.org').resizeWindow(1000, 500, function (result) {
281 expectType<NightwatchAPI>(this);
282 expectType<NightwatchCallbackResult<null>>(result);
283 });
284 });
285
286 test('async demo test', async function (browser) {
287 const result = await browser.resizeWindow(1000, 800);
288 expectType<null>(result);
289 });
290});
291
292//
293// .screenshot
294//
295describe('screenshot command demo', function () {
296 test('demo test', function (browser) {
297 browser
298 .screenshot(function (result) {
299 expectType<NightwatchAPI>(this);
300 expectType<NightwatchCallbackResult<string>>(result);
301 })
302 .screenshot(true, function (result) {
303 expectType<NightwatchAPI>(this);
304 expectType<NightwatchCallbackResult<string>>(result);
305 });
306 });
307
308 test('async demo test', async function (browser) {
309 const result = await browser.screenshot();
310 expectType<string>(result);
311
312 const result2 = await browser.screenshot(true);
313 expectType<string>(result2);
314 });
315});
316
317//
318// .saveScreenshot
319//
320describe('saveScreenshot command demo', function () {
321 test('async demo test', async function (browser) {
322 const result = await browser.saveScreenshot('bcd.jpg');
323 expectType<string>(result);
324 });
325});
326
327//
328// .setCookie
329//
330describe('setCookie command demo', function () {
331 test('demo test', function () {
332 return browser.navigateTo('https://www.ecosia.org').setCookie(
333 {
334 name: 'testCookie',
335 value: '',
336 },
337 function (result) {
338 expectType<NightwatchAPI>(this);
339 expectType<NightwatchCallbackResult<null>>(result);
340 }
341 );
342 });
343
344 test('async demo test', async function (browser) {
345 const result = await browser.setCookie({
346 name: 'testCookie',
347 value: '',
348 });
349 expectType<null>(result);
350 });
351});
352
353//
354// .setWindowPosition
355//
356describe('setWindowPosition command demo', function () {
357 test('demo test', function () {
358 browser.setWindowPosition(0, 0, function (result) {
359 expectType<NightwatchAPI>(this);
360 expectType<NightwatchCallbackResult<null>>(result);
361 });
362 });
363
364 test('async demo test', async function (browser) {
365 const result = await browser.setWindowPosition(0, 0);
366 expectType<null>(result);
367 });
368});
369
370//
371// .setWindowRect
372//
373describe('setWindowRect command demo', function () {
374 test('demo test', function () {
375 browser.setWindowRect({ x: 0, y: 0, width: 500, height: 500 }, function (result) {
376 expectType<NightwatchAPI>(this);
377 expectType<NightwatchCallbackResult<null>>(result);
378 });
379 });
380 test('async demo test', async function (browser) {
381 const result = await browser.setWindowRect({ x: 0, y: 0, width: 500, height: 500 });
382 expectType<null>(result);
383 });
384});
385
386//
387// .setWindowSize
388//
389describe('setWindowSize command demo', function () {
390 test('demo test', function () {
391 browser.setWindowSize(500, 500, function (result) {
392 expectType<NightwatchAPI>(this);
393 expectType<NightwatchCallbackResult<null>>(result);
394 });
395 });
396
397 test('async demo test', async function (browser) {
398 const result = await browser.setWindowSize(500, 500);
399 expectType<null>(result);
400 });
401});
402
403//
404// switchWindow
405//
406describe('switchWindow command demo', function () {
407 test('async demo test', async function (browser) {
408 const handle = await browser.windowHandle();
409 const result = await browser.switchWindow(handle);
410 expectType<null>(result);
411 });
412});
413
414//
415// switchToWindow
416//
417describe('switchToWindow command demo', function () {
418 test('async demo test', async function (browser) {
419 const handle = await browser.windowHandle();
420 const result = await browser.switchToWindow(handle);
421 expectType<null>(result);
422 });
423});
424
425//
426// .init
427//
428describe('init command demo', function () {
429 test('demo test', function () {
430 browser.init('https://www.google.com', function (result) {
431 expectType<NightwatchAPI>(this);
432 expectType<NightwatchCallbackResult<null>>(result);
433 });
434 });
435});
436
437//
438// .waitUntil
439//
440describe('waitUntil command demo', function () {
441 before((browser) => browser.url('https://www.google.com/'));
442
443 test('demo test', function () {
444 browser.waitUntil(
445 async function () {
446 expectType<NightwatchAPI>(this);
447 return true;
448 },
449 5000,
450 5000,
451 function (result) {
452 expectType<NightwatchAPI>(this);
453 expectType<NightwatchCallbackResult<null>>(result);
454 }
455 );
456 });
457 it('demo Test 2', function() {
458 browser
459 .url('https://nightwatchjs.org')
460 .waitUntil(async function() {
461 const title = await this.execute(function() {
462 return document.title;
463 });
464
465 return title === 'Nightwatch.js';
466 }, 1000, 100, 'some message');
467 });
468 test('async demo test', async function () {
469 const result = await browser.waitUntil(async function () {
470 return true;
471 });
472 expectType<null>(result);
473 });
474
475 after((browser) => browser.end());
476});
477
478//
479// .axeInject
480//
481describe('axeInject test', function () {
482 test('async demo test', async function (browser) {
483 const result = await browser.axeInject();
484 expectType<null>(result);
485 });
486 after((browser) => browser.end());
487});
488
489//
490// .injectScript
491//
492describe('injectScript command demo', function() {
493 before(browser => browser.url('https://www.google.com/'));
494
495 test('demo test', function(browser) {
496 browser.injectScript('<script-url>', function(result) {
497 expectType<NightwatchAPI>(this);
498 expectType<NightwatchCallbackResult<NightwatchElement>>(result);
499 });
500 browser.injectScript('<script-url>', 'id', function(result) {
501 expectType<NightwatchAPI>(this);
502 expectType<NightwatchCallbackResult<NightwatchElement>>(result);
503 });
504 });
505
506 test('async demo test', async function(browser) {
507 const result = await browser.injectScript('<script-url>');
508 expectType<NightwatchElement>(result);
509
510 const result2 = await browser.injectScript('<script-url>', 'id');
511 expectType<NightwatchElement>(result2);
512 });
513
514 after(browser => browser.end());
515});
516
517//
518// .perform
519//
520describe('perform command demo', function() {
521 test('demo test', function() {
522 browser.perform(async function() {
523 expectType<NightwatchAPI>(this);
524 });
525 browser.perform(function() {
526 expectType<NightwatchAPI>(this);
527 });
528 browser.perform(function(done: () => void) {
529 expectType<NightwatchAPI>(this);
530 done();
531 });
532 browser.perform(function(client: NightwatchAPI, done: () => void) {
533 expectType<NightwatchAPI>(this);
534 expectType<NightwatchAPI>(client);
535 done();
536 });
537 });
538
539 test('async demo test', async function() {
540 const result = await browser.perform(function() {
541 expectType<NightwatchAPI>(this);
542 return '';
543 })
544 expectType<string>(result);
545
546 const result2 = await browser.perform(async function() {
547 expectType<NightwatchAPI>(this);
548 return true;
549 })
550 expectType<boolean>(result2);
551
552 const result3 = await browser.perform(function(done: (result?: number) => void) {
553 expectType<NightwatchAPI>(this);
554 done(2);
555 });
556 expectType<number>(result3);
557
558 const result4 = await browser.perform(function(client: NightwatchAPI, done: (result?: string) => void) {
559 expectType<NightwatchAPI>(this);
560 expectType<NightwatchAPI>(client);
561
562 client.getTitle((result) => {
563 done(result);
564 });
565 });
566 expectType<string>(result4);
567 });
568});