This repository was archived by the owner on Jul 29, 2024. It is now read-only.
File tree 2 files changed +38
-2
lines changed
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,12 @@ var buildElementHelper = function(ptor) {
393
393
ElementArrayFinder . prototype . count = function ( ) {
394
394
return this . getWebElements ( ) . then ( function ( arr ) {
395
395
return arr . length ;
396
+ } , function ( err ) {
397
+ if ( err . code == webdriver . error . ErrorCode . NO_SUCH_ELEMENT ) {
398
+ return 0 ;
399
+ } else {
400
+ throw err ;
401
+ }
396
402
} ) ;
397
403
} ;
398
404
@@ -682,8 +688,10 @@ var buildElementHelper = function(ptor) {
682
688
var getWebElements = function ( ) {
683
689
return elementArrayFinder . getWebElements ( ) . then ( function ( webElements ) {
684
690
if ( webElements . length === 0 ) {
685
- throw new Error ( 'No element found using locator: ' +
686
- elementArrayFinder . locator_ . toString ( ) ) ;
691
+ throw new webdriver . error . Error (
692
+ webdriver . error . ErrorCode . NO_SUCH_ELEMENT ,
693
+ 'No element found using locator: ' +
694
+ elementArrayFinder . locator_ . toString ( ) ) ;
687
695
} else {
688
696
if ( webElements . length > 1 ) {
689
697
console . log ( 'warning: more than one element found for locator ' +
Original file line number Diff line number Diff line change @@ -91,6 +91,34 @@ describe('ElementFinder', function() {
91
91
expect ( element ( by . binding ( 'nopenopenope' ) ) . isPresent ( ) ) . toBe ( false ) ;
92
92
} ) ;
93
93
94
+ it ( 'should allow handling errors' , function ( ) {
95
+ browser . get ( 'index.html#/form' ) ;
96
+ var elmFinder = $ ( '.nopenopenope' ) . getText ( ) . then ( function ( success ) {
97
+ // This should throw an error. Fail.
98
+ expect ( true ) . toEqual ( false ) ;
99
+ } , function ( err ) {
100
+ expect ( true ) . toEqual ( true ) ;
101
+ } ) ;
102
+ } ) ;
103
+
104
+ it ( 'should allow handling chained errors' , function ( ) {
105
+ browser . get ( 'index.html#/form' ) ;
106
+ var elmFinder = $ ( '.nopenopenope' ) . $ ( 'furthernope' ) . getText ( ) . then (
107
+ function ( success ) {
108
+ // This should throw an error. Fail.
109
+ expect ( true ) . toEqual ( false ) ;
110
+ } , function ( err ) {
111
+ expect ( true ) . toEqual ( true ) ;
112
+ } ) ;
113
+ } ) ;
114
+
115
+ it ( 'isPresent() should not raise error on chained finders' , function ( ) {
116
+ browser . get ( 'index.html#/form' ) ;
117
+ var elmFinder = $ ( '.nopenopenope' ) . element ( by . binding ( 'greet' ) ) ;
118
+
119
+ expect ( elmFinder . isPresent ( ) ) . toBe ( false ) ;
120
+ } ) ;
121
+
94
122
it ( 'should export an allowAnimations helper' , function ( ) {
95
123
browser . get ( 'index.html#/animation' ) ;
96
124
var animationTop = element ( by . id ( 'animationTop' ) ) ;
You can’t perform that action at this time.
0 commit comments