@@ -540,6 +540,203 @@ ariaTest(
540
540
}
541
541
) ;
542
542
543
+ // "Test 1" in https://github.com/w3c/aria-practices/issues/1345
544
+
545
+ ariaTest (
546
+ 'Test backspace with focus on textbox' ,
547
+ exampleFile ,
548
+ 'standard-single-line-editing-keys' ,
549
+ async ( t ) => {
550
+ // Send key "a" to the textbox
551
+
552
+ await t . context . session
553
+ . findElement ( By . css ( ex . textboxSelector ) )
554
+ . sendKeys ( 'a' ) ;
555
+
556
+ // Get the value of the first option in the listbox
557
+
558
+ const firstOption = await (
559
+ await t . context . queryElements ( t , ex . optionsSelector )
560
+ ) [ 0 ] . getText ( ) ;
561
+
562
+ // Confirm that the value of the textbox is now set to the first option
563
+
564
+ t . is (
565
+ await t . context . session
566
+ . findElement ( By . css ( ex . textboxSelector ) )
567
+ . getAttribute ( 'value' ) ,
568
+ firstOption ,
569
+ 'key press "a" should result in first option in textbox'
570
+ ) ;
571
+
572
+ // Send key BACK_SPACE
573
+
574
+ await t . context . session
575
+ . findElement ( By . css ( ex . textboxSelector ) )
576
+ . sendKeys ( Key . BACK_SPACE ) ;
577
+
578
+ // Confirm that the listbox is still open
579
+
580
+ await assertAttributeValues ( t , ex . textboxSelector , 'aria-expanded' , 'true' ) ;
581
+
582
+ // Confirm that the value of the textbox is now "A"
583
+
584
+ t . is (
585
+ await t . context . session
586
+ . findElement ( By . css ( ex . textboxSelector ) )
587
+ . getAttribute ( 'value' ) ,
588
+ 'A' ,
589
+ 'key press "BACK_SPACE" should result in deleting the autocompleted text'
590
+ ) ;
591
+
592
+ // Send key BACK_SPACE
593
+
594
+ await t . context . session
595
+ . findElement ( By . css ( ex . textboxSelector ) )
596
+ . sendKeys ( Key . BACK_SPACE ) ;
597
+
598
+ // Confirm that the listbox is still open
599
+
600
+ await assertAttributeValues ( t , ex . textboxSelector , 'aria-expanded' , 'true' ) ;
601
+
602
+ // Confirm that the value of the textbox is now ""
603
+
604
+ t . is (
605
+ await t . context . session
606
+ . findElement ( By . css ( ex . textboxSelector ) )
607
+ . getAttribute ( 'value' ) ,
608
+ '' ,
609
+ 'key press "BACK_SPACE" should result in deleting the "A"'
610
+ ) ;
611
+
612
+ // Send key ARROW_DOWN
613
+ await t . context . session
614
+ . findElement ( By . css ( ex . textboxSelector ) )
615
+ . sendKeys ( Key . ARROW_DOWN ) ;
616
+
617
+ // Confirm that the listbox is still open
618
+
619
+ await assertAttributeValues ( t , ex . textboxSelector , 'aria-expanded' , 'true' ) ;
620
+
621
+ // Confirm aria-selected is set on the item "Alabama"
622
+
623
+ await assertAttributeValues (
624
+ t ,
625
+ ex . optionsSelector + ':nth-of-type(1)' ,
626
+ 'aria-selected' ,
627
+ 'true'
628
+ ) ;
629
+
630
+ // Confirm that the value of the textbox is now set to the first option
631
+
632
+ t . is (
633
+ await t . context . session
634
+ . findElement ( By . css ( ex . textboxSelector ) )
635
+ . getAttribute ( 'value' ) ,
636
+ firstOption ,
637
+ 'key press "ARROW_DOWN" should result in first option in textbox'
638
+ ) ;
639
+
640
+ // Confirm that there are 56 options visible
641
+ t . is (
642
+ await ( await t . context . queryElements ( t , ex . optionsSelector ) ) . length ,
643
+ 56 ,
644
+ 'key press "ARROW_DOWN" should result in all options being visible'
645
+ ) ;
646
+ }
647
+ ) ;
648
+
649
+ // "Test 2" in https://github.com/w3c/aria-practices/issues/1345
650
+
651
+ ariaTest (
652
+ 'Test backspace with focus on textbox (2)' ,
653
+ exampleFile ,
654
+ 'standard-single-line-editing-keys' ,
655
+ async ( t ) => {
656
+ // Send keys "no" to the textbox
657
+
658
+ await t . context . session
659
+ . findElement ( By . css ( ex . textboxSelector ) )
660
+ . sendKeys ( 'n' , 'o' ) ;
661
+
662
+ // Confirm that the value of the textbox is now set to "North Carolina"
663
+
664
+ t . is (
665
+ await t . context . session
666
+ . findElement ( By . css ( ex . textboxSelector ) )
667
+ . getAttribute ( 'value' ) ,
668
+ 'North Carolina' ,
669
+ 'key press "n" "o" should result in "North Carolina" in textbox'
670
+ ) ;
671
+
672
+ // Send key BACK_SPACE
673
+
674
+ await t . context . session
675
+ . findElement ( By . css ( ex . textboxSelector ) )
676
+ . sendKeys ( Key . BACK_SPACE ) ;
677
+
678
+ // Confirm that the listbox is still open
679
+
680
+ await assertAttributeValues ( t , ex . textboxSelector , 'aria-expanded' , 'true' ) ;
681
+
682
+ // Confirm that the value of the textbox is now "No"
683
+
684
+ t . is (
685
+ await t . context . session
686
+ . findElement ( By . css ( ex . textboxSelector ) )
687
+ . getAttribute ( 'value' ) ,
688
+ 'No' ,
689
+ 'key press "BACK_SPACE" should result in deleting the autocompleted text'
690
+ ) ;
691
+
692
+ // Send key BACK_SPACE
693
+
694
+ await t . context . session
695
+ . findElement ( By . css ( ex . textboxSelector ) )
696
+ . sendKeys ( Key . BACK_SPACE ) ;
697
+
698
+ // Confirm that the listbox is still open
699
+
700
+ await assertAttributeValues ( t , ex . textboxSelector , 'aria-expanded' , 'true' ) ;
701
+
702
+ // Confirm that the value of the textbox is now "N"
703
+
704
+ t . is (
705
+ await t . context . session
706
+ . findElement ( By . css ( ex . textboxSelector ) )
707
+ . getAttribute ( 'value' ) ,
708
+ 'N' ,
709
+ 'key press "BACK_SPACE" should result in deleting the "o"'
710
+ ) ;
711
+
712
+ // Send key ARROW_DOWN
713
+ await t . context . session
714
+ . findElement ( By . css ( ex . textboxSelector ) )
715
+ . sendKeys ( Key . ARROW_DOWN ) ;
716
+
717
+ // Confirm that the listbox is still open
718
+
719
+ await assertAttributeValues ( t , ex . textboxSelector , 'aria-expanded' , 'true' ) ;
720
+
721
+ // Confirm that the value of the textbox is now set to "Nebraska"
722
+
723
+ t . is (
724
+ await t . context . session
725
+ . findElement ( By . css ( ex . textboxSelector ) )
726
+ . getAttribute ( 'value' ) ,
727
+ 'Nebraska' ,
728
+ 'key press "ARROW_DOWN" should result in "Nebraska" in textbox'
729
+ ) ;
730
+
731
+ // Confirm that there are 9 options visible
732
+ t . is (
733
+ await ( await t . context . queryElements ( t , ex . optionsSelector ) ) . length ,
734
+ 9 ,
735
+ 'key press "ARROW_DOWN" should result in 9 options being visible'
736
+ ) ;
737
+ }
738
+ ) ;
739
+
543
740
ariaTest (
544
741
'Test enter key press with focus on listbox' ,
545
742
exampleFile ,
@@ -551,7 +748,7 @@ ariaTest(
551
748
. findElement ( By . css ( ex . textboxSelector ) )
552
749
. sendKeys ( 'a' , Key . ARROW_DOWN ) ;
553
750
554
- // Get the value of the first option in the listbox
751
+ // Get the value of the second option in the listbox
555
752
556
753
const secondOption = await (
557
754
await t . context . queryElements ( t , ex . optionsSelector )
@@ -563,7 +760,7 @@ ariaTest(
563
760
. findElement ( By . css ( ex . textboxSelector ) )
564
761
. sendKeys ( Key . ENTER ) ;
565
762
566
- // Confirm that the listbox is still open
763
+ // Confirm that the listbox is closed
567
764
568
765
await assertAttributeValues (
569
766
t ,
0 commit comments