       , done
 
 describe 'Login', ->
-  browser = null
-
-  before (done) ->
-    browser = new Browser()
+  before (done) ->
+    wd40.init ->
+      console.log browser
+      browser.get LOGIN_URL, done
+
+  before (done) ->
     createProfile
       shortName: 'ickletest'
       displayName: 'Mr Ickle Test'

          form: form
        , (err, resp, body) =>
          obj = JSON.parse body
          @browser = new Browser()
          @browser.visit "#{BASE_URL}/set-password/#{obj.token}", =>
            @browser.wait done

    it 'shows a page with a password field', ->
      should.exist @browser.query('#password')

    context 'when I fill in my new password', ->
      before (done) ->
        @browser.fill '#password', newPass
        @browser.pressButton '#content .btn-primary', =>
          @browser.wait done

      it 'sets my password', ->
        should.exist @browser.query('.alert-success')


describe 'Switch', ->


wd = require 'wd'
should = require 'should'
request = require 'request'
browser = wd.remote()
wd40 = require('../wd40')(browser)

BASE_URL = 'http://localhost:3001'
LOGIN_URL = "#{BASE_URL}/login"

# Overview
# Login as teststaff, create a profile called ickletest, attempt to login.
#
# Switching logs in as user A, adds a dataset using the API.
# Then we switch to a browser to switch the context.
#
# TODO: move Switching out into its own test file

login  = (username, password, callback) ->
  request.get LOGIN_URL, ->
    request.post
      uri: LOGIN_URL
      form:
        username: username
        password: password
