casper = require('casper').create()

casper.login = ->
  @fill('form[action="/sessions"]', {
    jid: 'testovaci1@jabbim.cz'
    password: 'heslo'
  }, true)

  casper.echo 'Loading roster. This may take some time.'

  casper.waitFor(->
    #test
    casper.evaluate(->
      __utils__.findAll('#js-inactive-friends ul li').length >= 2
    )
  , ->
    # on success
    casper.echo('loaded roster')
  , ->
    # on timeout
    casper.die('roster not loaded', 1)
  )

casper.inactiveListLength = ->
  casper.evaluate(-> __utils__.findAll('#js-inactive-friends ul li').length)

casper.activeListLength = ->
  casper.evaluate(-> __utils__.findAll('#js-active-friends ul li').length)

casper.tabsLength = ->
  casper.evaluate(-> __utils__.findAll('#js-tabbar .tab').length)

exports.Fantomas = casper