I want casperjs to make an ajax call but wait for the result from my server. This might take up to 3 minutes, but I can tell from looking at the results of running my script, casper.then function times out and just keeps going after exactly 30 seconds. I've tried putting casper.options.waitTimeout = 180000 /* 3 minutes */; in my code, which does work, and I've tried using this block of code, which seems to wait 3 minutes every single time regardless of the result of my api call.
I also know that the evaluate function returns only a boolean every time no matter what, and this won't work as I need the api call data that is returned in the rest of my script. How can I get this function to wait for 3 minutes? And there is a lot going on behind the scenes, so yes, I need to wait this long.
var casper = require('casper').create();
casper.start('mysite.html', function() {
});
casper.then(function() {
result = getSomethingFromMyServerViaAjax( theId );
});
This is the alternate method that I've tried that seems to always wait 3 minutes regardless or speed of the ajax call coming back.
casper.waitFor(function check() {
return this.evaluate(function() {
return result = getSomethingFromMyServerViaAjax( theId ) /* this takes up to 3 minutes */;
});
}, function then() {
casper.log("Doing something after the ajax call...", "info");
this.die("Stopping here for now", "error");
}, 180000 );
I have tested my ajax call elsewhere and it works, as long as the response comes back in under 30 seconds, but if it doesn't casper just skips that block and keeps going every time.