1
+ ///<reference path="e2e-spec.d.ts" />
2
+
1
3
'use strict' ;
2
4
3
5
import { browser , element , by } from 'protractor' ;
4
6
5
- declare module jasmine {
6
-
7
- interface Matchers {
8
- toHaveTextByCss ( expected : any ) : boolean ;
9
- toHaveText ( expected : any ) : boolean ;
10
- toBeDisplayed ( expectationFailOutput ?: any ) : boolean ;
11
- toBePresent ( expectationFailOutput ?: any ) : boolean ;
12
- toHaveValue ( expected : any ) : boolean ;
13
- toContainText ( expected : any ) : boolean ;
14
- toBeSelected ( expectationFailOutput ?: any ) : boolean ;
15
- }
16
-
17
- interface ProtractorCustomMatcherResult {
18
- pass : webdriver . promise . Promise < boolean > ;
19
- message ?: string ;
20
- }
21
-
22
- }
23
-
24
7
let matchers : any = {
25
8
toHaveTextByCss : toHaveTextByCss ,
26
9
toHaveText : toHaveText ,
@@ -224,72 +207,74 @@ function toHaveClass() {
224
207
225
208
}
226
209
227
- describe ( 'A11y Cookbook' , ( ) => {
210
+ describe ( 'A11y Cookbook' , function ( ) {
211
+
212
+ beforeEach ( function ( ) {
213
+ jasmine . addMatchers ( matchers ) ;
214
+ } )
228
215
229
- describe ( 'A11y Cookbook main index' , ( ) => {
216
+ describe ( 'A11y Cookbook main index' , function ( ) {
230
217
231
- beforeAll ( ( ) => {
232
- jasmine . addMatchers ( matchers ) ;
218
+ beforeAll ( function ( ) {
233
219
browser . get ( '' ) ;
234
220
} ) ;
235
221
236
- it ( 'should display the main heading and links' , ( ) => {
222
+ it ( 'should display the main heading and links' , function ( ) {
237
223
expect ( 'h1' ) . toHaveTextByCss ( 'Angular 2 a11y cookbook' ) ;
238
224
expect ( element . all ( by . tagName ( 'a' ) ) . get ( 0 ) ) . toHaveText ( 'Accessible form control labels' ) ;
239
225
expect ( element . all ( by . tagName ( 'a' ) ) . get ( 1 ) ) . toHaveText ( 'Managing focus' ) ;
240
226
expect ( element . all ( by . tagName ( 'a' ) ) . get ( 2 ) ) . toHaveText ( 'Roles for custom component widgets' ) ;
241
227
expect ( element . all ( by . tagName ( 'a' ) ) . get ( 3 ) ) . toHaveText ( 'Developer tools' ) ;
242
228
} ) ;
243
229
244
- it ( 'should display the dev tool deeplinks' , ( ) => {
230
+ it ( 'should display the dev tool deeplinks' , function ( ) {
245
231
element . all ( by . tagName ( 'a' ) ) . get ( 3 ) . click ( ) ;
246
232
expect ( element . all ( by . tagName ( 'a' ) ) . get ( 0 ) ) . toHaveText ( 'Demo with a11y errors' ) ;
247
233
expect ( element . all ( by . tagName ( 'a' ) ) . get ( 1 ) ) . toHaveText ( 'Demo with full a11y features' ) ;
248
234
} ) ;
249
235
250
236
} ) ;
251
237
252
- describe ( 'A11y Cookbook control labels' , ( ) => {
238
+ describe ( 'A11y Cookbook control labels' , function ( ) {
253
239
254
- beforeAll ( ( ) => {
255
- jasmine . addMatchers ( matchers ) ;
240
+ beforeAll ( function ( ) {
256
241
browser . get ( '' ) ;
257
242
element . all ( by . tagName ( 'a' ) ) . get ( 0 ) . click ( ) ;
258
243
} ) ;
259
244
260
- it ( 'should have the correct page heading' , ( ) => {
245
+ it ( 'should have the correct page heading' , function ( ) {
261
246
expect ( 'h2' ) . toHaveTextByCss ( 'Accessible form control labels' ) ;
262
247
} ) ;
263
248
264
- it ( 'should have the correct sections' , ( ) => {
249
+ it ( 'should have the correct sections' , function ( ) {
265
250
let headings = element . all ( by . tagName ( 'h3' ) ) ;
266
251
expect ( headings . get ( 0 ) ) . toHaveText ( 'Implicit labeling' ) ;
267
252
expect ( headings . get ( 1 ) ) . toHaveText ( 'Explicit labeling' ) ;
268
253
expect ( headings . get ( 2 ) ) . toHaveText ( 'Hiding labels' ) ;
269
254
expect ( headings . get ( 3 ) ) . toHaveText ( 'Labeling custom controls' ) ;
270
255
} ) ;
271
256
272
- it ( 'should have a working implicitly labelled input' , ( ) => {
257
+ it ( 'should have a working implicitly labelled input' , function ( ) {
273
258
let testVal = 'Some text' ;
274
259
expect ( element . all ( by . tagName ( 'label' ) ) . get ( 0 ) ) . toHaveText ( 'Type something:' ) ;
275
260
let input = element . all ( by . css ( 'label > input' ) ) . first ( ) ;
276
261
expect ( input ) . toHaveValue ( '' ) ;
277
- sendKeys ( input , testVal ) ;
262
+ input . sendKeys ( testVal ) ;
278
263
expect ( input ) . toHaveValue ( testVal ) ;
279
264
testValueDecorator ( 0 , testVal ) ;
280
265
} ) ;
281
266
282
- it ( 'should have a working implicitly labelled textarea' , ( ) => {
267
+ it ( 'should have a working implicitly labelled textarea' , function ( ) {
283
268
let testVal = 'Some text' ;
284
269
expect ( element . all ( by . tagName ( 'label' ) ) . get ( 1 ) ) . toHaveText ( 'Type some text:' ) ;
285
270
let textarea = element . all ( by . css ( 'label > textarea' ) ) . first ( ) ;
286
271
expect ( textarea ) . toHaveValue ( '' ) ;
287
- sendKeys ( textarea , testVal ) ;
272
+ textarea . sendKeys ( testVal ) ;
288
273
expect ( textarea ) . toHaveValue ( testVal ) ;
289
274
testValueDecorator ( 1 , testVal ) ;
290
275
} ) ;
291
276
292
- it ( 'should have working implicitly labelled checkboxes' , ( ) => {
277
+ it ( 'should have working implicitly labelled checkboxes' , function ( ) {
293
278
expect ( 'fieldset legend' ) . toHaveTextByCss ( 'What do you like most about Angular 2?' ) ;
294
279
let fieldSet = element . all ( by . css ( 'fieldset' ) ) . first ( ) ;
295
280
expect ( fieldSet . all ( by . css ( 'label' ) ) . get ( 0 ) ) . toHaveText ( 'Template syntax' ) ;
@@ -307,7 +292,7 @@ describe('A11y Cookbook', () => {
307
292
testValueDecorator ( 2 , '[ "Components", "Template syntax" ]' ) ;
308
293
} ) ;
309
294
310
- it ( 'should have working implicitly labelled radiobuttons' , ( ) => {
295
+ it ( 'should have working implicitly labelled radiobuttons' , function ( ) {
311
296
expect ( element . all ( by . css ( 'fieldset legend' ) ) . get ( 1 ) ) . toHaveText ( 'Choose your favourite Angular 2 language:' ) ;
312
297
let fieldSet = element . all ( by . css ( 'fieldset' ) ) . get ( 1 ) ;
313
298
expect ( fieldSet . all ( by . css ( 'label' ) ) . get ( 0 ) ) . toHaveText ( 'TypeScript' ) ;
@@ -323,87 +308,86 @@ describe('A11y Cookbook', () => {
323
308
testValueDecorator ( 3 , 'JavaScript' ) ;
324
309
} ) ;
325
310
326
- it ( 'should have a working implicitly labelled select' , ( ) => {
311
+ it ( 'should have a working implicitly labelled select' , function ( ) {
327
312
expect ( element . all ( by . tagName ( 'label' ) ) . get ( 10 ) ) . toContainText ( 'Why are you interested in a11y?' ) ;
328
313
expect ( element . all ( by . tagName ( 'select' ) ) . get ( 0 ) ) . toHaveValue ( 'Curiosity' ) ;
329
314
testValueDecorator ( 4 , 'Curiosity' ) ;
330
315
} ) ;
331
316
332
- it ( 'should have a working explicitly labelled input' , ( ) => {
317
+ it ( 'should have a working explicitly labelled input' , function ( ) {
333
318
let testVal = 'Some text' ;
334
319
expect ( element . all ( by . tagName ( 'label[for="inputexplicit"]' ) ) . first ( ) ) . toHaveText ( 'Label for input:' ) ;
335
320
let input = element . all ( by . css ( '#inputexplicit' ) ) . get ( 0 ) ;
336
321
expect ( input ) . toHaveValue ( '' ) ;
337
- sendKeys ( input , testVal ) ;
322
+ input . sendKeys ( testVal ) ;
338
323
expect ( input ) . toHaveValue ( testVal ) ;
339
324
testValueDecorator ( 5 , testVal ) ;
340
325
} ) ;
341
326
342
- it ( 'should have a working input with hidden label' , ( ) => {
327
+ it ( 'should have a working input with hidden label' , function ( ) {
343
328
let testVal = 'Some text' ;
344
329
expect ( element . all ( by . tagName ( 'label.visually-hidden' ) ) . first ( ) ) . toHaveText ( 'Search:' ) ;
345
330
let input = element . all ( by . css ( '#inputsearch' ) ) . first ( ) ;
346
331
expect ( input ) . toHaveValue ( '' ) ;
347
- sendKeys ( input , testVal ) ;
332
+ input . sendKeys ( testVal ) ;
348
333
expect ( input ) . toHaveValue ( testVal ) ;
349
334
testValueDecorator ( 6 , testVal ) ;
350
335
} ) ;
351
336
352
- it ( 'should have a working input with aria-label' , ( ) => {
337
+ it ( 'should have a working input with aria-label' , function ( ) {
353
338
let testVal = 'Some text' ;
354
339
let input = element . all ( by . css ( 'input[aria-label="Filter:"' ) ) . first ( ) ;
355
340
expect ( input ) . toHaveValue ( '' ) ;
356
- sendKeys ( input , testVal ) ;
341
+ input . sendKeys ( testVal ) ;
357
342
expect ( input ) . toHaveValue ( testVal ) ;
358
343
testValueDecorator ( 7 , testVal ) ;
359
344
} ) ;
360
345
361
- it ( 'should have a working editable div with label' , ( ) => {
346
+ it ( 'should have a working editable div with label' , function ( ) {
362
347
let testVal = 'Value' ;
363
348
expect ( element . all ( by . tagName ( 'div.col-xs-6 label' ) ) . first ( ) ) . toHaveText ( 'Write in this labeled div:' ) ;
364
349
let input = element . all ( by . css ( 'div.col-xs-6 div.edit-box' ) ) . first ( ) ;
365
350
expect ( input ) . toHaveText ( '' ) ;
366
- sendKeys ( input , testVal ) ;
351
+ input . sendKeys ( testVal ) ;
367
352
expect ( input ) . toHaveText ( testVal ) ;
368
353
} ) ;
369
354
370
- it ( 'should have a working wrapped input' , ( ) => {
355
+ it ( 'should have a working wrapped input' , function ( ) {
371
356
let testVal = 'Test' ;
372
357
expect ( element . all ( by . tagName ( 'div.col-xs-6 label span' ) ) . first ( ) ) . toHaveText ( 'Write in this wrapped input:' ) ;
373
358
let input = element . all ( by . css ( 'div.input-group input' ) ) . first ( ) ;
374
359
expect ( input ) . toHaveValue ( '' ) ;
375
- sendKeys ( input , testVal ) ;
360
+ input . sendKeys ( testVal ) ;
376
361
expect ( input ) . toHaveValue ( testVal ) ;
377
362
} ) ;
378
363
379
364
} ) ;
380
365
381
- describe ( 'A11y Cookbook managing focus' , ( ) => {
366
+ describe ( 'A11y Cookbook managing focus' , function ( ) {
382
367
383
- beforeAll ( ( ) => {
384
- jasmine . addMatchers ( matchers ) ;
368
+ beforeAll ( function ( ) {
385
369
browser . get ( '' ) ;
386
370
element . all ( by . tagName ( 'a' ) ) . get ( 1 ) . click ( ) ;
387
371
} ) ;
388
372
389
- it ( 'should have the correct page heading' , ( ) => {
373
+ it ( 'should have the correct page heading' , function ( ) {
390
374
expect ( 'h2' ) . toHaveTextByCss ( 'Managing focus' ) ;
391
375
} ) ;
392
376
393
- it ( 'should have the correct sections' , ( ) => {
377
+ it ( 'should have the correct sections' , function ( ) {
394
378
let headings = element . all ( by . tagName ( 'h3' ) ) ;
395
379
expect ( headings . get ( 0 ) ) . toHaveText ( 'The focus outline' ) ;
396
380
expect ( headings . get ( 1 ) ) . toHaveText ( 'Focus flow' ) ;
397
381
expect ( headings . get ( 2 ) ) . toHaveText ( 'Focusing custom controls' ) ;
398
382
expect ( headings . get ( 3 ) ) . toHaveText ( 'Internal focus in a component' ) ;
399
383
} ) ;
400
384
401
- it ( 'should have the focus outline elements' , ( ) => {
385
+ it ( 'should have the focus outline elements' , function ( ) {
402
386
expect ( element . all ( by . cssContainingText ( 'label' , 'Focus me for the standard browser outline:' ) ) . first ( ) ) . toBePresent ( ) ;
403
387
expect ( element . all ( by . cssContainingText ( 'label' , 'Focus me for a new and unusual outline:' ) ) . first ( ) ) . toBePresent ( ) ;
404
388
} ) ;
405
389
406
- it ( 'should have the focus flow elements' , ( ) => {
390
+ it ( 'should have the focus flow elements' , function ( ) {
407
391
expect ( element . all ( by . cssContainingText ( 'label' , 'Which city of The USA did you work in:' ) ) . first ( ) ) . toBePresent ( ) ;
408
392
expect ( element . all ( by . cssContainingText ( 'label' , 'How many months did you work in The USA:' ) ) . first ( ) ) . toBePresent ( ) ;
409
393
expect ( element . all ( by . cssContainingText ( 'label' , 'Which city of The Netherlands did you work in:' ) ) . first ( ) ) . toBePresent ( ) ;
@@ -416,12 +400,12 @@ describe('A11y Cookbook', () => {
416
400
expect ( element . all ( by . cssContainingText ( 'label' , 'How many months did you work in The UK:' ) ) . first ( ) ) . toBePresent ( ) ;
417
401
} ) ;
418
402
419
- it ( 'should have a clickable custom button component' , ( ) => {
403
+ it ( 'should have a clickable custom button component' , function ( ) {
420
404
element . all ( by . tagName ( 'a11y-custom-button' ) ) . get ( 0 ) . click ( ) ;
421
405
testValueDecorator ( 0 , 'Button has been clicked 1 times' ) ;
422
406
} ) ;
423
407
424
- it ( 'should have an error toggling component' , ( ) => {
408
+ it ( 'should have an error toggling component' , function ( ) {
425
409
let showErrorButton = element ( by . css ( 'a11y-error-demo button.btn.btn-primary' ) ) ;
426
410
expect ( showErrorButton ) . toHaveText ( 'Show error' ) ;
427
411
let errorBanner = element ( by . css ( 'a11y-error-demo div.alert' ) ) ;
@@ -434,81 +418,78 @@ describe('A11y Cookbook', () => {
434
418
435
419
} ) ;
436
420
437
- describe ( 'A11y Cookbook roles for custom components' , ( ) => {
421
+ describe ( 'A11y Cookbook roles for custom components' , function ( ) {
438
422
439
- beforeAll ( ( ) => {
440
- jasmine . addMatchers ( matchers ) ;
423
+ beforeAll ( function ( ) {
441
424
browser . get ( '' ) ;
442
425
element . all ( by . tagName ( 'a' ) ) . get ( 2 ) . click ( ) ;
443
426
} ) ;
444
427
445
- it ( 'should have the correct page heading' , ( ) => {
428
+ it ( 'should have the correct page heading' , function ( ) {
446
429
expect ( 'h2' ) . toHaveTextByCss ( 'Roles for custom component widgets' ) ;
447
430
} ) ;
448
431
449
- it ( 'should have the correct sections' , ( ) => {
432
+ it ( 'should have the correct sections' , function ( ) {
450
433
let headings = element . all ( by . tagName ( 'h3' ) ) ;
451
434
expect ( headings . get ( 0 ) ) . toHaveText ( 'Roles in the template' ) ;
452
435
expect ( headings . get ( 1 ) ) . toHaveText ( 'Roles of the host element' ) ;
453
436
} ) ;
454
437
455
- it ( 'should have a working editable div with label and internal role' , ( ) => {
438
+ it ( 'should have a working editable div with label and internal role' , function ( ) {
456
439
let testVal = 'Test' ;
457
440
expect ( element . all ( by . tagName ( 'div.col-xs-6 label' ) ) . first ( ) ) . toHaveText ( 'I set the role in my template:' ) ;
458
441
let input = element . all ( by . css ( 'div[role="textbox"]' ) ) . get ( 0 ) ;
459
442
expect ( input ) . toHaveText ( '' ) ;
460
- sendKeys ( input , testVal ) ;
443
+ input . sendKeys ( testVal ) ;
461
444
expect ( input ) . toHaveText ( testVal ) ;
462
445
} ) ;
463
446
464
- it ( 'should have a clickable custom button component with role' , ( ) => {
447
+ it ( 'should have a clickable custom button component with role' , function ( ) {
465
448
element . all ( by . css ( 'a11y-custom-button[role="button"]' ) ) . get ( 0 ) . click ( ) ;
466
449
testValueDecorator ( 1 , 'Button has been clicked 1 times' ) ;
467
450
} ) ;
468
451
469
452
} ) ;
470
453
471
- describe ( 'A11y Cookbook a11y errors page' , ( ) => {
454
+ describe ( 'A11y Cookbook a11y errors page' , function ( ) {
472
455
473
- beforeAll ( ( ) => {
474
- jasmine . addMatchers ( matchers ) ;
456
+ beforeAll ( function ( ) {
475
457
browser . get ( '' ) ;
476
458
element . all ( by . tagName ( 'a' ) ) . get ( 3 ) . click ( ) ;
477
459
element . all ( by . tagName ( 'a' ) ) . first ( ) . click ( ) ;
478
460
} ) ;
479
461
480
- it ( 'should have the correct page heading' , ( ) => {
462
+ it ( 'should have the correct page heading' , function ( ) {
481
463
expect ( 'h3' ) . toHaveTextByCss ( 'Demo with a11y errors' ) ;
482
464
} ) ;
483
465
484
- it ( 'should have the required form elements' , ( ) => {
466
+ it ( 'should have the required form elements' , function ( ) {
485
467
testDemoPageLabels ( ) ;
486
468
} ) ;
487
469
488
- it ( 'should have basic form functionality' , ( ) => {
470
+ it ( 'should have basic form functionality' , function ( ) {
489
471
testDemoPageFunction ( ) ;
490
472
} ) ;
491
473
492
474
} ) ;
493
475
494
- describe ( 'A11y Cookbook a11y features page' , ( ) => {
476
+ describe ( 'A11y Cookbook a11y features page' , function ( ) {
495
477
496
- beforeAll ( ( ) => {
497
- jasmine . addMatchers ( matchers ) ;
478
+ beforeAll ( function ( ) {
498
479
browser . get ( '' ) ;
499
480
element . all ( by . tagName ( 'a' ) ) . get ( 3 ) . click ( ) ;
500
481
element . all ( by . tagName ( 'a' ) ) . get ( 1 ) . click ( ) ;
501
482
} ) ;
502
483
503
- it ( 'should have the correct page heading' , ( ) => {
484
+ it ( 'should have the correct page heading' , function ( ) {
504
485
expect ( 'h2' ) . toHaveTextByCss ( 'Demo with full a11y features' ) ;
505
486
} ) ;
506
487
507
- it ( 'should have the required form elements' , ( ) => {
488
+ it ( 'should have the required form elements' , function ( ) {
508
489
testDemoPageLabels ( ) ;
509
490
} ) ;
510
491
511
- it ( 'should have basic form functionality' , ( ) => {
492
+ it ( 'should have basic form functionality' , function ( ) {
512
493
testDemoPageFunction ( ) ;
513
494
} ) ;
514
495
@@ -526,11 +507,11 @@ describe('A11y Cookbook', () => {
526
507
let submitButton = element ( by . css ( 'button.btn.btn-primary' ) ) ;
527
508
expect ( statusBanner ) . not . toBeDisplayed ( ) ;
528
509
let nameInput = element . all ( by . css ( 'input' ) ) . get ( 0 ) ;
529
- sendKeys ( nameInput , 'John' ) ;
510
+ nameInput . sendKeys ( 'John' ) ;
530
511
let surnameInput = element . all ( by . css ( 'input' ) ) . get ( 1 ) ;
531
- sendKeys ( surnameInput , 'Smith' ) ;
512
+ surnameInput . sendKeys ( 'Smith' ) ;
532
513
let reasonInput = element . all ( by . css ( 'input' ) ) . get ( 2 ) ;
533
- sendKeys ( reasonInput , 'It is awesome!!' ) ;
514
+ reasonInput . sendKeys ( 'It is awesome!!' ) ;
534
515
submitButton . click ( ) ;
535
516
expect ( statusBanner ) . toBeDisplayed ( ) ;
536
517
expect ( element . all ( by . cssContainingText ( 'div.alert.alert-success' ,
0 commit comments