0

When the script is executed, it will never reach the line where it says "I WILL NEVER BE EXECUTED".

/*********/

var casper = require('casper').create(
{
    //clientScripts: ["includes/jquery-1.11.1.min.js"],
    waitTimeout: 15000,
    stepTimeout: 5500,   
    verbose: true,
    logLevel: 'debug',
    viewportSize: {
        width: 1680,
        height: 1050
    },
    onRunComplete: function() {
    // Don't exit on complete.
    },
    onWaitTimeout: function () {
        logConsole('Wait TimeOut Occured');
        this.capture('xWait_timeout.png');
        this.exit();
    },
    pageSettings: {
        "ignoreSslErrors": true
    },
    onStepTimeout: function (self, m) {

    }
}
);

var subjectParameter = casper.cli.get("subject");
var timeoutForScreenshot = casper.cli.get("timeoutForScreenshot");
casper.options.stepTimeout = timeoutForScreenshot + 500;

casper.on('step.timeout', function (request) {
    console.log("---------------STEP:timed out---------------------:" + request);
    request.abort();
});

casper.start('https://email.t-online.de', function () {

    casper.userAgent('Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko)');

    casper.waitForSelector('input[name=pw_usr]', function () {

        this.fillSelectors('form[name="login"]', {
            'input[name=pw_usr]': 'someE-Mailaddress@t-online.de',
            'input[name=pw_pwd]': 'somePassword'
        });

    }, function () {
        casper.log('no login-form found', 'error');
        casper.exit();
    });

    casper.then(function () {
        this.click("#pw_submit");
    });

    casper.waitForSelector('#rowListContainerTable', function () {
        //abort.request();

        this.evaluate(function getElementInDom(term) {

            var els = document.getElementsByTagName('span');
            var len = els.length;

            for (var i = 0; i < len; i++) {
                if (els[i].innerHTML.indexOf(term) != -1) {
                    els[i].click();
                    abort.request();
                }
            }

        }, subjectParameter);

        this.then(function () {
            this.echo("I WILL NEVER BE EXECUTED");
        });

        this.wait(8000, function () {
            this.capture('tonline - ' + subjectParameter + '.png', {
                top: 0,
                left: 0,
                width: 1680,
                height: 1050
            });

            casper.log('mail found', 'error');
            //casper.exit();
        });

    }, function () {
        casper.log('login failed', 'error');
        casper.exit();
    });

});

casper.run();

"subjectParameter" is a string

"timeoutForScreenshot" is an int value

The Script is logging into "https://email.t-online.de" and looking for an E-Mail where subject == "subjectParameter", it opens up the mail and should take a screenshot, but after that, all other "steps" after the "getElementInDom-Step" will not be executed.

Is there a way to continue to the next "step" after a step.timeout?

  • The `abort.request();` will produce an error if `abort` is not a global property in the page context and the for loop will not execute further. Also see [here](http://stackoverflow.com/q/15739263/1816580) how to click an element in page context. This should not be an issue with slimerjs. – Artjom B. Sep 02 '14 at 07:40

1 Answers1

0

Answer: ignoring an particular requested URL (from googleadservices) like that:

casper.on('resource.requested', function (requestData, request) {
    if (requestData.url.indexOf('xplosion') != -1) {
        request.abort();
    }

});

and it worked!