Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

casper.then does not wait the end of my instruction to execute the next step

Tags:

casperjs

I have made this little test:

casper.test.begin('Test', function() {
casper.start();

casper.then(function() {
    casper = this;
    setTimeout(function(casper) {
        casper.echo('wait 5s');
    }, 5000);
});

casper.then(function() {
    this.echo('should appear after 5s');
});

casper.run(function() {
    this.test.done();
});
});

When I execute this test, my console shows only this line "should appear after 5s" but not the first sentence, in fact the second 'then' does not wait for 5 seconds.

It's a huge problem because it's the possible cause of many random failure in my casperjs test suite.

Maybe I have to use async (with series) to execute each step after the other.

Do you have this problem ? What's the best practice to execute some javascript functions one after the other in casperjs tests ?

like image 368
Brice LALU Avatar asked Feb 24 '14 09:02

Brice LALU


1 Answers

Try to use wait() here:

casper.then(function() {
    casper = this;
    casper.echo('wait 5s');
});

casper.then(function() {
    casper.wait(5000, function() {
        this.echo('should appear after 5s');
    });
});
like image 97
Felix Avatar answered Sep 24 '22 23:09

Felix