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

casperjs

Solution

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');
    });
});

Problem

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 ?

Original source