31

I am using waitFor(). The code as below:

casper.waitFor(function check() {
    return this.evaluate(function() {
        return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
    });
}, function then() {
    console.log('Done');
});

Am getting this as console output

Wait timeout of 5000ms expired, exiting.

How can I increase the timeout?

EDIT: I have changed the code to

 casper.waitFor(function check() {
        return this.evaluate(function() {
            return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
        });
    }, function then() {
        console.log('Done');
    },10000);

It's giving me the following error:

CasperError: Invalid timeout function, exiting.
    C:/filename:1720 in _check
warvariuc
  • 57,116
  • 41
  • 173
  • 227
user2129794
  • 2,388
  • 8
  • 33
  • 51

3 Answers3

58

Use that to increase the timeout of every wait() functions : casper.options.waitTimeout = 20000; (20sec)

Fanch
  • 3,274
  • 3
  • 20
  • 51
  • this value will be used for the command of waitFor() and also wait() all in commons @Fanch ? – gumuruh Jun 23 '16 at 05:38
  • 1
    @gumuruh : yes ;) http://docs.casperjs.org/en/latest/modules/casper.html#waittimeout `Default wait timeout, for wait* family functions.` – Fanch Jun 23 '16 at 12:01
27

As said here,

The signature is

waitFor(Function testFx[, Function then, Function onTimeout, Number timeout])

So, there is an additionnal argument to specify the timeout.

casper.waitFor(function check() {
    //...
    });
}, function then() {
     //...
}, function timeout() { 
//...
}, TIMEOUT_IN_MS);
Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
  • 5
    You can also set an option to increase the timeout. This will be the default for all timed functions. See the following link: [link](http://docs.casperjs.org/en/latest/modules/casper.html#timeout) – Ryguy Aug 13 '13 at 17:26
  • Please see Edit. I have updated the code but am getting the error as shown in the edit – user2129794 Aug 13 '13 at 17:39
  • 1
    yes, in fact the third argument is onTimeout callback. Timeout value is the fourth. – Cybermaxs Aug 13 '13 at 18:24
1

If you want to increase timeout while leaving the default error message, pass null as the third argument and number of milliseconds to wait as the fourth argument:

casper.waitFor(function check() {
    return this.evaluate(function() {
        return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
    });
}, function then() {
    console.log('Done');
}, null, 10000);
warvariuc
  • 57,116
  • 41
  • 173
  • 227