Skip to main content

A fully-automated testing rig #8

An article from ComputerMinds - Building with Drupal in the UK since 2005
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:

  1. Is all your syntax actually correct? If you're using CoffeeScript, are your indents all correct? Like, all of them?
  2. 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.
  3. 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!
  4. Have you used casper. , this. and 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 then block, you probably want this.
  5. 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.
  6. Can you use this.echo or test.pass statements to help monitor progress more clearly?
  7. 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().
  8. 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?

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.