A fully-automated testing rig #8
12th Aug 2014
Nathan Page
Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?
##Part 8: CasperJS debugging tips
You're getting desperate. Your CoffeeScript / Javascript syntax looks OK, but CasperJS doesn't like what you're giving it.
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.evaluate
statement, 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
casper.
,this.
andtest.
appropriately? It's easy to use the wrong one. Some helpful guidelines: If it's a step-related command (then, wait, etc.) then it'scasper
. If it's test-related (pass, fail, assert, etc.) then usetest
. If you're inside athen
block, you probably wantthis
. - 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?
- Do you need to turn off CSS animations? If things are animated with CSS (not jQuery or Javascript), PhantomCSS can disable the animations so that your page loads straight into its final state. Try
phantomcss.turnOffAnimations()
. - 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?