@@ -508,85 +508,73 @@ describe('WebDriver', function () {
508508 } )
509509
510510 describe ( '#waitNumberOfVisibleElements' , ( ) => {
511- it ( 'should wait for a specified number of elements on the page' , ( ) => {
512- return wd
513- . amOnPage ( '/info' )
514- . then ( ( ) => wd . waitNumberOfVisibleElements ( '//div[@id = "grab-multiple"]//a' , 3 ) )
515- . then ( ( ) => wd . waitNumberOfVisibleElements ( '//div[@id = "grab-multiple"]//a' , 2 , 0.1 ) )
516- . then ( ( ) => {
517- throw Error ( 'It should never get this far' )
518- } )
519- . catch ( e => {
520- e . message . should . include ( 'The number of elements (//div[@id = "grab-multiple"]//a) is not 2 after 0.1 sec' )
521- } )
511+ it ( 'should wait for a specified number of elements on the page' , async ( ) => {
512+ try {
513+ await wd . amOnPage ( '/info' )
514+ await wd . waitNumberOfVisibleElements ( '//div[@id = "grab-multiple"]//a' , 3 )
515+ await wd . waitNumberOfVisibleElements ( '//div[@id = "grab-multiple"]//a' , 2 , 0.1 )
516+ throw new Error ( 'It should never get this far' )
517+ } catch ( e ) {
518+ e . message . should . include ( 'The number of elements (//div[@id = "grab-multiple"]//a) is not 2 after 0.1 sec' )
519+ }
522520 } )
523521
524- it ( 'should be no [object Object] in the error message' , ( ) => {
525- return wd
526- . amOnPage ( '/info' )
527- . then ( ( ) => wd . waitNumberOfVisibleElements ( { css : '//div[@id = "grab-multiple"]//a' } , 3 ) )
528- . then ( ( ) => {
529- throw Error ( 'It should never get this far' )
530- } )
531- . catch ( e => {
532- e . message . should . not . include ( '[object Object]' )
533- } )
522+ it ( 'should be no [object Object] in the error message' , async ( ) => {
523+ try {
524+ await wd . amOnPage ( '/info' )
525+ await wd . waitNumberOfVisibleElements ( { css : '//div[@id = "grab-multiple"]//a' } , 3 )
526+ throw new Error ( 'It should never get this far' )
527+ } catch ( e ) {
528+ e . message . should . not . include ( '[object Object]' )
529+ }
534530 } )
535531
536- it ( 'should wait for a specified number of elements on the page using a css selector' , ( ) => {
537- return wd
538- . amOnPage ( '/info' )
539- . then ( ( ) => wd . waitNumberOfVisibleElements ( '#grab-multiple > a' , 3 ) )
540- . then ( ( ) => wd . waitNumberOfVisibleElements ( '#grab-multiple > a' , 2 , 0.1 ) )
541- . then ( ( ) => {
542- throw Error ( 'It should never get this far' )
543- } )
544- . catch ( e => {
545- e . message . should . include ( 'The number of elements (#grab-multiple > a) is not 2 after 0.1 sec' )
546- } )
532+ it ( 'should wait for a specified number of elements on the page using a css selector' , async ( ) => {
533+ try {
534+ await wd . amOnPage ( '/info' )
535+ await wd . waitNumberOfVisibleElements ( '#grab-multiple > a' , 3 )
536+ await wd . waitNumberOfVisibleElements ( '#grab-multiple > a' , 2 , 0.1 )
537+ throw new Error ( 'It should never get this far' )
538+ } catch ( e ) {
539+ e . message . should . include ( 'The number of elements (#grab-multiple > a) is not 2 after 0.1 sec' )
540+ }
547541 } )
548542
549- it ( 'should wait for a specified number of elements which are not yet attached to the DOM' , ( ) => {
550- return wd
551- . amOnPage ( '/form/wait_num_elements' )
552- . then ( ( ) => wd . waitNumberOfVisibleElements ( '.title' , 2 , 3 ) )
553- . then ( ( ) => wd . see ( 'Hello' ) )
554- . then ( ( ) => wd . see ( 'World' ) )
543+ it ( 'should wait for a specified number of elements which are not yet attached to the DOM' , async ( ) => {
544+ await wd . amOnPage ( '/form/wait_num_elements' )
545+ await wd . waitNumberOfVisibleElements ( '.title' , 2 , 3 )
546+ await wd . see ( 'Hello' )
547+ await wd . see ( 'World' )
555548 } )
556549 } )
557550
558551 describe ( '#waitForVisible' , ( ) => {
559- it ( 'should be no [object Object] in the error message' , ( ) => {
560- return wd
561- . amOnPage ( '/info' )
562- . then ( ( ) => wd . waitForVisible ( '//div[@id = "grab-multiple"]//a' , 3 ) )
563- . then ( ( ) => {
564- throw Error ( 'It should never get this far' )
565- } )
566- . catch ( e => {
567- e . message . should . not . include ( '[object Object]' )
568- } )
552+ it ( 'should be no [object Object] in the error message' , async ( ) => {
553+ try {
554+ await wd . amOnPage ( '/info' )
555+ await wd . waitForVisible ( '//div[@id = "grab-multiple"]//a' , 3 )
556+ throw new Error ( 'It should never get this far' )
557+ } catch ( e ) {
558+ e . message . should . not . include ( '[object Object]' )
559+ }
569560 } )
570561 } )
571562
572563 describe ( '#waitForInvisible' , ( ) => {
573- it ( 'should be no [object Object] in the error message' , ( ) => {
574- return wd
575- . amOnPage ( '/info' )
576- . then ( ( ) => wd . waitForInvisible ( '//div[@id = "grab-multiple"]//a' , 3 ) )
577- . then ( ( ) => {
578- throw Error ( 'It should never get this far' )
579- } )
580- . catch ( e => {
581- e . message . should . not . include ( '[object Object]' )
582- } )
564+ it ( 'should be no [object Object] in the error message' , async ( ) => {
565+ try {
566+ await wd . amOnPage ( '/info' )
567+ await wd . waitForInvisible ( '//div[@id = "grab-multiple"]//a' , 3 )
568+ throw new Error ( 'It should never get this far' )
569+ } catch ( e ) {
570+ e . message . should . not . include ( '[object Object]' )
571+ }
583572 } )
584573
585- it ( 'should wait for a specified element to be invisible' , ( ) => {
586- return wd
587- . amOnPage ( '/form/wait_invisible' )
588- . then ( ( ) => wd . waitForInvisible ( '#step1' , 3 ) )
589- . then ( ( ) => wd . dontSeeElement ( '#step1' ) )
574+ it ( 'should wait for a specified element to be invisible' , async ( ) => {
575+ await wd . amOnPage ( '/form/wait_invisible' )
576+ await wd . waitForInvisible ( '#step1' , 3 )
577+ await wd . dontSeeElement ( '#step1' )
590578 } )
591579 } )
592580
@@ -624,73 +612,69 @@ describe('WebDriver', function () {
624612 assert . equal ( numPagesAfter , 2 )
625613 } )
626614
627- it ( 'should assert when there is no ability to switch to next tab' , ( ) => {
628- return wd
629- . amOnPage ( '/' )
630- . then ( ( ) => wd . click ( 'More info' ) )
631- . then ( ( ) => wd . wait ( 1 ) ) // Wait is required because the url is change by previous statement (maybe related to #914)
632- . then ( ( ) => wd . switchToNextTab ( 2 ) )
633- . then ( ( ) => assert . equal ( true , false , 'Throw an error if it gets this far (which it should not)!' ) )
634- . catch ( e => {
635- assert . equal ( e . message , 'There is no ability to switch to next tab with offset 2' )
636- } )
615+ it ( 'should assert when there is no ability to switch to next tab' , async ( ) => {
616+ try {
617+ await wd . amOnPage ( '/' )
618+ await wd . click ( 'More info' )
619+ await wd . wait ( 1 ) // Wait is required because the url is changed by the previous statement (maybe related to #914)
620+ await wd . switchToNextTab ( 2 )
621+ assert . equal ( true , false , 'Throw an error if it gets this far (which it should not)!' )
622+ } catch ( e ) {
623+ assert . equal ( e . message , 'There is no ability to switch to next tab with offset 2' )
624+ }
637625 } )
638626
639- it ( 'should close current tab' , ( ) => {
640- return wd
641- . amOnPage ( '/info' )
642- . then ( ( ) => wd . click ( 'New tab' ) )
643- . then ( ( ) => wd . switchToNextTab ( ) )
644- . then ( ( ) => wd . seeInCurrentUrl ( '/login' ) )
645- . then ( ( ) => wd . grabNumberOfOpenTabs ( ) )
646- . then ( numPages => assert . equal ( numPages , 2 ) )
647- . then ( ( ) => wd . closeCurrentTab ( ) )
648- . then ( ( ) => wd . seeInCurrentUrl ( '/info' ) )
649- . then ( ( ) => wd . grabNumberOfOpenTabs ( ) )
627+ it ( 'should close current tab' , async ( ) => {
628+ await wd . amOnPage ( '/info' )
629+ await wd . click ( 'New tab' )
630+ await wd . switchToNextTab ( )
631+ await wd . seeInCurrentUrl ( '/login' )
632+ const numPages = await wd . grabNumberOfOpenTabs ( )
633+ assert . equal ( numPages , 2 )
634+ await wd . closeCurrentTab ( )
635+ await wd . seeInCurrentUrl ( '/info' )
636+ await wd . grabNumberOfOpenTabs ( )
650637 } )
651638
652- it ( 'should close other tabs' , ( ) => {
653- return wd
654- . amOnPage ( '/' )
655- . then ( ( ) => wd . openNewTab ( ) )
656- . then ( ( ) => wd . seeInCurrentUrl ( 'about:blank' ) )
657- . then ( ( ) => wd . amOnPage ( '/info' ) )
658- . then ( ( ) => wd . click ( 'New tab' ) )
659- . then ( ( ) => wd . switchToNextTab ( ) )
660- . then ( ( ) => wd . seeInCurrentUrl ( '/login' ) )
661- . then ( ( ) => wd . closeOtherTabs ( ) )
662- . then ( ( ) => wd . seeInCurrentUrl ( '/login' ) )
663- . then ( ( ) => wd . grabNumberOfOpenTabs ( ) )
664- } )
665-
666- it ( 'should open new tab' , ( ) => {
667- return wd
668- . amOnPage ( '/info' )
669- . then ( ( ) => wd . openNewTab ( ) )
670- . then ( ( ) => wd . waitInUrl ( 'about:blank' ) )
671- . then ( ( ) => wd . grabNumberOfOpenTabs ( ) )
672- . then ( numPages => assert . equal ( numPages , 2 ) )
639+ it ( 'should close other tabs' , async ( ) => {
640+ await wd . amOnPage ( '/' )
641+ await wd . openNewTab ( )
642+ await wd . seeInCurrentUrl ( 'about:blank' )
643+ await wd . amOnPage ( '/info' )
644+ await wd . click ( 'New tab' )
645+ await wd . switchToNextTab ( )
646+ await wd . seeInCurrentUrl ( '/login' )
647+ await wd . closeOtherTabs ( )
648+ await wd . seeInCurrentUrl ( '/login' )
649+ await wd . grabNumberOfOpenTabs ( )
673650 } )
674651
675- it ( 'should switch to previous tab' , ( ) => {
676- return wd
677- . amOnPage ( '/info' )
678- . then ( ( ) => wd . openNewTab ( ) )
679- . then ( ( ) => wd . waitInUrl ( 'about:blank' ) )
680- . then ( ( ) => wd . switchToPreviousTab ( ) )
681- . then ( ( ) => wd . waitInUrl ( '/info' ) )
652+ it ( 'should open new tab' , async ( ) => {
653+ await wd . amOnPage ( '/info' )
654+ await wd . openNewTab ( )
655+ await wd . waitInUrl ( 'about:blank' )
656+ const numPages = await wd . grabNumberOfOpenTabs ( )
657+ assert . equal ( numPages , 2 )
682658 } )
683659
684- it ( 'should assert when there is no ability to switch to previous tab' , ( ) => {
685- return wd
686- . amOnPage ( '/info' )
687- . then ( ( ) => wd . openNewTab ( ) )
688- . then ( ( ) => wd . waitInUrl ( 'about:blank' ) )
689- . then ( ( ) => wd . switchToPreviousTab ( 2 ) )
690- . then ( ( ) => wd . waitInUrl ( '/info' ) )
691- . catch ( e => {
692- assert . equal ( e . message , 'There is no ability to switch to previous tab with offset 2' )
693- } )
660+ it ( 'should switch to previous tab' , async ( ) => {
661+ await wd . amOnPage ( '/info' )
662+ await wd . openNewTab ( )
663+ await wd . waitInUrl ( 'about:blank' )
664+ await wd . switchToPreviousTab ( )
665+ await wd . waitInUrl ( '/info' )
666+ } )
667+
668+ it ( 'should assert when there is no ability to switch to previous tab' , async ( ) => {
669+ try {
670+ await wd . amOnPage ( '/info' )
671+ await wd . openNewTab ( )
672+ await wd . waitInUrl ( 'about:blank' )
673+ await wd . switchToPreviousTab ( 2 )
674+ await wd . waitInUrl ( '/info' )
675+ } catch ( e ) {
676+ assert . equal ( e . message , 'There is no ability to switch to previous tab with offset 2' )
677+ }
694678 } )
695679 } )
696680
@@ -1287,7 +1271,6 @@ describe('WebDriver - Basic Authentication', () => {
12871271
12881272 afterEach ( ( ) => wd . _after ( ) )
12891273
1290- // local run passed ✔ should be authenticated (443ms)
12911274 describe ( 'open page : #amOnPage' , ( ) => {
12921275 it ( 'should be authenticated' , async ( ) => {
12931276 await wd . amOnPage ( '/basic_auth' )
0 commit comments