javascript - Why is waitFor() ignoring my return value? -
this code not working:
casper.waitfor(function check(){ //wait new line appear in table , input box emptied console.log("in waitfor:"); console.log(casper.evaluate(function(){return $("table.packageslisting tr td:contains('some text')").length;}) ); console.log(casper.evaluate(function(){return $("table.packageslisting tr td:contains('some text')").length;}) == 1 ); return casper.evaluate(function(){return $("table.packageslisting tr td:contains('some text')").length;}) == 1 //&& //(casper.evaluate(function(){return $('input#addnewpackage').val();}) == "") ; },function then(){}, function ontimeout(){ this.capture("screenshots/"+label+".failed_timeout_waiting_for_package_add.png"); });
when run see is:
in waitfor: 1 true in waitfor: 1 true ... in waitfor: 1 true in waitfor: 1 true
and timeout! must missing obvious, because using casper.waitfor() elsewhere in script, no problems!
the problem return
statement on line itself. in javascript, semi-colons optional (see automatic semicolon insertion & return statements), same writing:
return null; casper.evaluate(/*...*/) == 1 ;
when returning , of multiple booleans better (and more readable) assign them local vars. code looks like:
casper.waitfor(function check(){ //wait new line appear in table , input box emptied var isintable = casper.evaluate(function(){return $("table.packageslisting tr td:contains('some text')").length;}) == 1; var inputisemptied = casper.evaluate(function(){return $('input#addnewpackage').val();}) == ""; return isintable && inputisemptied; },function then(){}, function ontimeout(){ /*...*/ } );
Comments
Post a Comment