Ka0s
Ka0s

Reputation: 398

CasperJS Not timing out

I have a CasperJS script that does various functions and records the times taken by emitting signals after each step. This process works. I have encountered infrequent instances where the custom timeouts I specified are not being called. I know this because the step time is way larger than the timeout. My CasperJS setup looks like this:

var session1 = require('casper').create({
    logLevel: 'debug',
    waitTimeout: 60000,
    userAgent: 'Mozilla/5.0'
});

The function looks like this:

session1.waitForSelector('#Selector', function () {
    this.emit('logged.in');
    this.clickLabel('Clients', 'a');
}, function timeout() {
    this.emit('genericTimeout', 'Could not log in');
});

In some instances the timeout function is reached, and sometimes, very rarely, it is not. Any advice?

Upvotes: 1

Views: 107

Answers (1)

Diego Borges
Diego Borges

Reputation: 342

@Ka0s , apparently everything is ok with your code. Just an afterthought and a suggestion for your code ... I noticed that you are using the waitForSelector, I prefer to use waitFor therefore he can deal with any other variable within my duties.

Another point it would be cool if you pay attention is that you can set a default time for their timeouts and in addition, in each use, you can force a different timeout, and I appreciate very work that way!

Here's an example:

// Default setting:
casper.options.timeout = 30000; // 30s for loading a page
casper.options.stepTimeout = 60000; // = 60s 1m to perform the processing ofeach step

After that, in each block of code, you can force a different timeout, if you want ...

casper.waitFor (check function () {
    return this.evaluate (function () {return (__utils getElementByXPath __ ('XPATH') = null);.!});
} Then function () {
    // Then
}, Function timeout () {
    // Timeout
} 10000); // Forcing timeout 10 seconds waiting for the element on the page

As in waitFor in waitForSelector works the same way, take a look at the documentation here to waitFor() and here to waitForSelector().

Upvotes: 1

Related Questions