Question

I am trying to make use of the new 1.1 eachThen() API in casperJS however I am finding some strange behaviour with it.

Below follows a simple application

var casper = require('casper').create({
    verbose: true,
    logLevel: "error"
});
var urls = ['http://google.com/'];

casper.start();

var testvar = "";

casper.then(function() {
    urls = ['http://yahoo.com/', 'http://www.youtube.com/'];
});

casper.eachThen(urls, function(response) {
    console.log("Opening: "+response.data);
    this.thenOpen(response.data, function(response) {
        testvar = response.url;
    });
});

casper.run();

The way I understand it is that this application should open yahoo.com followed youtube.com however the array assignment on the step before does not seem to be taken in consideration at all and the output will be "Opening: http://google.com/".

Is anybody aware of any limitation on doing this or is this possible a bug in the current (beta) version of casperJS. I am using the latest 1.1.0-DEV

Was it helpful?

Solution

To answer my own question, wrapping the whole thing in a then() step does the job as explained by hexid in the comments however it seems that doing it as a "standalone" is not possible (Either due to a bug or by design, uncertain to me at the moment).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top