Tuesday, September 20, 2011

Testing with Zombie.js

I have been struggling for a while with the idea of TDD and in particular BDD. I have wanted to use it and the cool stuff like Cucumber is only available in Ruby, but I use Symfony. I don't use the pretty new Symfony2, but instead regular old Symfony1.4. All of the cool Symfony2 kids are using Behat. The even cooler kids are using Behat+Mink+Zombie. I really wanted that to be me so I set forth, but my journey wasn't without problems, so look out for these issues:

The Issues (and fixes)

  • The most important issue of all, and maybe the only one that matters, is that zombie cannot load your scripts or styles from third parties, in particular, googleapis. I got around this by checking for a user agent, and directing zombie to a local version of the scripts. I am not sure if it was because of https or because google is blocking the user agent, but it simply will not work. See the example at the bottom.
  • The 0.5.x versions of Node, do not work. I tried them and failed. I finally got it working with version 0.4.11. I guess its also important to note the versions of all of my other software. I used: Zombie Version: 0.10.1 and NPM Version: 1.0.17.
  • No matter how it may seem, Behat and Mink are not the issue. The issue is almost definitely between you, Node, and Zombie.
  • Test Zombie Separately. I will post a gist on how to do just that at the bottom
  • Error Messages

    • PHP Fatal error: Uncaught exception 'Behat\Mink\Exception\DriverException' with message 'Could not load resource
    • Argument #2 of PHPUnit_Framework_Assert::assertContains() must be a array, iterator or string

    Issues Without an Error

    • $page->getText() doesn't work.
    • zombie.visit(url) doesn't error, but doesn't run the stuff inside the closure.

    Symfony User Agent Check

    Zombie Test Script

    Obviously you will want to put in your local url. Also, if this works, remove runScripts. If it fails without runScripts, the issue is with a script you are including. Try to get rid of third party hosted scripts.

    Enjoy! Tomorrow I will post an installation tutorial for OSX+Macports. Look out for it!

    0 comments:

    Post a Comment