1

I'm using casper tester module, and I had this structure:

casper.start();

...(various then() and wait() calls)

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

Doing it that way appeared to work fine (except for an intermittent timer problem I've been trying to troubleshoot).

If I change the above the following, which is shown in the casper docs, and which I thought was basically the same:

casper.start();

...(various then() and wait() calls)

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

then I get "WARN Looks like you didn't run any test.". I realized it was because I didn't have any assert() calls yet! I added a gratuitous assert and the warning went away, and now I start getting a report of how many tests run, etc. (The intermittent timer problem remains, so that must be something else.)

But it made me realize that I should've been doing it the second way, and that obviously there is a difference.

Can somebody explain what the difference is, and why the first was not working correctly? I'm hoping it will lead to a deeper understanding of how CasperJS tests work!

Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • Hello, did you find any solution? I have a same problem. Thank you. – DzeryCZ Sep 04 '14 at 14:03
  • @DzeryCZ I think the second half of my question is the solution (i.e. `test.done()` must be done in the `run()` function, *and* you must have defined at least one assert). What I still don't understand is why it matters :-) – Darren Cook Sep 04 '14 at 17:06
  • thank you for your solution. I'd imagine the reason has something to do with the order those callbacks are called in. There are probably some cleanup things like closing all webpages at the end of casper.run before its given callback is executed that would otherwise be called out of order. – encrest Jan 07 '15 at 22:33

1 Answers1

0

Your final then() (containing the call to done()) isn't quite finished when done() gets called - it still has one more function to call.

On the other hand, the run() function executes it's callback when all previous steps are completely finished. From the docs: 'you can consider as a custom final step to perform when all the other steps have been executed.'

This shouldn't make a difference in most cases, as done() is probably the last step of your final then. It could make a difference, for example, if done checked that all steps had been completed.

Source: http://casperjs.readthedocs.org/en/latest/modules/casper.html#run

psimyn
  • 406
  • 5
  • 12