I am trying to utilize casperjs for an ajax call that requires waiting for my server's response, which may take up to 3 minutes. However, I have encountered an issue where the casper.then function times out after exactly 30 seconds. I attempted adjusting casper.options.waitTimeout = 180000 /* 3 minutes */ in the code, and also experimented with a code block that consistently waits for 3 minutes regardless of the api call result.
It is essential for me to receive the data from the api call in order to proceed with the rest of my script, as the evaluate function only returns a boolean value every time and does not suffice. How can I ensure that the function waits for the full 3 minutes? There are numerous processes happening in the background that necessitate this extended wait period.
var casper = require('casper').create();
casper.start('mysite.html', function() {
});
casper.then(function() {
result = getSomethingFromMyServerViaAjax( theId );
});
I also attempted an alternate method, but it consistently waits for 3 minutes irrespective of the speed at which the ajax call returns.
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 );
Although my ajax call functions correctly elsewhere within the 30-second timeframe, if it exceeds this limit, casper disregards the block and continues execution without waiting.