user2726621
user2726621

Reputation: 41

CasperJS code from tutorial does not work

It's my first post here : ) I'm learning CasperJS and I have to write script who search all img's on site and check urls.

I found this tutorial from vgaltes.com

var imagesArray = [];

function getImages() {
    var scripts = document.querySelectorAll('img[src]');
    return Array.prototype.map.call(scripts, function (e) {
        return e.getAttribute('src');
    });
};

casper.start('http://fooo.fooo', function () {
    imagesArray = this.evaluate(getImages);
    var self = this;
    imagesArray.forEach(function (item) {
        if (self.resourceExists(item)) {
            self.echo(item + ' loaded');
        } else {
            var message = item + ' not loaded';
            self.echo(message, 'ERROR');
        }
    });
});

but when I run this code on CasperJS (with valid url) do not work. Nothing happens. Casper Version is 1.1

Upvotes: 1

Views: 282

Answers (2)

vgaltes
vgaltes

Reputation: 1218

I'm the owner of vgaltes.com. As Pbk1303 said, you have to call to run function. If you read the tutorial, is the last source code posted.

casper.run(function(){
    this.echo('finished');
    this.test.done(1);
    this.test.renderResults(true);
});

Regards,

Upvotes: 1

Pbk1303
Pbk1303

Reputation: 3802

Looks like you did not run the function, try adding the below code in the end

casper.run(function() {this.test.renderResults(true);});

Upvotes: 2

Related Questions