casperjsでテストを書く

casperJSでテストを書いてみた。

インストールは、こちらを参考にする。
インストールしたら、


$ casperjs
と打ってみる。エラーが出なければ、多分OK

続いてテストを書いてみる。
書き方は、JSかCoffeeScriptの2通りある。自分はCoffeeScriptで書いてみた。


1 casper = require('casper').create();
2 casper.start 'http://lifephoto.herokuapp.com', ->
3 @capture "top.png"
4 @test.assertTitle 'LifePhotos'
5 @test.assertTextExists 'Wellcome', 'Wellcome message exists'
6 @click("a[rel=facebook_login]")
7
8 casper.then ->
9 @capture "login.png"
10 @test.assertTitle 'Facebook', ' title is the one expected'
11
12 casper.run ->
13 @test.done 3
14 @test.renderResults true

では実行してみる。


$ casperjs top-test.coffee

テストが実行される、はず。