A fully-automated testing rig #8
Part 8: CasperJS debugging tips
Try going through this checklist for a selection of sensible sanity checks and more:
- Is all your syntax actually correct? If you're using CoffeeScript, are your indents all correct? Like, all of them?
- Is the page actually there? Is the content actually published? Have a look in a real browser, make sure you're doing what you think you're doing.
- Is your selector correct? If you're using selectors or maybe running a
this.evaluatestatement, it's a good idea to get the developer tools out and try doing things for yourself in your browser's console. Sometimes this highlights when you're trying to do something with CasperJS that even directly through the browser won't work!
- Have you used
test.appropriately? It's easy to use the wrong one. Some helpful guidelines: If it's a step-related command (then, wait, etc.) then it's
casper. If it's test-related (pass, fail, assert, etc.) then use
test. If you're inside a
thenblock, you probably want
- If you're using
casper.then ->blocks, is everything inside a then block? If you want something to happen exactly in order in this asynchronous world, you need to specify the order. If you're doing anything asynchronous, like loading pages or resizing the viewport, surround it in a then block and put anything that you want to do afterwards in another then block.
- Can you use this.echo or test.pass statements to help monitor progress more clearly?
- Is there another way to do what you're trying to do? Can you wait for a selector, rather than text? Is there a better selector to wait for? Could you use this.fillSelectors rather than this.fill?