2013-08-13 16 views
29

Sto usando waitFor(). Il codice, come di seguito:Come aumentare il timeout in CasperJS

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

sono sempre questo come uscita della console

Wait timeout of 5000ms expired, exiting. 

Come è possibile aumentare il timeout?

EDIT: ho cambiato il codice per

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

E mi sta dando il seguente errore:

CasperError: Invalid timeout function, exiting. 
    C:/filename:1720 in _check 

risposta

27

Come detto here,

La firma è

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

Quindi, c'è un argomento aggiuntivo per specificare il timeout.

casper.waitFor(function check() { 
    //... 
    }); 
}, function then() { 
    //... 
}, function timeout() { 
//... 
}, TIMEOUT_IN_MS); 
+5

È anche possibile impostare un'opzione per aumentare il timeout. Questo sarà l'impostazione predefinita per tutte le funzioni a tempo. Vedere il seguente link: [collegamento] (http://docs.casperjs.org/en/latest/modules/casper.html#timeout) – Ryguy

+0

Vedere Modifica. Ho aggiornato il codice ma sto ricevendo l'errore come mostrato nella modifica – user2129794

+1

sì, infatti il ​​terzo argomento è il callback Timeout. Il valore di timeout è il quarto. – Cybermaxs

53

Usa che per aumentare il timeout di ogni attesa() funzioni: casper.options.waitTimeout = 20000; (20sec)

+0

questo valore verrà utilizzato per il comando di waitFor() e anche wait() all in commons @Fanch? – gumuruh

+1

@gumuruh: sì;) http://docs.casperjs.org/en/latest/modules/casper.html#waittimeout 'Timeout di attesa predefinito, per le funzioni della famiglia wait *. – Fanch

1

Se si vuole aumentare il timeout, lasciando il messaggio di errore predefinito, passare null come terzo argomento e il numero di millisecondi per attendere come quarto argomento:

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