How to increase the timeout in CasperJS

26,451

Solution 1

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);

Solution 2

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

Solution 3

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);
Share:
26,451
user2129794
Author by

user2129794

Updated on September 15, 2020

Comments

  • user2129794
    user2129794 over 3 years

    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
    
  • Ryguy
    Ryguy over 10 years
    You can also set an option to increase the timeout. This will be the default for all timed functions. See the following link: link
  • user2129794
    user2129794 over 10 years
    Please see Edit. I have updated the code but am getting the error as shown in the edit
  • Cybermaxs
    Cybermaxs over 10 years
    yes, in fact the third argument is onTimeout callback. Timeout value is the fourth.
  • gumuruh
    gumuruh almost 8 years
    this value will be used for the command of waitFor() and also wait() all in commons @Fanch ?
  • Fanch
    Fanch almost 8 years
    @gumuruh : yes ;) docs.casperjs.org/en/latest/modules/casper.html#waittimeout Default wait timeout, for wait* family functions.