@@ -19,6 +19,7 @@ import events from 'events';
1919 * @param {String } attribute - attribute to be checked
2020 * @param {Function } checker - function that must return true if the attribute matches, false otherwise
2121 * @param {Integer } [timeoutInMilliseconds] - timeout of this wait commands in milliseconds
22+ * @param {String } [defaultMessage] - message to display
2223*/
2324
2425class WaitForAttribute extends events . EventEmitter {
@@ -40,7 +41,7 @@ class WaitForAttribute extends events.EventEmitter {
4041 }
4142 }
4243
43- command ( elementSelector , attribute , checker , timeoutInMilliseconds ) {
44+ command ( elementSelector , attribute , checker , timeoutInMilliseconds , defaultMessage ) {
4445 //Save the origian locate strategy, because if this command is used with
4546 //page objects, the "checker" function of this command is wrapped with another
4647 //function which resets the locate strategy after the function is called,
@@ -56,10 +57,16 @@ class WaitForAttribute extends events.EventEmitter {
5657 if ( typeof timeoutInMilliseconds !== 'number' ) {
5758 timeoutInMilliseconds = this . defaultTimeoutInMilliseconds ;
5859 }
60+ if ( defaultMessage && typeof defaultMessage !== 'string' ) {
61+ this . emit ( 'error' , "defaultMessage is not a string" ) ;
62+ return ;
63+ }
5964
6065 this . check ( elementSelector , attribute , checker , ( result , loadedTimeInMilliseconds ) => {
6166 let message = "" ;
62- if ( result ) {
67+ if ( defaultMessage ) {
68+ message = defaultMessage ;
69+ } else if ( result ) {
6370 message = `waitForAttribute: ${ elementSelector } @${ attribute } . Expression was true after ${ loadedTimeInMilliseconds - this . startTimeInMilliseconds } .` ;
6471 } else {
6572 message = `waitForAttribute: ${ elementSelector } @${ attribute } . Expression wasn't true in ${ timeoutInMilliseconds } ms.` ;
0 commit comments